void TABLE::insert(SYM *sp) { int nn; TypeArray *ta = sp->GetProtoTypes(); TABLE *tab = this; SYM *p; int s1,s2,s3; std::string nm; // std::string sig; if (sp == nullptr || this == nullptr ) { dfs.printf("Null pointer at insert\n"); throw new C64PException(ERR_NULLPOINTER,1); } if (this==&tagtable) { dfs.printf("Insert into tagtable:%s|\n",(char *)sp->name->c_str()); } else dfs.printf("Insert %s into %p", (char *)sp->name->c_str(), (char *)this); dfs.printf("(%s)\n",owner ? (char *)SYM::GetPtr(owner)->name->c_str(): (char *)""); // sig = sp->BuildSignature(); if (tab==&gsyms[0]) { dfs.printf("Insert into global table\n"); s1 = hashadd((char *)sp->name->c_str()); s2 = hashadd((char *)sp->name2->c_str()); s3 = hashadd((char *)sp->name3->c_str()); // tab = &gsyms[(s1&s2)|(s1&s3)|(s2&s3)]; tab = &gsyms[s1]; } nm = *sp->name; // The symbol may not have a type if it's just a label. Find doens't // look at the return type parameter anyway, so we just set it to bt_long // if tp isn't set. nn = tab->Find(nm,sp->tp ? sp->tp->typeno : bt_long,ta,true); if(nn == 0) { if( tab->head == 0) { tab->SetHead(sp->GetIndex()); tab->SetTail(sp->GetIndex()); } else { sp->GetPtr(tab->tail)->next = sp->GetIndex(); tab->SetTail(sp->GetIndex()); } sp->SetNext(0); dfs.printf("At insert:\n"); sp->GetProtoTypes()->Print(); } else error(ERR_DUPSYM); if (ta) delete ta; // p = tab->GetHead(); // while(p) { // printf("Xele:%p|%s|\r\n", p, p->name.c_str()); // p = p->GetNext(); // } }
int StructDeclaration::Parse(int ztype) { SYM *sp; TYP *tp; int ret; int psd; ENODE nd; ENODE *pnd = &nd; sp = nullptr; psd = isStructDecl; isStructDecl++; ret = 0; bit_offset = 0; bit_next = 0; bit_width = -1; if(lastst == id) { if((sp = tagtable.Find(lastid,false)) == NULL) { sp = allocSYM(); sp->SetName(*(new std::string(lastid))); sp->tp = allocTYP(); sp->tp->type = (e_bt)ztype; sp->tp->typeno = typeno++; sp->tp->lst.Clear(); sp->storage_class = sc_type; sp->tp->sname = new std::string(*sp->name); sp->tp->alignment = 0; NextToken(); if (lastst == kw_align) { NextToken(); sp->tp->alignment = GetIntegerExpression(&pnd); } // Could be a forward structure declaration like: // struct buf; if (lastst==semicolon) { ret = 1; tagtable.insert(sp); NextToken(); } // Defining a pointer to an unknown struct ? else if (lastst == star) { tagtable.insert(sp); } else if(lastst != begin) error(ERR_INCOMPLETE); else { tagtable.insert(sp); NextToken(); ParseMembers(sp, sp->tp,ztype); } } // Else it is a known structure else { NextToken(); if (lastst==kw_align) { NextToken(); sp->tp->alignment = GetIntegerExpression(&pnd); } if (lastst==begin) { NextToken(); ParseMembers(sp,sp->tp,ztype); } } head = sp->tp; } // Else there was no tag identifier else { tp = allocTYP(); tp->type = (e_bt)ztype; tp->typeno = typeno++; tp->sname = new std::string(""); if (lastst==kw_align) { NextToken(); tp->alignment = GetIntegerExpression(&pnd); } if( lastst != begin) error(ERR_INCOMPLETE); else { NextToken(); ParseMembers(sp,tp,ztype); } head = tp; } isStructDecl = psd; return ret; }
// Class declarations have the form: // // class identifier [: base class] // { // class members // } // // We could also have a forward reference: // // class identifier; // // Or a pointer to a class: // // class *identifier; // int ClassDeclaration::Parse(int ztype) { SYM *sp, *bcsp; int ret; int psd; ENODE nd; ENODE *pnd = &nd; char *idsave; int alignment; SYM *cls; cls = currentClass; dfs.puts("<ParseClassDeclaration>\n"); alignment = 0; isTypedef = TRUE; NextToken(); if (lastst != id) { error(ERR_SYNTAX); goto lxit; } // ws = allocSYM(); idsave = my_strdup(lastid); // ws->name = idsave; // ws->storage_class = sc_typedef; // Passes lastid onto struct parsing psd = isStructDecl; isStructDecl++; ret = 0; bit_offset = 0; bit_next = 0; bit_width = -1; dfs.printf("---------------------------------"); dfs.printf("Class decl:%s\n", lastid); dfs.printf("---------------------------------"); if((sp = tagtable.Find(std::string(lastid),false)) == NULL) { sp = allocSYM(); sp->SetName(*(new std::string(lastid))); sp->tp = nullptr; NextToken(); dfs.printf("A"); if (lastst == kw_align) { NextToken(); alignment = GetIntegerExpression(&pnd); } else alignment = AL_STRUCT; // Could be a forward structure declaration like: // struct buf; if (lastst==semicolon) { dfs.printf("B"); ret = 1; printf("classdecl insert1\r\n"); tagtable.insert(sp); NextToken(); } // Defining a pointer to an unknown struct ? else if (lastst == star) { dfs.printf("C"); printf("classdecl insert2\r\n"); tagtable.insert(sp); } else if (lastst==colon) { dfs.printf("D"); NextToken(); // Absorb and ignore public/private keywords if (lastst == kw_public || lastst==kw_private) NextToken(); if (lastst != id) { error(ERR_SYNTAX); goto lxit; } bcsp = tagtable.Find(std::string(lastid),false); if (bcsp==nullptr) { error(ERR_UNDEFINED); goto lxit; } dfs.printf("E"); // Copy the type chain of base class //sp->tp = TYP::Copy(bcsp->tp); // Start off at the size of the base. sp->tp = allocTYP(); sp->tp->lst.SetBase(bcsp->GetIndex()); dfs.printf("Set base class: %d\n", sp->tp->lst.base); sp->tp->size = bcsp->tp->size; sp->tp->type = (e_bt)ztype; sp->tp->typeno = typeno++; sp->tp->sname = new std::string(*sp->name); sp->tp->alignment = alignment; sp->storage_class = sc_type; NextToken(); if (lastst != begin) { error(ERR_INCOMPLETE); goto lxit; } /* sp->tp = allocTYP(); sp->tp->typeno = typeno++; sp->tp->sname = new std::string(*sp->name); sp->tp->alignment = alignment; sp->tp->type = (e_bt)ztype; sp->tp->lst.SetBase(bcsp->GetIndex()); sp->storage_class = sc_type; */ tagtable.insert(sp); NextToken(); currentClass = sp; dfs.printf("f"); ParseMembers(sp,ztype); dfs.printf("G"); } else if(lastst != begin) error(ERR_INCOMPLETE); else { if (sp->tp == nullptr) { sp->tp = allocTYP(); } sp->tp->size = 0; sp->tp->typeno = typeno++; sp->tp->sname = new std::string(*sp->name); sp->tp->alignment = alignment; sp->tp->type = (e_bt)ztype; sp->tp->lst.SetBase(0); sp->storage_class = sc_type; tagtable.insert(sp); NextToken(); currentClass = sp; ParseMembers(sp,ztype); } } // Else the class was found in the tag table. else { NextToken(); if (lastst==kw_align) { NextToken(); sp->tp->alignment = GetIntegerExpression(&pnd); } if (lastst==begin) { NextToken(); currentClass = sp; ParseMembers(sp,ztype); } } head = sp->tp; isStructDecl = psd; lxit: isTypedef = TRUE; if (classname) delete classname; classname = new std::string(idsave); currentClass = cls; dfs.puts("</ParseClassDeclaration>\n"); return ret; }