bool GetRecordTypeFromDecl(RecordDecl * rd, Obj * tt) { if(rd->isStruct() || rd->isUnion()) { std::string name = rd->getName(); Obj * thenamespace = &tagged; if(name == "") { TypedefNameDecl * decl = rd->getTypedefNameForAnonDecl(); if(decl) { thenamespace = &general; name = decl->getName(); } } //if name == "" then we have an anonymous struct if(!thenamespace->obj(name.c_str(),tt)) { PushTypeField("getorcreatecstruct"); lua_pushstring(L, name.c_str()); lua_pushboolean(L, thenamespace == &tagged); lua_call(L,2,1); tt->initFromStack(L,ref_table); if(!tt->boolean("llvm_definingfunction")) { std::string definingfunction; size_t argpos; RegisterRecordType(Context->getRecordType(rd), &definingfunction, &argpos); lua_pushstring(L,definingfunction.c_str()); tt->setfield("llvm_definingfunction"); lua_pushinteger(L,argpos); tt->setfield("llvm_argumentposition"); } if(name != "") { //do not remember a name for an anonymous struct tt->push(); thenamespace->setfield(name.c_str()); //register the type } } if(tt->boolean("undefined") && rd->getDefinition() != NULL) { tt->clearfield("undefined"); RecordDecl * defn = rd->getDefinition(); Obj entries; tt->newlist(&entries); if(GetFields(defn, &entries)) { if(!defn->isUnion()) { //structtype.entries = {entry1, entry2, ... } entries.push(); tt->setfield("entries"); } else { //add as a union: //structtype.entries = { {entry1,entry2,...} } Obj allentries; tt->obj("entries",&allentries); entries.push(); allentries.addentry(); } tt->pushfield("complete"); tt->push(); lua_call(L,1,0); } } return true; } else { return ImportError("non-struct record types are not supported"); } }
bool GetRecordTypeFromDecl(RecordDecl * rd, Obj * tt, std::string * fullname) { if(rd->isStruct() || rd->isUnion()) { std::string name = rd->getName(); //TODO: why do some types not have names? Obj * thenamespace = &tagged; if(name == "") { TypedefNameDecl * decl = rd->getTypedefNameForAnonDecl(); if(decl) { thenamespace = &general; name = decl->getName(); } else { name = "anon"; } } assert(name != ""); if(!thenamespace->obj(name.c_str(),tt)) { //create new blank struct, fill in with members std::stringstream ss; ss << (rd->isStruct() ? "struct." : "union.") << name; PushTypeFunction("getorcreatecstruct"); lua_pushstring(L, name.c_str()); lua_pushstring(L,ss.str().c_str()); lua_call(L,2,1); tt->initFromStack(L,ref_table); tt->push(); thenamespace->setfield(name.c_str()); //register the type (this prevents an infinite loop for recursive types) } if(tt->boolean("undefined") && rd->getDefinition() != NULL) { tt->clearfield("undefined"); RecordDecl * defn = rd->getDefinition(); Obj entries; tt->newlist(&entries); if(GetFields(defn, &entries)) { if(!defn->isUnion()) { //structtype.entries = {entry1, entry2, ... } entries.push(); tt->setfield("entries"); } else { //add as a union: //structtype.entries = { {entry1,entry2,...} } Obj allentries; tt->obj("entries",&allentries); entries.push(); allentries.addentry(); } tt->pushfield("complete"); tt->push(); lua_call(L,1,0); } } if(fullname) { std::stringstream ss; if(thenamespace == &tagged) ss << (rd->isStruct() ? "struct " : "union "); ss << name; *fullname = ss.str(); } return true; } else { return ImportError("non-struct record types are not supported"); } }