// Attach the variable to the SemanticAnalysis node tree. void attachVar(Context& context, const String& name, const AST::Node<AST::TypeVar>& astTypeVarNode, SEM::Var* const var, const Debug::VarInfo::Kind varKind) { assert(var->isBasic()); const auto insertResult = insertVar(context.scopeStack().back(), name, var); if (!insertResult.second) { const auto existingVar = insertResult.first->second; throw ErrorException(makeString("Variable name '%s' at position %s duplicates existing variable of the same name at position %s.", name.c_str(), astTypeVarNode.location().toString().c_str(), existingVar->debugInfo()->declLocation.toString().c_str())); } var->setDebugInfo(makeVarInfo(varKind, astTypeVarNode)); }
void LocalsTree::refreshFrame( const Frame &f ){ HTREEITEM it=GetChildItem( f.item ); for( int n=0;n<f.env->decls->size();++n ){ Decl *d=f.env->decls->decls[n]; if( !(d->kind & (DECL_LOCAL|DECL_PARAM) ) ) continue; char name[256]; d->getName( name ); if( !isalpha( name[0] ) ) continue; it=insertVar( (char*)f.frame+d->offset,d,name,it,f.item ); } }
void ConstsTree::reset( Environ *env ){ HTREEITEM it=GetChildItem( TVI_ROOT ); for( int k=0;k<env->decls->size();++k ){ Decl *d=env->decls->decls[k]; if( !(d->kind & (DECL_GLOBAL) ) ) continue; if( d->type->constType() ){ char name[256]; d->getName( name ); it=insertVar( 0,d,name,it,TVI_ROOT ); } } }
void GlobalsTree::refresh(){ if( !module || !envron ) return; HTREEITEM it=GetChildItem( TVI_ROOT ); for( int k=0;k<envron->decls->size();++k ){ Decl *d=envron->decls->decls[k]; if( !(d->kind & (DECL_GLOBAL) ) ) continue; if( !d->type->constType() ){ char name[256]; d->getName( name ); void *var=0; module->findSymbol( ("_v"+string(name)).c_str(),(int*)&var ); it=insertVar( var,d,name,it,TVI_ROOT ); } } }
bool LineOfSymbols::replaceVar(const QString &pattern, modbusVar *var, unsigned int pos) { variable curVar; QVector<quint16> curSymbols; for(int i=0;i<vars.count();i++) { unsigned char startPos = vars[i].view.getPosition(); unsigned char endPos = startPos + vars[i].view.getLength()-1; if((pos>=startPos)&&(pos<=endPos)) { curVar = vars[i]; for(int j=startPos;j<=endPos;j++) curSymbols+=symbols.at(j); break; } } for(int i=0;i<vars.count();i++) { unsigned char startPos = vars[i].view.getPosition(); unsigned char endPos = startPos + vars[i].view.getLength()-1; if((pos>=startPos)&&(pos<=endPos)) { vars.remove(i); for(int j=startPos;j<=endPos;j++) { if(j<symbols.count()) deleteSymbol(startPos); } bool res = insertVar(pattern,var,startPos); if(res==false) { for(int j=startPos;j<=endPos;j++) { insertSymbol(curSymbols[j-startPos],j); } vars+=curVar; } return res; } } return false; }
HTREEITEM DebugTree::insertVar( void *var,Decl *d,const string &name,HTREEITEM it,HTREEITEM parent ){ string s=name; ConstType *ct=d->type->constType(); StructType *st=d->type->structType(); VectorType *vt=d->type->vectorType(); if( ct ){ Type *t=ct->valueType; s+=typeTag(t); if( t->intType() ){ s+="="+itoa( ct->intValue ); }else if( t->floatType() ){ s+="="+ftoa( ct->floatValue ); }else if( t->stringType() ){ s+="=\""+ct->stringValue+'\"'; } }else if( var ){ Type *t=d->type; s+=typeTag( t ); if( t->intType() ){ s+="="+itoa( *(int*)var ); }else if( t->floatType() ){ s+="="+ftoa( *(float*)var ); }else if( t->stringType() ){ BBStr *str=*(BBStr**)var; if( str ) s+="=\""+*str+'\"'; else s+="=\"\""; }else if( st ){ var=*(void**)var; if( var ) var=*(void**)var; if( !var ) s+=" (Null)"; } } if( it ){ if( GetItemText( it )!=s.c_str() ){ SetItemText( it,s.c_str() ); } }else{ it=InsertItem( s.c_str(),parent ); } ++st_nest; if( st ){ if( var ){ if( st_nest<4 ){ HTREEITEM st_it=GetChildItem( it ); for( int k=0;k<st->fields->size();++k ){ Decl *st_d=st->fields->decls[k]; void *st_var=(char*)var+st_d->offset; char name[256]; st_d->getName( name ); st_it=insertVar( st_var,st_d,name,st_it,it ); } } }else{ while( HTREEITEM t=GetChildItem( it ) ){ DeleteItem( t ); } } } --st_nest; return it ? GetNextSiblingItem( it ) : 0; }
/* procedure BLOCK; begin if TOKEN = "constsym" then begin repeat GET(TOKEN); if TOKEN != "identsym" then ERROR; GET(TOKEN); if TOKEN != "eqsym" then ERROR; GET(TOKEN); if TOKEN != NUMBER then ERROR; GET(TOKEN) until TOKEN != "commasym"; if TOKEN != "semicolomsym" then ERROR; GET(TOKEN) end; if TOKEN = "intsym" then begin repeat GET(TOKEN); if TOKEN != "identsym" then ERROR; GET(TOKEN) until TOKEN != "commasym"; if TOKEN != "semicolomsym" then ERROR; GET(TOKEN) end; while TOKEN = "procsym" do begin GET(TOKEN); if TOKEN != “identsym” then ERROR; GET(TOKEN); if TOKEN != "semicolomsym" then ERROR; GET(TOKEN); BLOCK; if TOKEN != "semicolomsym" then ERROR; GET(TOKEN) end; STATEMENT end; */ int block() { char *temp = NULL; int numVars = 0; g_addr = 4; if (token == constsym) { do { getNextToken(); if (token != identsym) { error(4); return 4; } getNextToken(); temp = getID(token); getNextToken(); if (token != eqsym) { error(3); return 3; } getNextToken(); if (token != numbersym) { error(2); return 2; } getNextToken(); if (insertConst(temp, token)) { return 1; } getNextToken(); } while (token == commasym); if (token != semicolonsym) { error(5); return 5; } getNextToken(); } if (token == intsym) { do { getNextToken(); if (token != identsym) { error(4); return 4; } getNextToken(); if (insertVar(getID(token))) { return 1; } numVars++; getNextToken(); } while (token == commasym); if (token != semicolonsym) { error(5); return 5; } // Increment the stack ptr by the number of variables emit(inc, 0, numVars); getNextToken(); } if (token == procsym) { // Throw error because we are not implementing procedure yet error(21); return 21; } return 0; }
/* procedure BLOCK; begin if TOKEN = "constsym" then begin repeat GET(TOKEN); if TOKEN != "identsym" then ERROR; GET(TOKEN); if TOKEN != "eqsym" then ERROR; GET(TOKEN); if TOKEN != NUMBER then ERROR; GET(TOKEN) until TOKEN != "commasym"; if TOKEN != "semicolomsym" then ERROR; GET(TOKEN) end; if TOKEN = "intsym" then begin repeat GET(TOKEN); if TOKEN != "identsym" then ERROR; GET(TOKEN) until TOKEN != "commasym"; if TOKEN != "semicolomsym" then ERROR; GET(TOKEN) end; while TOKEN = "procsym" do begin GET(TOKEN); if TOKEN != “identsym” then ERROR; GET(TOKEN); if TOKEN != "semicolomsym" then ERROR; GET(TOKEN); BLOCK; if TOKEN != "semicolomsym" then ERROR; GET(TOKEN) end; STATEMENT end; */ int block() { //printf("Block\n"); int errorCode = 0; char *temp = NULL; int numVars = 0; g_addr = 4; emit(inc,0,4); if (token == constsym) { do { getNextToken(); if (token != identsym) { error(4); return 4; } getNextToken(); temp = getID(token); getNextToken(); if (token != eqsym) { if (token == becomessym) { error(1); return 1; } else { error(3); return 3; } } getNextToken(); if (token != numbersym) { error(2); return 2; } getNextToken(); if (insertConst(temp, token)) { return 1; } getNextToken(); } while (token == commasym); if (token != semicolonsym) { error(5); return 5; } getNextToken(); } if (token == intsym) { //printf("Int Symbol Found!"); do { getNextToken(); if (token != identsym) { error(4); return 4; } getNextToken(); if (insertVar(getID(token))) { return 1; } numVars++; getNextToken(); } while (token == commasym); if (token != semicolonsym) { error(5); return 5; } // Increment the stack ptr by the number of variables emit(inc, 0, numVars); getNextToken(); } if (token == procsym) { // Throw error because we are not implementing procedure yet error(21); return 21; } if (token == periodsym) { error(7); return 7; } errorCode = statement(); if (errorCode) return errorCode; // Propogate error up emit(opr,0,0); return 0; }