void openScopes(Entry * object) { int cur_scope_separator_pos = 0; int last_scope_separator_pos = 0; while (0 <= (cur_scope_separator_pos = object->name.find("::", last_scope_separator_pos))) { QString scope = object->name.mid(last_scope_separator_pos, cur_scope_separator_pos - last_scope_separator_pos); last_scope_separator_pos = cur_scope_separator_pos + 2; Entry * current_namespace = openNamespace(scope); if (!m_scopeStack.isEmpty()) { m_scopeStack.last()->scope->addSubEntry(current_namespace); } m_scopeStack.append(new ScopeData(current_namespace, m_scopeCount)); } QCString scoped_name(getCurrentScope()); if (!scoped_name.isEmpty()) { scoped_name.append("::"); } scoped_name.append(object->name.mid(last_scope_separator_pos)); object->name = scoped_name; if (!m_scopeStack.isEmpty()) { m_scopeStack.last()->scope->addSubEntry(object); } m_scopeStack.append(new ScopeData(object, m_scopeCount)); ++m_scopeCount; }
/** Insere objeto de informação (Information) na Tabela de Símbolos. @param info objeto de informação (Information) que será inserido na Tabela de Símbolos. @see Information */ void SymbolTable::insertAtCurrentScope(IdentifierInformation *identiferInfo) { identiferInfo->setScopeLevel( getScopeCount() ); identifierInfoList_.push_back(identiferInfo); getCurrentScope()->insertIdentifierInfo(identiferInfo); }
/*Generates code for local variables of hidden main method*/ int getAllLocalsMain(FILE* yyout) { fillMainMethodDataSize(); Method* main = getCurrentScope(); // New base. fprintf( yyout,"\tR6 = R7;\t// New base\n", main->label ); // Allocate space for local variables. fprintf( yyout,"\tR7 = R7 - %d;\t// Allocate space for local variables\n", main->localsSize ); }
QString getDBusType(const QCString & type) { QCString scoped_type = type; if (!scoped_type.contains("::")) { scoped_type = getCurrentScope(type); } if (m_namedTypeMap.contains(scoped_type)) { return m_namedTypeMap[scoped_type]; } else { return type; } }
void addNamedType(const QCString &type) { QCString scoped_name(getCurrentScope()); if (m_namedTypeMap.contains(scoped_name)) { DOC_ERROR(QString("Named type \"%1\" is already defined.").arg(scoped_name)); return; } m_namedTypeMap.insert(scoped_name, type); }
Entry * openNamespace(const QString & name) { Entry * current_namespace = createEntry(); QCString scoped_name(getCurrentScope()); if (!scoped_name.isEmpty()) { scoped_name.append("::"); } scoped_name.append(name.utf8()); current_namespace->name = scoped_name; current_namespace->section = Entry::NAMESPACE_SEC; current_namespace->type = "namespace" ; return current_namespace; }
QString getType(const QXmlAttributes & attributes) { const int type_idx(indexOf(attributes, "type")); const int named_type_idx(indexOf(attributes, "named-type")); QCString type; if (named_type_idx >= 0) { type = attributes.value(named_type_idx).utf8(); if (type.left(2)!="::") { type = getCurrentScope(attributes.value(named_type_idx).utf8()); } else { type = type.mid(2); } if (m_namedTypeMap.contains(type)) { if (type_idx >= 0) { const QCString dbus_type(attributes.value(type_idx).utf8()); if (dbus_type != m_namedTypeMap[type]) { DOC_ERROR(QString("Type \"%1\" does not match up with " "previous definition of named type \"%2\" (which was \"%3\"."). arg(dbus_type). arg(type). arg(m_namedTypeMap[type])); } } return type; } DOC_ERROR(QString("Undefined named type \"%1\" used.").arg(type)); } if (type_idx >= 0) { type = attributes.value(type_idx).utf8(); QRegExp reg_exp(QCString("(a?[ybnqiuxdtsogv]|a[{]sv[}])")); if (reg_exp.match(type.data())) { return type; } DOC_ERROR(QString("Unnamed complex D-Bus type \"%1\" found.").arg(type)); } return QString(); }
// Generate the code for a block "begin" (set method label and new base, and // allocate local space). struct Symbol* genBlockBegin( FILE* yyout, cstr varName, cstr argumentName ) { //Get current scope struct Method* scope = getCurrentScope(); //Get a label for the hidden method int nextCodeLabel = newLabel(); //Save the scope in the ExtraInfo struct struct Symbol* currentScope = createExtraInfoSymbol(nextCodeLabel, 0); ((struct ExtraInfo*)(currentScope->info))->variable = (struct Symbol*)scope; //This is a method definition so do not execute yet fprintf( yyout,"\tGT(%d); //Jump to next code block\n", nextCodeLabel); char *blockName = createBlockName(varName, argumentName); //Generate block definition using method function genMethodBegin(yyout, (cstr)blockName, SYM_BLOCK); free(blockName); return currentScope; }
Symbol* genAssignement(FILE* yyout, SymbolInfo* leftSide, Symbol* rightSide, int insideIfLoop) { ExtraInfo* rightInfo = (ExtraInfo*)(rightSide->info); Variable* leftInfo = (Variable*)(leftSide->varSymbol->info); int i, arraySize, elementSize; if( rightInfo->assignmentType == TYPE_ARRAY || leftSide->info == TYPE_ARRAY ){ arraySize = ((Type*)(leftInfo->type->info))->arrayInfo->nElements; elementSize = ((Type*)(((Type*)(leftInfo->type->info))->arrayInfo->type->info))->size; } int isFloat_ = isFloat(leftSide->varSymbol); cstr regStr = getRegStr( isFloat_ ); int height = returnVariableHeight( leftSide->varSymbol->symType, leftSide->varSymbol->name ); //Left side is a global variable if (leftSide->varSymbol->symType == SYM_GLOBAL){ //Aquí no afecta el derramado porque la asignacion se hace directamente a memoria. //var = Array / Class if( rightInfo->assignmentType == LOAD_ADDRESS ){ //FIXME Aqui deberiamos cargar la direccion de la variable, para arrays y clases }else{ //Right side is Array.new if( rightInfo->assignmentType == TYPE_ARRAY ){ for( i = 0; i < arraySize; i++ ){ fprintf(yyout,"\t%c(0x%x + %d) = %s%d; //Initializing %s array",pointerType(leftSide->varSymbol), leftInfo->address, elementSize*i, regStr, rightInfo->nRegister, leftSide->varSymbol->name); } }else{ //Assignement $var[expression] = expression if( leftSide->info == TYPE_ARRAY ){ int reg = ((ExtraInfo*)(leftSide->exprSymbol->info))->nRegister; fprintf(yyout, "\tR%d = R%d * %d; //Calculate array %s position\n",reg, reg, elementSize, leftSide->varSymbol->name); fprintf(yyout,"\t%c(0x%x + R%d) = %s%d; //%s[expr] = expr\n",pointerType(leftSide->varSymbol), leftInfo->address, reg, regStr, rightInfo->nRegister, leftSide->varSymbol->name ); freeRegister( reg, 0 ); freeSymbol(leftSide->exprSymbol); //Assignement $var = expression }else{ fprintf(yyout,"\t%c(0x%x) = %s%d; //%s = expr\n",pointerType(leftSide->varSymbol), leftInfo->address, regStr, rightInfo->nRegister, leftSide->varSymbol->name, isFloat_); } } } //Left side not a global varialbe }else if (leftSide->varSymbol->symType == SYM_VARIABLE){ //Obtenemos la direccion con el desplazamiento y almacenamos if( rightInfo->assignmentType == LOAD_ADDRESS ){ //FIXME Aqui deberiamos cargar la direccion de la variable, para arrays y clases }else{ int accessRegister = genFrameAccess( yyout, height, -1, 1 ); //Left side is a local variable if(((Variable*)(leftSide->varSymbol->info))->symSubtype == SYM_LOCAL){ //Right side is Array.new or [e,e,..,e] if( rightInfo->assignmentType == TYPE_ARRAY ){ for( i = 0; i < arraySize; i++ ){ fprintf(yyout,"\t%c(R%d - %d) = %s%d; //Initializing %s array\n",pointerType(leftSide->varSymbol), accessRegister,leftInfo->address - elementSize*i, regStr, rightInfo->nRegister, leftSide->varSymbol->name); } }else{ //Assignement var[expression] = expression if( leftSide->info == TYPE_ARRAY ){ int reg = ((ExtraInfo*)(leftSide->exprSymbol->info))->nRegister; fprintf(yyout, "\tR%d = R%d * %d; //Calculate array %s position\n",reg, reg, elementSize, leftSide->varSymbol->name); fprintf(yyout, "\tR%d = R%d - %d; //Calculate local %s position\n",reg, reg, leftInfo->address, leftSide->varSymbol->name); fprintf(yyout,"\t%c(R%d + R%d) = %s%d; //%s[expr] = expr (2)\n",pointerType(leftSide->varSymbol), accessRegister, reg, regStr, rightInfo->nRegister, leftSide->varSymbol->name); freeRegister( reg, 0 ); freeSymbol(leftSide->exprSymbol); //Assignement var = expression }else{ fprintf(yyout,"\t%c(R%d - %d) = %s%d; //%s = expr\n",pointerType(leftSide->varSymbol), accessRegister, leftInfo->address, regStr, rightInfo->nRegister, leftSide->varSymbol->name); } } } //Left side is an argument variable else{ //Right side is Array.new or [e,e,..,e] if( rightInfo->assignmentType == TYPE_ARRAY ){ for( i = 0; i < arraySize; i++ ){ fprintf(yyout,"\t%c(R%d + %d) = %s%d; //Initializing %s array\n",pointerType(leftSide->varSymbol), accessRegister, leftInfo->address + elementSize*i, regStr, rightInfo->nRegister, leftSide->varSymbol->name); } }else{ //Assignement var[expression] = expression if( leftSide->info == TYPE_ARRAY ){ int reg = ((ExtraInfo*)(leftSide->exprSymbol->info))->nRegister; fprintf(yyout, "\tR%d = R%d * %d; //Calculate array %s position\n",reg, reg, elementSize, leftSide->varSymbol->name); fprintf(yyout, "\tR%d = R%d - %d; //Calculate local %s position\n",reg, reg, leftInfo->address, leftSide->varSymbol->name); fprintf(yyout,"\t%c(R%d - R%d) = %s%d; //%s[expr] = expr\n",pointerType(leftSide->varSymbol), accessRegister, reg, regStr, rightInfo->nRegister, leftSide->varSymbol->name); freeRegister( reg, 0 ); freeSymbol(leftSide->exprSymbol); //Assignement var = expression }else{ fprintf(yyout,"\t%c(R%d + %d) = %s%d; //%s = expr\n",pointerType(leftSide->varSymbol), accessRegister, leftInfo->address, regStr, rightInfo->nRegister, leftSide->varSymbol->name); } } } if( accessRegister != 6 ){ freeRegister( accessRegister, 0 ); } } } if(!insideIfLoop){ int reg = rightInfo->nRegister; Method* method = getCurrentScope(); if(method->returnType){ int size = method->argumentsSize; if(!isFloat(method->returnType) && !isFloat_){ fprintf(yyout,"\t%c(R6 + %d) = R%d; //Store return value\n", pointerType(method->returnType), size, reg); }else{ if(isFloat(method->returnType) && isFloat_){ fprintf(yyout,"\t%c(R6 + %d) = RR%d; //Store return value\n", pointerType(method->returnType), size, reg); } } } } freeRegister( rightInfo->nRegister, isFloat_ ); freeSymbolInfo(leftSide); return rightSide; }