static void HandleX86ForceAlignArgPointerAttr(Decl *D, const AttributeList& Attr, Sema &S) { // Check the attribute arguments. if (Attr.getNumArgs() != 0) { S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; return; } // If we try to apply it to a function pointer, don't warn, but don't // do anything, either. It doesn't matter anyway, because there's nothing // special about calling a force_align_arg_pointer function. ValueDecl *VD = dyn_cast<ValueDecl>(D); if (VD && VD->getType()->isFunctionPointerType()) return; // Also don't warn on function pointer typedefs. TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D); if (TD && (TD->getUnderlyingType()->isFunctionPointerType() || TD->getUnderlyingType()->isFunctionType())) return; // Attribute can only be applied to function types. if (!isa<FunctionDecl>(D)) { S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) << Attr.getName() << /* function */0; return; } D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(Attr.getRange(), S.Context)); }
CXString clang_getTypedefName(CXType CT) { QualType T = GetQualType(CT); const TypedefType *TT = T->getAs<TypedefType>(); if (TT) { TypedefNameDecl *TD = TT->getDecl(); if (TD) return cxstring::createDup(TD->getNameAsString().c_str()); } return cxstring::createEmpty(); }
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"); } }