void Creature::onAppear() { // cancel any disappear event if(m_disappearEvent) { m_disappearEvent->cancel(); m_disappearEvent = nullptr; } // creature appeared the first time or wasn't seen for a long time if(m_removed) { stopWalk(); m_removed = false; callLuaField("onAppear"); // walk } else if(m_oldPosition != m_position && m_oldPosition.isInRange(m_position,1,1) && m_allowAppearWalk) { m_allowAppearWalk = false; walk(m_oldPosition, m_position); callLuaField("onWalk", m_oldPosition, m_position); // teleport } else if(m_oldPosition != m_position) { stopWalk(); callLuaField("onDisappear"); callLuaField("onAppear"); } // else turn }
void LocalPlayer::cancelWalk(Otc::Direction direction) { // only cancel client side walks if(m_walking && m_preWalking) stopWalk(); m_lastPrewalkDone = true; m_idleTimer.restart(); lockWalk(); if(m_autoWalkDestination.isValid()) { g_game.stop(); auto self = asLocalPlayer(); if(m_autoWalkContinueEvent) m_autoWalkContinueEvent->cancel(); m_autoWalkContinueEvent = g_dispatcher.scheduleEvent([self]() { if(self->m_autoWalkDestination.isValid()) self->autoWalk(self->m_autoWalkDestination); }, 500); } // turn to the cancel direction if(direction != Otc::InvalidDirection) setDirection(direction); callLuaField("onCancelWalk", direction); }
void LocalPlayer::cancelWalk(Otc::Direction direction) { // only cancel client side walks if(m_walking && m_preWalking) stopWalk(); m_lastPrewalkDone = true; // turn to the cancel direction if(direction != Otc::InvalidDirection) setDirection(direction); }
void LocalPlayer::cancelWalk(Otc::Direction direction) { // only cancel client side walks if(m_walking && m_preWalking) stopWalk(); m_lastPrewalkDone = true; m_waitingWalkPong = false; m_walkPingTimer.restart(); m_idleTimer.restart(); // turn to the cancel direction if(direction != Otc::InvalidDirection) setDirection(direction); }
void LocalPlayer::setHealth(double health, double maxHealth) { if(m_health != health || m_maxHealth != maxHealth) { double oldHealth = m_health; double oldMaxHealth = m_maxHealth; m_health = health; m_maxHealth = maxHealth; callLuaField("onHealthChange", health, maxHealth, oldHealth, oldMaxHealth); // cannot walk while dying if(health == 0) { if(isPreWalking()) stopWalk(); lockWalk(); } } }
void ClassDectorAst::walk() { if (checkIsNotWalking()) { return ; } if (nodeType != T_CCLASSDECTOR_DECTOR) { //std::cout << "error: nodetype is not T_CCLASSDECTOR_DECTOR in ClassDectorAst" << std::endl; LogiMsg::logi("error: nodetype is not T_CCLASSDECTOR_DECTOR in ClassDectorAst", getLineno()); stopWalk(); return ; } //std::cout << "walk in T_CCLASSDECTOR_DECTOR" << endl; LogiMsg::logi("walk in T_CCLASSDECTOR_DECTOR", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } }
void Creature::onDisappear() { if(m_disappearEvent) m_disappearEvent->cancel(); m_oldPosition = m_position; // a pair onDisappear and onAppear events are fired even when creatures walks or turns, // so we must filter auto self = static_self_cast<Creature>(); m_disappearEvent = g_dispatcher.addEvent([self] { self->m_removed = true; self->stopWalk(); self->callLuaField("onDisappear"); // invalidate this creature position if(!self->isLocalPlayer()) self->setPosition(Position()); self->m_oldPosition = Position(); self->m_disappearEvent = nullptr; }); }
void FuncDefAst::walk() { if (checkIsNotWalking()) { return ; } if (nodeType != T_CFUNCDEF_DECTIONSFS_DECTOR_COMPSTM) { //std::cout<<"error: nodetype error in FuncDefAst"<<std::endl; LogiMsg::logi("error: nodetype error in FuncDefAst", getLineno()); stopWalk(); return ; } //std::cout << "walk in T_CFUNCDEF_DECTIONSFS_DECTOR_COMPSTM" << endl; LogiMsg::logi("walk in T_CFUNCDEF_DECTIONSFS_DECTOR_COMPSTM", getLineno()); if ((childs.at(1)->nodeType != T_CDIRDECTOR_DIRDECTOR_CALL_PARAMTYPELIST) && (childs.at(1)->nodeType != T_CDIRDECTOR_DIRDECTOR_CALL_VOID)) { /*std::cout<<"error in FuncDefAst: the children's type of function is not param either void at line " <<getLineno()<<std::endl;*/ LogiMsg::logi("error in FuncDefAst: the children's type of function is not param either void", getLineno()); stopWalk(); return ; } childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } Scope *tmpScope = new Scope(); tmpScope->setReturnTypeClass(&(s_context->tmpDeclType)); tmpScope->setCurStartOffset(0); tmpScope->setTotalByteSize(0); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } tmpScope->setScopeName(s_context->tmpIdenName); if (Scope::resolveScope(tmpScope->scopeName, Scope::SCOPE_GLOBALFUNC)) { /*std::cout<<"error in FuncDefAst: the function" << tmpScope->scopeName << " has been defined at line "<<getLineno()<<std::endl;*/ string erroStr = "error in FuncDefAst: the function" + tmpScope->scopeName + " has been defined"; LogiMsg::logi(erroStr, getLineno()); delete tmpScope; stopWalk(); return ; } if (Scope::resolveScope(tmpScope->scopeName, Scope::SCOPE_GLOBALFUNCCHAN)) { /*std::cout<<"error in FuncDefAst: the function" << tmpScope->scopeName << " has been defined at line "<<getLineno()<<std::endl;*/ string erroStr = "error in FuncDefAst: the function" + tmpScope->scopeName + " has been defined"; LogiMsg::logi(erroStr, getLineno()); delete tmpScope; stopWalk(); return ; } Scope *tmpFuncImp = NULL; tmpFuncImp = Scope::resolveScope(tmpScope->scopeName, Scope::SCOPE_GLOBALFUNCDECL); if ( NULL != tmpFuncImp ) { delete tmpScope; tmpScope = tmpFuncImp; tmpScope->clearSymbolSeqList(); tmpScope->setScopeType(Scope::SCOPE_GLOBALFUNCCHAN); //replace tmpScope->setCurStartOffset(0); tmpScope->setTotalByteSize(0); Scope::setCurScope(tmpScope); } else { tmpScope->setScopeType(Scope::SCOPE_GLOBALFUNC); Scope::pushScope(Scope::s_curScope, tmpScope); Scope::setCurScope(tmpScope); } if (s_context->tmpParaWithoutIdNum) { //std::cout<<"error in FuncDefAst: argument list do not have identifier"<<std::endl; LogiMsg::logi("error in FuncDefAst: argument list do not have identifier", getLineno()); stopWalk(); return ; } if (s_context->tmpParaWithIdNum) { for (int i = 0; i <s_context->tmpParaWithIdNum ; i++) { /*Symbol *tmpsymbol = new Symbol(Symbol::SYMBOL_VAR); tmpsymbol->symbolName = s_context->tmpParaWithIdList.at(i).symbolName; tmpsymbol->typeClass.clone(&(s_context->tmpParaWithIdList.at(i).typeClass));*/ if (NULL != Scope::s_curScope->searchSymbolVarMap(s_context->tmpParaWithIdList.at(i).symbolName)) { /*std::cout << "error in FuncDefAst: duplicate argument " << s_context->tmpParaWithIdList.at(i).symbolName << " at line " << getLineno() << std::endl;*/ string errorStr = "error in FuncDefAst: duplicate argument " + s_context->tmpParaWithIdList.at(i).symbolName; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return ; } Symbol *tmpsymbol = new Symbol(Symbol::SYMBOL_VAR); tmpsymbol->setSymbolName(s_context->tmpParaWithIdList.at(i).symbolName); tmpsymbol->setTypeClass(&(s_context->tmpParaWithIdList.at(i).typeClass)); /*if (Scope::s_curScope->symbolVarMap.find(tmpsymbol->symbolName)!=Scope::s_curScope->symbolVarMap.end()) { std::cout<<"error in FuncDefAst: duplicate argument at line "<<getLineno()<<std::endl; delete tmpsymbol; exit(0); }*/ Scope::s_curScope->defineSymbol(tmpsymbol); } list<Symbol *>::reverse_iterator r_itr; for (r_itr= Scope::s_curScope->symbolSeqList.rbegin(); r_itr!=Scope::s_curScope->symbolSeqList.rend(); r_itr++) { Scope::s_curScope->incTotalByteSize((*r_itr)->getByteSize()); (*r_itr)->setOffset(Scope::s_curScope->getTotalByteSize()); } Scope::s_curScope->incTotalByteSize(4); } childs.at(2)->walk(); if (checkIsNotWalking()) { return ; } Scope::setCurScope(Scope::encloseScope(Scope::s_curScope)); }
void PostfixExpAst::walk() { if (checkIsNotWalking()) { return ; } switch(nodeType) { case T_CPOSTEXP_POSTEXP_ARRAY_EXP: { LogiMsg::logi("walk in T_CPOSTEXP_POSTEXP_ARRAY_EXP", getLineno()); break; } case T_CPOSTEXP_POSTEXP_CALL_VOID: { //std::cout << "walk in T_CPOSTEXP_POSTEXP_CALL_VOID" << endl; LogiMsg::logi("walk in T_CPOSTEXP_POSTEXP_CALL_VOID", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } if (s_context->tmpOpType==ItmCode::OPR_CLASS_REFLIST) { Reg *result=Reg::getReg(0, ((Scope *)(s_context->getExpListLast()))->getReturnTypeClass()->getTypeSfType()); vector<void* >* refList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); ItmCode *tmpCode=new ItmCode(ItmCode::IR_CALLCLASSFUNC, ItmCode::OPR_CLASS_REFLIST,(void *)refList, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_REGISTER, result); Scope::s_curScope->addItemCode(tmpCode); s_context->clearContext(); s_context->tmpOpType=ItmCode::OPR_REGISTER; s_context->tmpExpReg=result; } else { Scope *tmpScope=NULL; if (NULL != (tmpScope=Scope::resolveClassFuncScope(Scope::s_curScope, s_context->tmpIdenName))) { Reg *result=Reg::getReg(0, tmpScope->getReturnTypeClass()->getTypeSfType()); ItmCode *tmpCode=new ItmCode(ItmCode::IR_CALLCLASSFUNC, ItmCode::OPR_SCOPE ,(void *)tmpScope, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_REGISTER, result); Scope::s_curScope->addItemCode(tmpCode); s_context->clearContext(); s_context->tmpOpType=ItmCode::OPR_REGISTER; s_context->tmpExpReg=result; } else if (NULL != (tmpScope=Scope::s_curScope->resolveGlobalFuncScope(s_context->tmpIdenName))) { Reg *result=Reg::getReg(0, tmpScope->getReturnTypeClass()->getTypeSfType()); ItmCode *tmpCode=new ItmCode(ItmCode::IR_CALLFUNC, ItmCode::OPR_SCOPE ,(void *)tmpScope, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_REGISTER, result); Scope::s_curScope->addItemCode(tmpCode); s_context->clearContext(); s_context->tmpOpType=ItmCode::OPR_REGISTER; s_context->tmpExpReg=result; } else { /*std::cout << "error: in T_CPOSTEXP_POSTEXP_CALL_VOID the func " << s_context->tmpIdenName << "is not exist" << std::endl;*/ string errorStr = "error: in T_CPOSTEXP_POSTEXP_CALL_VOID the func " + s_context->tmpIdenName + "is not exist"; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return; } } break; } case T_CPOSTEXP_POSTEXP_CALL_ARGEXPLIST: { //std::cout << "walk in T_CPOSTEXP_POSTEXP_CALL_ARGEXPLIST"<< std::endl; LogiMsg::logi("walk in T_CPOSTEXP_POSTEXP_CALL_ARGEXPLIST", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } if (s_context->tmpOpType==ItmCode::OPR_CLASS_REFLIST) { Reg *result=Reg::getReg(0, ((Scope *)(s_context->getExpListLast()))->getReturnTypeClass()->getTypeSfType()); vector<void* >* refList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } vector<void* >* arguList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); ItmCode *tmpCode=new ItmCode(ItmCode::IR_CALLCLASSFUNC, ItmCode::OPR_CLASS_REFLIST,(void *)refList, ItmCode::OPR_ARGLIST, (void *)arguList, ItmCode::OPR_REGISTER, result); Scope::s_curScope->addItemCode(tmpCode); s_context->clearContext(); s_context->tmpOpType=ItmCode::OPR_REGISTER; s_context->tmpExpReg=result; } else { Scope *tmpScope=NULL; if (NULL != (tmpScope=Scope::resolveClassFuncScope(Scope::s_curScope, s_context->tmpIdenName))) { Reg *result=Reg::getReg(0, tmpScope->getReturnTypeClass()->getTypeSfType()); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } vector<void* >* arguList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); ItmCode *tmpCode=new ItmCode(ItmCode::IR_CALLCLASSFUNC, ItmCode::OPR_SCOPE ,(void *)tmpScope, ItmCode::OPR_ARGLIST, (void *)arguList, ItmCode::OPR_REGISTER, result); Scope::s_curScope->addItemCode(tmpCode); s_context->clearContext(); s_context->tmpOpType=ItmCode::OPR_REGISTER; s_context->tmpExpReg=result; } else if (NULL != (tmpScope=Scope::s_curScope->resolveGlobalFuncScope(s_context->tmpIdenName))) { Reg *result=Reg::getReg(0, tmpScope->getReturnTypeClass()->getTypeSfType()); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } vector<void* >* arguList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); ItmCode *tmpCode=new ItmCode(ItmCode::IR_CALLFUNC, ItmCode::OPR_SCOPE ,(void *)tmpScope, ItmCode::OPR_ARGLIST, (void *)arguList, ItmCode::OPR_REGISTER, result); Scope::s_curScope->addItemCode(tmpCode); s_context->clearContext(); s_context->tmpOpType=ItmCode::OPR_REGISTER; s_context->tmpExpReg=result; } else { /*std::cout << "error: in T_CPOSTEXP_POSTEXP_CALL_ARGEXPLIST the func " << s_context->tmpIdenName << "is not exist" << std::endl;*/ string errorStr = "error: in T_CPOSTEXP_POSTEXP_CALL_ARGEXPLIST the func " + s_context->tmpIdenName + "is not exist"; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return; } } break; } case T_CPOSTEXP_POSTEXP_REF_ID: { //std::cout << "walk in T_CPOSTEXP_POSTEXP_REF_ID" << endl; LogiMsg::logi("walk in T_CPOSTEXP_POSTEXP_REF_ID", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } if (s_context->tmpExpSymbol->typeClass.scopeType==NULL) { /*std::cout << "error in T_CPOSTEXP_POSTEXP_REF_ID the id " << s_context->tmpExpSymbol->getSymbolName() << " is not a class type " << std::endl;*/ string errorStr = "error in T_CPOSTEXP_POSTEXP_REF_ID the id " + s_context->tmpExpSymbol->getSymbolName() + " is not a class type "; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return; } Symbol *tmpSymbol=s_context->tmpExpSymbol; childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } if (parent->nodeType==NodeAst::T_CPOSTEXP_POSTEXP_CALL_ARGEXPLIST || parent->nodeType==NodeAst::T_CPOSTEXP_POSTEXP_CALL_VOID) { Scope *tmpScope=Scope::resolveClassFuncScope(tmpSymbol->typeClass.scopeType, s_context->tmpIdenName); if (tmpScope==NULL) { /*std::cout << "error: there is no func named " << s_context->tmpIdenName << "at line " << getLineno() <<std::endl;*/ string errorStr = "error: there is no func named " + s_context->tmpIdenName; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return; } s_context->clearContext(); s_context->clearExpList(); s_context->addToExpList((void *)tmpSymbol); s_context->addToExpList((void *)tmpScope); s_context->tmpOpType=ItmCode::OPR_CLASS_REFLIST; } else { Symbol *tmpMemSymbol=Scope::resolveSymbolMemVar(tmpSymbol->typeClass.scopeType, s_context->tmpIdenName); if (tmpMemSymbol==NULL) { /*std::cout << "error: there is no var named " << s_context->tmpIdenName << "at line " << getLineno() <<std::endl;*/ string errorStr = "error: there is no var named " + s_context->tmpIdenName; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return; } s_context->clearContext(); s_context->clearExpList(); s_context->addToExpList((void *)tmpSymbol); s_context->addToExpList((void *)tmpMemSymbol); s_context->tmpOpType=ItmCode::OPR_CLASS_REFLIST; } break; } case T_CPOSTEXP_POSTEXP_INC_OP: { childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } Symbol *tmpSymbol = NULL; vector<void* >* tmpRefList = NULL; if (s_context->tmpOpType == ItmCode::OPR_SYMBOL) { tmpSymbol = s_context->tmpExpSymbol; Reg *tmpReg=processChildOperand(0); ItmCode *tmpCode = new ItmCode(ItmCode::IR_INC_OP_POST, ItmCode::OPR_REGISTER, (void *)tmpReg, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_SYMBOL, (void *)(tmpSymbol)); Scope::s_curScope->addItemCode(tmpCode); } else if (s_context->tmpOpType == ItmCode::OPR_CLASS_REFLIST) { tmpRefList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); Reg *tmpReg=processChildOperand(0); ItmCode *tmpCode = new ItmCode(ItmCode::IR_INC_OP_POST, ItmCode::OPR_REGISTER, (void *)tmpReg, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_CLASS_REFLIST, (void *)(tmpRefList)); Scope::s_curScope->addItemCode(tmpCode); } else { /*std::cout << "error in T_CPOSTEXP_POSTEXP_INC_OP: the op is not left value at line " << getLineno() <<std::endl;*/ LogiMsg::logi("error in T_CPOSTEXP_POSTEXP_INC_OP: the op is not left value", getLineno()); stopWalk(); return; } break; } case T_CPOSTEXP_POSTEXP_DEC_OP: { childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } Symbol *tmpSymbol = NULL; vector<void* >* tmpRefList = NULL; if (s_context->tmpOpType == ItmCode::OPR_SYMBOL) { tmpSymbol = s_context->tmpExpSymbol; Reg *tmpReg=processChildOperand(0); ItmCode *tmpCode = new ItmCode(ItmCode::IR_DEC_OP_POST, ItmCode::OPR_REGISTER, (void *)tmpReg, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_SYMBOL, (void *)(tmpSymbol)); Scope::s_curScope->addItemCode(tmpCode); } else if (s_context->tmpOpType == ItmCode::OPR_CLASS_REFLIST) { tmpRefList = ItmCode::copyVectorToAllExpList(s_context->tmpExpList); Reg *tmpReg=processChildOperand(0); ItmCode *tmpCode = new ItmCode(ItmCode::IR_DEC_OP_POST, ItmCode::OPR_REGISTER, (void *)tmpReg, ItmCode::OPR_INVALID, NULL, ItmCode::OPR_CLASS_REFLIST, (void *)(tmpRefList)); Scope::s_curScope->addItemCode(tmpCode); } else { /*std::cout << "error in T_CPOSTEXP_POSTEXP_INC_OP: the op is not left value at line " << getLineno() <<std::endl;*/ LogiMsg::logi("error in T_CPOSTEXP_POSTEXP_INC_OP: the op is not left value", getLineno()); stopWalk(); return; } break; } default: { //std::cout << "error in PostfixExpAst: nodeType is invalid" << std::endl; LogiMsg::logi("error in PostfixExpAst: nodeType is invalid", getLineno()); stopWalk(); return ; break; } } }
void SelectionStmAst::walk() { if (checkIsNotWalking()) { return ; } switch(nodeType) { case T_CSELSTM_IF_EXP_STM: { LogiMsg::logi("walk in T_CSELSTM_IF_EXP_STM", getLineno()); list<ItmCode *> trueLabelList; ItmCode::copyLabelList(trueLabelList, s_context->tmpTrueLabelList); s_context->tmpTrueLabelList.clear(); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } Reg *r = processChildOperand(0); if (NULL == r) { LogiMsg::logi("error in T_CSELSTM_IF_EXP_STM: conditon expression is invalid", getLineno()); stopWalk(); return ; } if (checkNodeTypeReturnValueIsBool(childs.at(0)->getNodeType()) || (T_CASSIGNEXP_CONDITIONALEXP == childs.at(0)->getNodeType() && !childs.at(0)->childs.empty() && checkNodeTypeReturnValueIsBool(childs.at(0)->childs.at(0)->getNodeType())) ) { } else { r = ItmCode::genCodeRegIsTrueAssign(r); if (NULL == r) { stopWalk(); return ; } s_context->tmpExpReg = r; } ItmCode *newCode = ItmCode::genCodeRegIfNotGotoLabel(r, NULL); s_context->addToFalseLabelList(newCode); Symbol *trueLabel = new Symbol(Symbol::SYMBOL_LABEL); Scope::s_curScope->defineSymbol(trueLabel); ItmCode::genCodeEmitLabel(trueLabel); s_context->backFillTrueLabelList(trueLabel); ItmCode::copyLabelList(s_context->tmpTrueLabelList, trueLabelList); list<ItmCode *> falseLabelList; ItmCode::copyLabelList(falseLabelList, s_context->tmpFalseLabelList); s_context->tmpFalseLabelList.clear(); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } Symbol *falseLabel = new Symbol(Symbol::SYMBOL_LABEL); Scope::s_curScope->defineSymbol(falseLabel); ItmCode::genCodeEmitLabel(falseLabel); ItmCode::copyLabelList(s_context->tmpFalseLabelList, falseLabelList); s_context->backFillFalseLabelList(falseLabel); break; } case T_CSELSTM_IF_EXP_STM_ELSE_STM: { LogiMsg::logi("walk in T_CSELSTM_IF_EXP_STM_ELSE_STM", getLineno()); list<ItmCode *> trueLabelList; ItmCode::copyLabelList(trueLabelList, s_context->tmpTrueLabelList); s_context->tmpTrueLabelList.clear(); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } Reg *r = processChildOperand(0); if (NULL == r) { LogiMsg::logi("error in T_CSELSTM_IF_EXP_STM_ELSE_STM: conditon expression is invalid", getLineno()); stopWalk(); return ; } if (checkNodeTypeReturnValueIsBool(childs.at(0)->getNodeType()) || (T_CASSIGNEXP_CONDITIONALEXP == childs.at(0)->getNodeType() && !childs.at(0)->childs.empty() && checkNodeTypeReturnValueIsBool(childs.at(0)->childs.at(0)->getNodeType())) ) { } else { r = ItmCode::genCodeRegIsTrueAssign(r); if (NULL == r) { stopWalk(); return ; } s_context->tmpExpReg = r; } ItmCode *newCode = ItmCode::genCodeRegIfNotGotoLabel(r, NULL); s_context->addToFalseLabelList(newCode); Symbol *trueLabel = new Symbol(Symbol::SYMBOL_LABEL); Scope::s_curScope->defineSymbol(trueLabel); ItmCode::genCodeEmitLabel(trueLabel); s_context->backFillTrueLabelList(trueLabel); ItmCode::copyLabelList(s_context->tmpTrueLabelList, trueLabelList); list<ItmCode *> falseLabelList; ItmCode::copyLabelList(falseLabelList, s_context->tmpFalseLabelList); s_context->tmpFalseLabelList.clear(); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } ItmCode *outNewCode = ItmCode::genCodeGotoOutLabel(NULL); Symbol *falseLabel = new Symbol(Symbol::SYMBOL_LABEL); Scope::s_curScope->defineSymbol(falseLabel); ItmCode::genCodeEmitLabel(falseLabel); ItmCode::copyLabelList(s_context->tmpFalseLabelList, falseLabelList); s_context->backFillFalseLabelList(falseLabel); childs.at(2)->walk(); if (checkIsNotWalking()) { return ; } Symbol *ifElseOutLabel = new Symbol(Symbol::SYMBOL_LABEL); Scope::s_curScope->defineSymbol(ifElseOutLabel); ItmCode::genCodeEmitLabel(ifElseOutLabel); ItmCode::setGotoOutLabel(outNewCode, ifElseOutLabel); break; } default: { LogiMsg::logi("error in SelectionStmAst: nodeType is invalid", getLineno()); stopWalk(); return ; break; } } }
void ClassSpecifierAst::walk() { if (checkIsNotWalking()) { return ; } switch (nodeType){ case T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST:{ //std::cout << "walk in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST" << endl; LogiMsg::logi("walk in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } //Scope *tmpScope = new Scope(); if (Scope::resolveScope(s_context->tmpIdenName, Scope::SCOPE_CLASS)) { /*std::cout << "error in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST: " << s_context->tmpIdenName << " has been defined at line " << getLineno() << std::endl;*/ string errorStr = "error in T_CCLASSSF_CLASS_ID_CLASSDECTIONLIST: " + s_context->tmpIdenName + " has been defined"; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return ; } Scope *tmpScope = new Scope(); tmpScope->setTotalByteSize(0); tmpScope->setTotalFuncByteSize(0); tmpScope->initClassScope(s_context->tmpIdenName); Scope::pushScope(Scope::s_curScope,tmpScope); Scope::setCurScope(tmpScope); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } Scope::setCurScope(Scope::encloseScope(Scope::s_curScope)); //std::cout<<"safsadfafasfsafasf"<<Scope::s_curScope->scopeName<<std::endl; TypeClass tmp; //tmp.scopeType = tmpScope; tmp.setScopeType(tmpScope); tmp.typeSfType = TypeClass::SF_INT; s_context->clearContext(); s_context->tmpDeclType.clone(&tmp); break; } case T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST:{ //std::cout << "walk in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST" << endl; LogiMsg::logi("walk in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } //Scope *tmpScope = new Scope(); if (Scope::resolveScope(s_context->tmpIdenName, Scope::SCOPE_CLASS)) { /*std::cout << "error in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: " << s_context->tmpIdenName << " has been defined at line " << getLineno() << std::endl;*/ string errorStr = "error in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: " + s_context->tmpIdenName + " has been defined"; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return ; } //tmpScope->initClassScope(s_context->tmpIdenName); if (childs.at(1)->nodeType!=T_CTERMINATE_CIDLIST_ID) { /*std::cout << "sorry in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: our compiler do not support multiple inheritance at line " << getLineno() << std::endl;*/ LogiMsg::logi("sorry in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: our compiler do not support multiple inheritance", getLineno()); stopWalk(); return ; } Scope *tmpScope = new Scope(); tmpScope->initClassScope(s_context->tmpIdenName); childs.at(1)->walk(); if (checkIsNotWalking()) { return ; } Scope *superScope = Scope::resolveScope(s_context->tmpIdenName, Scope::SCOPE_CLASS); if (!superScope) { /*std::cout<<"error in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: the super class " << s_context->tmpIdenName << " does not exit at line " << getLineno() << std::endl;*/ string errorStr = "error in T_CCLASSSF_CLASS_ID_IDLIST_CLASSDECTIONLIST: the super class " + s_context->tmpIdenName + " does not exit"; LogiMsg::logi(errorStr, getLineno()); delete tmpScope; stopWalk(); return ; } tmpScope->setSuperClass(superScope); tmpScope->setTotalByteSize(tmpScope->getSuperClass()->getTotalByteSize()); tmpScope->setTotalFuncByteSize(tmpScope->getSuperClass()->getTotalFuncByteSize()); Scope::pushScope(Scope::s_curScope,tmpScope); Scope::setCurScope(tmpScope); childs.at(2)->walk(); if (checkIsNotWalking()) { return ; } Scope::setCurScope(Scope::encloseScope(Scope::s_curScope)); TypeClass tmp; //tmp.scopeType = tmpScope; tmp.setScopeType(tmpScope); tmp.typeSfType = TypeClass::SF_INT; s_context->clearContext(); s_context->tmpDeclType.clone(&tmp); break; } case T_CCLASSSF_CLASS_ID:{ //std::cout << "walk in T_CCLASSSF_CLASS_ID" << endl; LogiMsg::logi("walk in T_CCLASSSF_CLASS_ID", getLineno()); childs.at(0)->walk(); if (checkIsNotWalking()) { return ; } Scope *tmpScope = Scope::resolveScope(s_context->tmpIdenName,Scope::SCOPE_CLASS); if (!tmpScope) { /*std::cout<<"error in T_CCLASSSF_CLASS_ID: the super class " << s_context->tmpIdenName << " does not exit at line "<<getLineno()<<std::endl;*/ string errorStr = "error in T_CCLASSSF_CLASS_ID: the super class " + s_context->tmpIdenName + " does not exit"; LogiMsg::logi(errorStr, getLineno()); stopWalk(); return ; } TypeClass tmp; //tmp.scopeType = tmpScope; tmp.setScopeType(tmpScope); tmp.typeSfType = TypeClass::SF_INT; s_context->clearContext(); s_context->tmpDeclType.clone(&tmp); break; } default:{ //std::cout << "error in ClassSpecifierAst: nodeType is invalid" << std::endl; LogiMsg::logi("error in ClassSpecifierAst: nodeType is invalid", getLineno()); stopWalk(); return ; break; } } }