本文整理汇总了C++中SymTab::get_current_scope方法的典型用法代码示例。如果您正苦于以下问题:C++ SymTab::get_current_scope方法的具体用法?C++ SymTab::get_current_scope怎么用?C++ SymTab::get_current_scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymTab
的用法示例。
在下文中一共展示了SymTab::get_current_scope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visitSelfCall
void visitSelfCall(SelfCall *p) {
fprintf( m_outputfile, "#### SELF CALL\n");
int args;
Symbol * symbP;
SymScope * sync;
MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid);
char * funcName = strdup(MethIdP->m_symname->spelling());
sync = m_symboltable->get_current_scope();
symbP = sync->lookup((const char *)"xxx");
p->visit_children(this);
args = p->m_expression_list->size();
args = args * wordsize;
// cout<<"the number of params: "<<args<<endl;
char * className = strdup(symbP->classType.classID);
strcat(className,"_");
strcat(className,funcName);
fprintf( m_outputfile, "call %s\n",className);
fprintf( m_outputfile, "addl $%d , %%esp\n",args);
// WRITEME
}
示例2: visitMethodImpl
void visitMethodImpl(MethodImpl *p) {
fprintf( m_outputfile, "#### METHOD IMPLEMENTATION\n");
int localSpace, args, mem;
int j=0;
int methMem = 0;
CompoundType info;
currMethodOffset = new OffsetTable();
// cout<<"before my childen"<<endl;
//this is to make the label name
Symbol * symbP;
SymScope * sync;
MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid);
char * funcName = strdup(MethIdP->m_symname->spelling());
sync = m_symboltable->get_current_scope();
symbP = sync->lookup((const char *)"xxx");
char * classMethName = strdup(symbP->classType.classID);
strcat(classMethName,"_");
strcat(classMethName,funcName);
fprintf( m_outputfile, "_%s:\n",classMethName);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fprintf( m_outputfile, " pushl %%ebp\n");
fprintf( m_outputfile, " movl %%esp , %%ebp\n");
MethodBodyImpl * MethBodP = dynamic_cast<MethodBodyImpl*>(p->m_methodbody);
localSpace = (p->m_parameter_list->size() + MethBodP->m_declaration_list->size());
localSpace = localSpace * wordsize;
// currMethodOffset->insert(classMethName, localSpace, 4,symbP->classType);
currMethodOffset->setTotalSize(localSpace);
currMethodOffset->setParamSize(p->m_parameter_list->size() * wordsize);
//### inserting paramaters into the offset table ###########
for (std::list<Parameter_ptr>::iterator it = p->m_parameter_list->begin() ; it != p->m_parameter_list->end(); ++it){
ParameterImpl * param = dynamic_cast<ParameterImpl*>(*it);
VariableIDImpl * VarId = dynamic_cast<VariableIDImpl*>(param->m_variableid);
info.baseType = param->m_type->m_attribute.m_type.baseType;
if(info.baseType == 8){
info.classID = param->m_type->m_attribute.m_type.classType.classID;
}
else{
info.classID = "NO CLASS";
}
methMem -= 4;
// cout<<"Offset-> symname: "<<VarId->m_symname->spelling()<<" offset: "<<methMem<<" class type: " <<info.baseType<<endl;
currMethodOffset->insert(VarId->m_symname->spelling(), methMem, 4,info);
}
//################################
//<><>Diving into Declaration <><><><>><><><><><><><><><><><>><><><><><><
typename std::list<Declaration_ptr>::iterator it = MethBodP->m_declaration_list->begin();
for( ; it != MethBodP->m_declaration_list->end(); ++it) {
DeclarationImpl * DeclaP = dynamic_cast<DeclarationImpl *> (*it);
typename std::list<VariableID_ptr>::iterator it = DeclaP->m_variableid_list->begin();
for( ; it != DeclaP->m_variableid_list->end(); ++it) {
methMem -= 4; // need to move to the next offset
VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(*it);
char * var = strdup(VarIdP->m_symname->spelling());
// cout<<"Offset-> symname: "<<var<<" Offset: "<<methMem<<" Class type: " <<endl;
info.baseType = DeclaP->m_type->m_attribute.m_type.baseType;
if(info.baseType == 8){
info.classID = DeclaP->m_type->m_attribute.m_type.classType.classID;
}
else{
info.classID = "NO CLASS";
}
currMethodOffset->insert(var, methMem, 4,info);
}
}
//<><><><><><><><><><><><><><><><><>><><><><><><
//~~~~ allocating space on the stack and moves parameters into local ~~~~~~
// cout<<"param size: "<<currMethodOffset->getParamSize()<<endl;
// cout<<" LocalSpace: "<< -(methMem)<<endl;
fprintf( m_outputfile, " subl $%d, %%esp\n",-(methMem));
mem = -4;
for(int i = currMethodOffset->getParamSize() + 4; i>= 8; i = i-4){
fprintf( m_outputfile, " movl %d(%%ebp) , %%eax\n",i);
fprintf( m_outputfile, " movl %%eax , %d(%%ebp)\n",mem);
mem -= 4;
// symbP->methodType.argsType[j].baseType;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p->visit_children(this);
// cout<<"after the children"<<endl;
fprintf( m_outputfile, " leave\n");
fprintf( m_outputfile, " ret\n");
// WRITEME
}