uint32 AsScene1307Key::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); switch (messageNum) { case 0x1011: if (_isClickable) { sendMessage(_parentScene, 0x4826, 0); stRemoveKey(); messageResult = 1; } break; case 0x2000: _isClickable = param.asInteger() != 0; break; case 0x2001: setSubVar(VA_CURR_KEY_SLOT_NUMBERS, _keyIndex, param.asInteger()); stMoveKey(); break; case 0x2003: playSound(3); stUnlock(); break; case 0x2004: playSound(2); stInsert(); break; } return messageResult; }
void buildSymtab(TreeNode* node,StTable* handle,TreeNode* paraOfFun,ValueType funType,char* funcName){ int i; int count=0; StTable* newHandle; TreeNode* paraNode; StNode* stPtr; StPara* stParaPtr; /*** * compound statement is a new scope * */ if(node->kind==StmtK && node->subkind.stmtType==ComStmt){ /* * create new scope in the symbol table * */ newHandle=stNewScope(handle); newHandle->funType=funType; strcpy(newHandle->funcName,funcName); /*** * if it is the begin of a function, * need to insert the parameters into symbol table * */ while(paraOfFun!=NULL){ paraOfFun->handle=newHandle; stPtr=stInsert(newHandle,paraOfFun->attr.name,paraOfFun->type,paraOfFun->lineno,0); if(stPtr==NULL){ printf("error:line %d:redeclaration of arguement %s\n",node->lineno,node->attr.name); Error=1; } paraOfFun=paraOfFun->sibling; } } else{ newHandle=handle; } node->handle=newHandle; if(node->kind==DeclK){ if(node->subkind.declType==SimVarDcl){ /** * simple variable declaration, insert into symbol table * **/ stPtr=stInsert(node->handle,node->attr.name,node->type,node->lineno,0); if(stPtr==NULL){ printf("error:line %d:redeclaration of variable %s\n",node->lineno,node->attr.name); Error=1; } /* * preorder travel * */ for(i=0;i<MAXCHILDREN;i++){ if(node->child[i]!=NULL){ buildSymtab(node->child[i],node->handle,NULL,funType,funcName); } } if(node->sibling!=NULL){ buildSymtab(node->sibling,handle,NULL,funType,funcName); } } else if(node->subkind.declType==ArrVarDcl){ /** * array declaration * **/ stPtr=stInsert(node->handle,node->attr.name,node->type,node->lineno,0); if(stPtr==NULL){ printf("error:line %d:redeclaration of variable %s\n",node->lineno,node->attr.name); Error=1; } /***** * preorder travel * ***/ for(i=0;i<MAXCHILDREN;i++){ if(node->child[i]!=NULL){ buildSymtab(node->child[i],node->handle,NULL,funType,funcName); } } if(node->sibling!=NULL){ buildSymtab(node->sibling,handle,NULL,funType,funcName); } } else{ /**** * function declaration * ****/ stPtr=stInsert(node->handle,node->attr.name,node->type,node->lineno,1); if(stPtr==NULL){ printf("error:line %d:redeclaration of function %s\n",node->lineno,node->attr.name); Error=1; } /**need to store the parameter with the function name**/ else{ paraNode=node->child[0]; while(paraNode!=NULL){ if(stPtr->para==NULL){ stPtr->para=(StPara*)malloc(sizeof(StPara)); stParaPtr=stPtr->para; stParaPtr->type=paraNode->type; stParaPtr->next=NULL; count++; } else{ stParaPtr->next=(StPara*)malloc(sizeof(StPara)); stParaPtr=stParaPtr->next; stParaPtr->type=paraNode->type; stParaPtr->next=NULL; count++; } paraNode=paraNode->sibling; } stPtr->count=count; /******* * the statement is in new function scope * ********/ buildSymtab(node->child[1],node->handle,node->child[0],node->type,node->attr.name); /******** * actually, no sibling * but for formalize * *******/ if(node->sibling!=NULL){ buildSymtab(node->sibling,handle,NULL,funType,funcName); } } } } else{ /******* * just preorder travel for other case * *******/ for(i=0;i<MAXCHILDREN;i++){ if(node->child[i]!=NULL){ buildSymtab(node->child[i],node->handle,NULL,funType,funcName); } } if(node->sibling!=NULL){ buildSymtab(node->sibling,handle,NULL,funType,funcName); } } }