本文整理汇总了C++中SymTab类的典型用法代码示例。如果您正苦于以下问题:C++ SymTab类的具体用法?C++ SymTab怎么用?C++ SymTab使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SymTab类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluate
void AssignmentStatement::evaluate(SymTab &symTab,
std::unique_ptr<FuncTab> &funcTab) {
if(_lhsExpression == nullptr) {
symTab.setValueFor(lhsVariable(),
rhsExpression()->evaluate(symTab, funcTab));
} else {
auto lhsindex = dynamic_cast<NumberDescriptor*>
(_lhsExpression->evaluate(symTab, funcTab).get());
if(lhsindex->type() != TypeDescriptor::INTEGER) {
std::cout << "AssignmentStatement::evaluate error index must be";
std::cout << " an integer\n";
exit(1);
}
int index = lhsindex->value.intValue;
auto lhs = symTab.getValueFor(lhsVariable());
auto rhs = _rhsExpression->evaluate(symTab, funcTab);
if(lhs->type() == TypeDescriptor::STRINGARRAY) {
if(rhs->type() != TypeDescriptor::STRING){
std::cout<<"array value not of compatible types"<<std::endl;
exit(1);
}
auto desc = dynamic_cast<StringDescriptor*>(rhs.get());
std::string val = desc->value;
dynamic_cast<StringArray*>(lhs.get())->setSubStr(index, val);
} else if(lhs->type() == TypeDescriptor::NUMBERARRAY) {
if(rhs->type() != TypeDescriptor::INTEGER){
std::cout<<"array value not of compatible types"<<std::endl;
exit(1);
}
auto desc = dynamic_cast<NumberDescriptor*>(rhs.get());
int val = desc->value.intValue;
dynamic_cast<NumberArray*>(lhs.get())->setSubNum(index, val);
}
}
}
示例2: addCatchTypeName
//Add catch type string into symbol tabel to speed up string comparation.
static void addCatchTypeName(DexRegion * rg)
{
Dex2IR * d2ir = rg->getDex2IR();
SymTab * symtab = rg->getRegionMgr()->getSymTab();
for (TryInfo * ti = d2ir->getTryInfo(); ti != NULL; ti = ti->next) {
for (CatchInfo * ci = ti->catch_list; ci != NULL; ci = ci->next) {
ASSERT0(ci->kindname);
symtab->add(ci->kindname);
}
}
}
示例3: generateDecls
/* generate declarations for global variables used in the program */
void generateDecls( const SymTab &curSymTab )
{
for ( SymTab::const_iterator curSym = curSymTab.begin( );
curSym != curSymTab.end( ); ++curSym ) {
if ( curSym -> second.isReg( ) == true
|| curSym -> second.Type( ) == FUNC
|| curSym -> second.isLocal( ) )
continue;
curSym -> second.declare( curSym -> first );
}
cout << "\n\n";
}
示例4: typeCheck
Type* GlobalEntry::typeCheck(){
SymTab* st = this->symTab();
for(SymTab::iterator i = st->begin(); i != st->end(); ++i){
(*i)->typeCheck();
}
//Loops over all Rules
for(unsigned int x = 0; x < rules_.size();++x){
rules_[x]->typeCheck();
}
return NULL;
}
示例5: MemoryMgr
void EventEntry::memAlloc(MemoryMgr &mm){
memory_mgr_ = MemoryMgr();
//cout << "Event memAlloc" << endl;
SymTab* st = this->symTab();
if(st!=NULL){
for(SymTab::iterator i = st->begin(); i != st->end();++i){
if((*i)->kind()==SymTabEntry::Kind::VARIABLE_KIND){
VariableEntry* ve = (VariableEntry*) (*i);
if(ve->varKind()==VariableEntry::VarKind::PARAM_VAR){
ve->offSet(memory_mgr_.getNextAddress());
}
}
}
}
}
示例6: Label
void GlobalEntry::memAlloc(MemoryMgr &mm){
memory_mgr_ = mm;
parse_label_ = new Label(Label::LabelType::PARSE_START);
end_label_ = new Label(Label::LabelType::END_PROGRAM);
//Loops over all declarations
SymTab* st = this->symTab();
for(SymTab::iterator i = st->begin(); i != st->end(); ++i){
(*i)->memAlloc(mm);
}
//Technically this happens between the two of them, but all registers should be free at this point
in_reg_ = mm.getNextRegister(true);
mm.addRegister(in_reg_);
comp_reg_ = mm.getNextRegister(true);
mm.addRegister(comp_reg_);
mm.freeRegister(comp_reg_);
//Loops over all Rules
for(unsigned int x = 0; x < rules_.size();++x){
MemoryMgr mm_r;
mm_r.addRegister(in_reg_);
rules_[x]->memAlloc(mm_r);
mm_r.freeRegister(in_reg_);
if(rules_[x]->pat()->kind() == BasePatNode::PatNodeKind::PRIMITIVE){
PrimitivePatNode* pn = (PrimitivePatNode*)((PatNode*)rules_[x]->pat())->pat1();
EventEntry* ee = pn->event();
if(ee->name().length() == 1){
rule_names_.push_back(ee->name());
rule_labels_.push_back(rules_[x]->startLabel());
rule_return_labels_.push_back(rules_[x]->returnLabel());
}
if(ee->name() == "any"){
any_labels_.push_back(rules_[x]->startLabel());
any_return_labels_.push_back(rules_[x]->returnLabel());
}
}
}
mm.freeRegister(in_reg_);
}
示例7: visitFuncImpl
void visitFuncImpl(FuncImpl * p)
{
p->m_attribute.m_scope = m_st->get_scope();
p->m_type->accept(this);
add_func_symbol(p);
m_st->open_scope();
p->visit_children(this);
m_st->close_scope();
check_return_type(p);
}
示例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: visitClassImpl
void visitClassImpl(ClassImpl *p) {
int stop;
m_symboltable->open_scope();
Symbol * symPtr = new Symbol;
// = new ClassNode;
Symbol * symp;// = new Symbol;
ClassIDImpl * ClassIdP = dynamic_cast<ClassIDImpl*>(p->m_classid_1);
ClassIDImpl * ClassIdP2 = dynamic_cast<ClassIDImpl*>(p->m_classid_2);
char * key1 = strdup(ClassIdP->m_classname->spelling());
symPtr->classType.classID = ClassIdP->m_classname->spelling();
char * progFinder = strdup("Program");
ClassName * nm = new ClassName(key1);
if(progger == true){
t_error(no_program, p->m_attribute);
}
if(std::string(key1) == std::string(progFinder)){
progger = true;
}
//char * key2 = strdup(ClassIdP2->m_classname->spelling());
if(m_classtable->exist(key1)){
t_error(dup_ident_name, p->m_attribute);
}
else{
if(ClassIdP2->m_classname != NULL){
char * key2 = strdup(ClassIdP2->m_classname->spelling());
ClassName * nm2 = new ClassName(key2);
// cout<<"inserted class: " <<key1 <<" from :"<<key2 <<endl;
m_classtable->insert(nm, nm2, p, m_symboltable->get_scope());
ClassNode * clasp = m_classtable->getParentOf(key2);
// cout<<"Class: " <<key1 <<", Super class: "<<clasp->name->spelling()<<endl;
}
else{
// cout<< "instered this in class table: "<< key1 <<endl;
m_classtable->insert(nm, NULL, p, m_symboltable->get_scope());
}
}
m_symboltable->insert((char *)"xxx", symPtr);
p->visit_children(this);
m_symboltable->close_scope();
//WRITE ME
}
示例10: visitMethodImpl
void visitMethodImpl(MethodImpl *p) {
m_symboltable->open_scope();
if (p->m_type != NULL) {
p->m_type->accept( this );
} else {
this->visitNullPointer();
}
// cout<<"my type: "<<p->m_type->m_attribute.m_type.baseType<<endl;
Symbol *symp = new Symbol;
Symbol *Msymp = new Symbol;
Symbol *test;
MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid);
p->m_attribute.m_type.baseType = p->m_type->m_attribute.m_type.baseType;
//this is dealing with duplicate method names
char * key = strdup(MethIdP->m_symname->spelling());//~!~!~!~!~!~!~!~ place here
test = InScope(key);
if(test != NULL){//change this make Msymp = my function
t_error(dup_ident_name, p->m_attribute);
}
else{
CompoundType arg;
p->visit_children(this);
//Adding parameters to sym table and each argument to method vector
typename std::list<Parameter_ptr>::iterator it = p->m_parameter_list->begin();
for( ; it != p->m_parameter_list->end(); ++it) {
ParameterImpl * Pimp = dynamic_cast<ParameterImpl *> (*it);
VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(Pimp->m_variableid);
//char * key = strdup(VarIdP->m_symname->spelling());
arg.baseType = Pimp->m_type->m_attribute.m_type.baseType;
Msymp->methodType.argsType.push_back(arg);
}
Msymp->methodType.returnType.baseType = p->m_type->m_attribute.m_type.baseType;
Msymp->baseType = p->m_type->m_attribute.m_type.baseType;
m_symboltable->insert_in_parent_scope(key, Msymp);
}
if(p->m_type->m_attribute.m_type.baseType != p->m_methodbody->m_attribute.m_type.baseType){
t_error(ret_type_mismatch, p->m_attribute);
}
m_symboltable->close_scope();
//WRITE ME
}
示例11: 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);
}
示例12: visitParameterImpl
void visitParameterImpl(ParameterImpl *p) {
p->visit_children(this);
Symbol *symp = new Symbol;
Symbol * test;
VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid);
char * key = strdup(VarIdP->m_symname->spelling());
test = InScope(key);
if(test!=NULL){
t_error(dup_ident_name, p->m_attribute);
}
else{
symp->baseType = p->m_type->m_attribute.m_type.baseType;
// cout<< "param; key: "<< key <<" type : "<< symp->baseType<<endl;
if(symp->baseType == 8){
symp->classType.classID = p->m_type->m_attribute.m_type.classType.classID;
// cout<< "this is what i'm SEETTTING key: " << symp->classType.classID<<endl;
}
// cout<<"insertingthis var from param: "<<key <<endl;
m_symboltable->insert(key, symp);
}
//WRITE ME
}
示例13: 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
}
示例14: 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));
}
示例15: visitBoolLit
void visitBoolLit(BoolLit * p)
{
p -> m_attribute.m_scope = m_st->get_scope();
p -> visit_children(this);
p -> m_attribute.m_basetype = bt_boolean;
}