void NodeStatements::updateLineage(NNO pno) { setYourParentNo(pno); if(m_node) m_node->updateLineage(getNodeNo()); if(m_nodeNext) m_nodeNext->updateLineage(getNodeNo()); } //updateLineage
void NodeBlock::updateLineage(NNO pno) { if(getPreviousBlockPointer() == NULL) { setPreviousBlockPointer(m_state.getCurrentBlock()); } else assert(getPreviousBlockPointer() == m_state.getCurrentBlock()); m_state.pushCurrentBlock(this); setYourParentNo(pno); //has no m_node if(m_nodeNext) m_nodeNext->updateLineage(getNodeNo()); m_state.popClassContext(); //restores previousBlockNode } //updateLineage
UTI NodeUnaryOp::constantFold() { u64 val = U64_MAX; UTI nuti = getNodeType(); if(nuti == Nav) return Nav; //nothing to do yet //if(nuti == Hzy) return Hzy; //nothing to do yet TRY? // if here, must be a constant.. assert(isAConstant()); NNO pno = Node::getYourParentNo(); assert(pno); Node * parentNode = m_state.findNodeNoInThisClassForParent(pno); //t3767 assert(parentNode); evalNodeProlog(0); //new current frame pointer makeRoomForNodeType(nuti); //offset a constant expression EvalStatus evs = eval(); if( evs == NORMAL) { UlamValue cnstUV = m_state.m_nodeEvalStack.popArg(); u32 wordsize = m_state.getTotalWordSize(nuti); if(wordsize <= MAXBITSPERINT) val = cnstUV.getImmediateData(m_state); else if(wordsize <= MAXBITSPERLONG) val = cnstUV.getImmediateDataLong(m_state); else m_state.abortGreaterThanMaxBitsPerLong(); } evalNodeEpilog(); if(evs == ERROR) { std::ostringstream msg; msg << "Constant value expression for unary op" << getName(); msg << " is erroneous while compiling class: "; msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str(); MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); setNodeType(Nav); return Nav; } if(evs == NOTREADY) { std::ostringstream msg; msg << "Constant value expression for unary op" << getName(); msg << " is not yet ready while compiling class: "; msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str(); MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), WAIT); setNodeType(Hzy); m_state.setGoAgain(); //for compiler counts return Hzy; } //replace ourselves (and kids) with a node terminal; new NNO unlike template's NodeTerminal * newnode = new NodeTerminal(val, nuti, m_state); assert(newnode); newnode->setNodeLocation(getNodeLocation()); AssertBool swapOk = parentNode->exchangeKids(this, newnode); assert(swapOk); std::ostringstream msg; msg << "Exchanged kids! for unary " << getName(); msg << ", with a constant == " << newnode->getName(); msg << " while compiling class: "; msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str(); MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), DEBUG); newnode->setYourParentNo(pno); newnode->resetNodeNo(getNodeNo()); delete this; //suicide is painless.. return newnode->checkAndLabelType(); } //constantFold
void NodeUnaryOp::updateLineage(NNO pno) { setYourParentNo(pno); m_node->updateLineage(getNodeNo()); }
void NodeTypedef::updateLineage(NNO pno) { Node::updateLineage(pno); if(m_nodeTypeDesc) m_nodeTypeDesc->updateLineage(getNodeNo()); } //updateLineage
void NodeCast::updateLineage(NNO pno) { NodeUnaryOp::updateLineage(pno); if(m_nodeTypeDesc) m_nodeTypeDesc->updateLineage(getNodeNo()); } //updateLineage
void NodeConstantArray::checkForSymbol() { //in case of a cloned unknown NodeBlock * currBlock = getBlock(); m_state.pushCurrentBlockAndDontUseMemberBlock(currBlock); Symbol * asymptr = NULL; bool hazyKin = false; if(m_state.alreadyDefinedSymbol(m_token.m_dataindex, asymptr, hazyKin)) { if(asymptr->isConstant()) { m_constSymbol = (SymbolConstantValue *) asymptr; } else { std::ostringstream msg; msg << "(1) <" << m_state.getTokenDataAsString(m_token).c_str(); msg << "> is not a constant, and cannot be used as one with class: "; msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str(); MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); } } else { std::ostringstream msg; msg << "Named Constant Array <" << m_state.getTokenDataAsString(m_token).c_str(); msg << "> is not defined, or was used before declared in a function"; if(!hazyKin) MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); else MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), DEBUG); } m_state.popClassContext(); //restore if(m_constSymbol && !m_constSymbol->isDataMember() && !m_constSymbol->isLocalsFilescopeDef() && !m_constSymbol->isClassArgument() && (m_constSymbol->getDeclNodeNo() > getNodeNo())) { NodeBlock * currBlock = getBlock(); currBlock = currBlock->getPreviousBlockPointer(); std::ostringstream msg; msg << "Named constant array '" << getName(); msg << "' was used before declared in a function"; if(currBlock) { MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), WAIT); setBlockNo(currBlock->getNodeNo()); m_constSymbol = NULL; return checkForSymbol(); } else { MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); m_constSymbol = NULL; } } } //checkForSymbol
NodeTypeDescriptorSelect::NodeTypeDescriptorSelect(Token typetoken, UTI auti, NodeTypeDescriptor * node, CompilerState & state) : NodeTypeDescriptor(typetoken, auti, state), m_nodeSelect(node) { if(m_nodeSelect) m_nodeSelect->updateLineage(getNodeNo()); //for unknown subtrees }
void NodeTypeDescriptorSelect::updateLineage(NNO pno) { setYourParentNo(pno); if(m_nodeSelect) m_nodeSelect->updateLineage(getNodeNo()); } //updateLineage
void NodeControl::updateLineage(NNO pno) { setYourParentNo(pno); m_nodeCondition->updateLineage(getNodeNo()); m_nodeBody->updateLineage(getNodeNo()); } //updateLineage
void NodeBlock::replaceIdInScope(Symbol * oldsym, Symbol * newsym) { assert(oldsym->getBlockNoOfST() == getNodeNo()); newsym->setBlockNoOfST(getNodeNo()); //update ST block no in new symbol m_ST.replaceInTable(oldsym, newsym); }
void NodeBlock::replaceIdInScope(u32 oldid, u32 newid, Symbol * symptr) { assert(symptr->getBlockNoOfST() == getNodeNo()); m_ST.replaceInTable(oldid, newid, symptr); }
void NodeBlock::addIdToScope(u32 id, Symbol * symptr) { assert(symptr->getBlockNoOfST() == getNodeNo()); //set by Symbol constr, based on m_currentBlock m_ST.addToTable(id, symptr); }
NodeSquareBracket::NodeSquareBracket(Node * left, Node * right, CompilerState & state) : NodeBinaryOp(left,right,state) { m_nodeRight->updateLineage(getNodeNo()); //for unknown subtrees }