本文整理汇总了C++中SymTab::lookup方法的典型用法代码示例。如果您正苦于以下问题:C++ SymTab::lookup方法的具体用法?C++ SymTab::lookup怎么用?C++ SymTab::lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymTab
的用法示例。
在下文中一共展示了SymTab::lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visitCall
void visitCall(Call * p)
{
int n = 0;
list<Expr_ptr>::reverse_iterator iter;
for(iter = p->m_expr_list->rbegin();iter != p->m_expr_list->rend();iter++)
{
n = n + wordsize;
(*iter)->accept( this );
}
Symbol *x = m_st->lookup(p->m_attribute.m_scope, p->m_symname_1->spelling());
fprintf(m_outputfile, "call %s\n", strdup(p->m_symname_2->spelling()));
fprintf(m_outputfile, "addl $%d, %%esp\n",n);
fprintf( m_outputfile, "movl %%eax, -%d(%%ebp)\n", (m_st->lookup(p->m_attribute.m_scope, p->m_symname_1->spelling()))->get_offset() + 4);
}
示例2: visitArrayCall
void visitArrayCall(ArrayCall *p)
{
int n = 0;
list<Expr_ptr>::reverse_iterator iter;
for(iter = p->m_expr_list_2->rbegin();iter != p->m_expr_list_2->rend();iter++)
{
n = n + wordsize;
(*iter)->accept( this );
}
Symbol *x = m_st->lookup(p->m_attribute.m_scope, p->m_symname_1->spelling());
fprintf(m_outputfile, "call %s\n", strdup(p->m_symname_2->spelling()));
fprintf(m_outputfile, "addl $%d, %%esp\n",n);
x = m_st->lookup(p->m_attribute.m_scope, p->m_symname_2->spelling());
int xx=4+x->get_offset();
fprintf(m_outputfile, "movl %%eax, \t%d(%%ebp)\n", (-xx+(-1)*4*((IntLit*)p->m_expr_1)->m_primitive->m_data));
}
示例3: visitAssignment
void visitAssignment(Assignment * p)
{
p->visit_children(this);
fprintf(m_outputfile, "\tpopl\t%%eax\n");
Symbol *s = m_st->lookup(p->m_attribute.m_scope, p->m_symname->spelling());
fprintf(m_outputfile, "\tmovl\t%%eax, %d(%%ebp)\n", -(4+s->get_offset()) );
}
示例4: visitAssignment
void visitAssignment(Assignment * p)
{
p->m_symname->accept( this );
p->m_expr->accept( this );
fprintf( m_outputfile, "popl %%eax\n");
fprintf( m_outputfile, "movl %%eax, -%d(%%ebp)\n", (m_st->lookup( p -> m_attribute.m_scope, p->m_symname->spelling()))->get_offset() + 4);
}
示例5: visitIdent
// variable and constant access
void visitIdent(Ident * p)
{
fprintf(m_outputfile, "\t ## Ident ##\n");
p->visit_children(this);
Symbol *s = m_st->lookup(p->m_attribute.m_scope, p->m_symname->spelling());
fprintf(m_outputfile, "\tpushl\t%d(%%ebp)\n", -(4+s->get_offset()));
fprintf(m_outputfile, "\t ## END Ident ##\n");
}
示例6: visitArrayAssignment
void visitArrayAssignment(ArrayAssignment * p)
{
p->visit_children(this);
fprintf(m_outputfile, "popl %%eax\n");
Symbol *x = m_st->lookup(p->m_attribute.m_scope, p->m_symname->spelling());
int xx=4+x->get_offset();
fprintf(m_outputfile, "movl %%eax, \t%d(%%ebp)\n", (-xx+(-1)*4*((IntLit*)p->m_expr_1)->m_primitive->m_data));
}
示例7: check_assignment
// check that the assigned-to variable exists and that the right-hand-side expression is valid
// check that the return type of the expression matches the type of the variable
void check_assignment( Assignment * p )
{
Symbol *s;
s = m_st->lookup(p->m_symname->spelling());
if(!s)
this->t_error(var_undef, p->m_attribute);
if(s->m_basetype - p->m_expr->m_attribute.m_basetype)
this->t_error(incompat_assign, p->m_attribute);
}
示例8: visitIdent
void visitIdent(Ident * p)
{
p -> m_attribute.m_scope = m_st->get_scope();
p -> visit_children(this);
Symbol *newSym;
newSym = m_st->lookup( p->m_symname->spelling());
if(!newSym)
this->t_error(var_undef, p->m_attribute);
p->m_attribute.m_basetype = newSym->m_basetype;
}
示例9: visitArrayAccess
void visitArrayAccess(ArrayAccess * p)
{
p->visit_children(this);
fprintf( m_outputfile, "popl %%eax\n");
fprintf( m_outputfile, "imul $4, %%eax\n");
fprintf( m_outputfile, "movl %%ebp, %%ebx\n");
fprintf( m_outputfile, "subl $%d, %%ebp\n", (m_st->lookup(p->m_attribute.m_scope, p->m_symname->spelling()))->get_size() + (m_st->lookup(p->m_attribute.m_scope, p->m_symname->spelling()))->get_size());//here
fprintf( m_outputfile, "addl %%eax, %%ebp\n");
fprintf( m_outputfile, "pushl 0(%%ebp)\n");
fprintf( m_outputfile, "movl %%ebx, %%ebp\n");
}
示例10: check_array_access
// check that intarray index is integer and that variable is actually intarray
void check_array_access(ArrayAccess *p)
{
Symbol *s;
s = m_st->lookup(p->m_symname->spelling());
if(!s)
this->t_error(var_undef, p->m_attribute);
if(p->m_attribute.m_basetype != 4)
this->t_error(incompat_assign, p->m_attribute);
if(p->m_expr->m_attribute.m_basetype != 1)
this->t_error(incompat_assign, p->m_attribute);
}
示例11: pName
Symbol * InScope(char* key){// before calling this function make sure there is a parent scope
Symbol * symbP;
SymScope *sync;
ClassNode * parent;
ClassNode * clasp;
char* parentName;
bool found;
string pName;
int i =0;
// cout<<" the key is "<<key<<endl;
symbP = m_symboltable->lookup(key);
if(!m_symboltable->exist(key)){
symbP = m_symboltable->lookup((const char *)"xxx");
char * Cname = strdup(symbP->classType.classID);
parent = m_classtable->lookup(Cname);
// cout<<"parent: "<<parent->name->spelling()<<endl;
sync = parent->scope;
symbP = sync->lookup(key);
found = sync->exist(key);
while(found == false){
ClassName * classGreat = new ClassName(Cname);
ClassNode* pNode = m_classtable->getParentOf(classGreat);
Cname = strdup(pNode->name->spelling());
std::string pName(pNode->name->spelling());
// cout<<"the parent name: "<<Cname<<endl;
if( pName == "TopClass"){
return NULL;
}
sync = pNode->scope;
found = sync->exist(key);
symbP = sync->lookup(key);
i++;
}
}
return symbP;
}
示例12: visitArrayAccess
void visitArrayAccess(ArrayAccess * p)
{
fprintf(m_outputfile, "\t ## ArrayAccess ##\n");
p->visit_children(this);
fprintf(m_outputfile, "\tpopl\t%%ebx\n");
Symbol *s = m_st->lookup(p->m_attribute.m_scope, p->m_symname->spelling());
fprintf(m_outputfile, "\timull\t$4, %%ebx\n");
fprintf(m_outputfile, "\taddl\t$%d, %%ebx\n", s->get_offset());
fprintf(m_outputfile, "\taddl\t$%d, %%ebx\n", 4);
fprintf(m_outputfile, "\tneg\t%%ebx\n");
fprintf(m_outputfile, "\taddl\t%%ebp, %%ebx\n");
fprintf(m_outputfile, "\tpushl\t(%%ebx)\n");
fprintf(m_outputfile, "\t ## END ArrayAccess ##\n");
}
示例13: check_call
// create a symbol for the function and check there is none already existing
// make sure all the expressions used as arguments are valid
// check if the argument list matches the declared one (length and types)
// make sure the variable assigned to matches the return type of the function
void check_call(Call *p)
{
Symbol *s;
s = m_st->lookup(p->m_symname->spelling());
if(!s)
this->t_error(var_undef, p->m_attribute);
if(s->m_basetype - p->m_expr->m_attribute.m_basetype)
this->t_error(incompat_assign, p->m_attribute);
Symbol *s2;
s2 = m_st->lookup( p->m_symname_1->spelling());
if(!s2)
this->t_error(var_undef, p->m_attribute);
if(s->m_return_type != s2->m_basetype )
this->t_error(incompat_assign, p->m_attribute);
if(s->m_arg_type.size() != p->m_expr_list->size())
this->t_error(call_narg_mismatch, p->m_attribute);
list<Expr_ptr>::iterator iter;
iter = p->m_expr_list->begin();
for(int i =0; i < s->m_arg_type.size(); i++){
if(s->m_arg_type[i] != (*iter)->m_attribute.m_basetype)
this->t_error(call_args_mismatch, (*iter)->m_attribute);
iter++;
}
}
示例14: visitCall
void visitCall(Call * p)
{
int num_arguments = 0;
list<Expr_ptr>::reverse_iterator m_expr_list_iter;
for(m_expr_list_iter = p->m_expr_list->rbegin();
m_expr_list_iter != p->m_expr_list->rend();
++m_expr_list_iter)
{
num_arguments++;
(*m_expr_list_iter)->accept( this );
}
fprintf(m_outputfile, "\tcall\t%s\n", p->m_symname_2->spelling());
Symbol *s = m_st->lookup(p->m_attribute.m_scope, p->m_symname_1->spelling());
fprintf(m_outputfile, "\tmovl\t%%eax, %d(%%ebx)\n", -(4+s->get_offset()) );
}
示例15: visitAssignment
void visitAssignment(Assignment *p) {
p->visit_children(this);
string str1, str2, temp1, temp2;
Symbol * symp;
// Symbol * symp;
SymScope *sync;
ClassNode * parent;
char* parentName;
bool oneLevel = false;
VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid);
char * key = strdup(VarIdP->m_symname->spelling());
symp = m_symboltable->lookup((const char *)"xxx");
symp = InScope(key);
if(symp != NULL){ // or i could change this to if symp ==NULL
if(p->m_expression->m_attribute.m_type.baseType == 8){
if(p->m_expression->m_attribute.m_type.baseType == 8 && symp->baseType == 8){
// std::string temp1(p->m_expression->m_attribute.m_type.classType.classID);
//std::string temp2(symp->classType.classID);
if(temp1!= temp2){
t_error(incompat_assign, p->m_attribute);
}
if(p->m_expression->m_attribute.m_type.methodType.returnType.baseType != symp->baseType){
t_error(incompat_assign, p->m_attribute);
}
}
}
if(p->m_expression->m_attribute.m_type.baseType != 8 && p->m_expression->m_attribute.m_type.baseType != symp->baseType){
t_error(incompat_assign, p->m_attribute);
}
}
else{
t_error(sym_name_undef, p->m_attribute);
}
//WRITE ME
}