Author: kremenek Date: Thu May 6 20:04:32 2010 New Revision: 103225 URL: http://llvm.org/viewvc/llvm-project?rev=103225&view=rev Log: Add initial USR support for mangling in the types of C++ functions and methods.
Modified: cfe/trunk/test/Index/usrs.cpp cfe/trunk/tools/libclang/CIndexUSRs.cpp Modified: cfe/trunk/test/Index/usrs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.cpp?rev=103225&r1=103224&r2=103225&view=diff ============================================================================== --- cfe/trunk/test/Index/usrs.cpp (original) +++ cfe/trunk/test/Index/usrs.cpp Thu May 6 20:04:32 2010 @@ -47,21 +47,25 @@ }; }} +extern "C" { + void rez(int a, int b); +} + // RUN: c-index-test -test-load-source-usrs all %s | FileCheck %s // CHECK: usrs.cpp c:@n...@foo Extent=[1:11 - 4:2] // CHECK: usrs.cpp c:@n...@foo@x Extent=[2:3 - 2:8] -// CHECK: usrs.cpp c:@n...@foo@f...@bar Extent=[3:8 - 3:18] -// CHECK: usrs.cpp c:usrs....@3:1...@n@f...@f@b...@z Extent=[3:12 - 3:17] +// CHECK: usrs.cpp c:@n...@foo@f...@bar#i Extent=[3:8 - 3:18] +// CHECK: usrs.cpp c:usrs....@3:1...@n@f...@f@ba...@z Extent=[3:12 - 3:17] // CHECK: usrs.cpp c:@n...@bar Extent=[5:11 - 8:2] // CHECK: usrs.cpp c:usrs....@6:1...@n@b...@t@QType Extent=[6:15 - 6:20] -// CHECK: usrs.cpp c:@n...@bar@f...@bar Extent=[7:8 - 7:20] -// CHECK: usrs.cpp c:usrs....@7:1...@n@b...@f@b...@z Extent=[7:12 - 7:19] +// CHECK: usrs.cpp c:@n...@bar@f...@bar#i Extent=[7:8 - 7:20] +// CHECK: usrs.cpp c:usrs....@7:1...@n@b...@f@ba...@z Extent=[7:12 - 7:19] // CHECK: usrs.cpp c:@c...@clsa Extent=[10:1 - 14:2] // CHECK: usrs.cpp c:@c...@clsa@f...@a Extent=[12:7 - 12:8] // CHECK: usrs.cpp c:@c...@clsa@f...@b Extent=[12:10 - 12:11] -// CHECK: usrs.cpp c:@c...@clsa@f...@clsa Extent=[13:3 - 13:37] -// CHECK: usrs.cpp c:usrs....@13:8...@c@c...@f@c...@a Extent=[13:8 - 13:13] -// CHECK: usrs.cpp c:usrs....@13:1...@c@c...@f@c...@b Extent=[13:15 - 13:20] +// CHECK: usrs.cpp c:@c...@clsa@f...@clsa#i#i Extent=[13:3 - 13:37] +// CHECK: usrs.cpp c:usrs....@13:8...@c@c...@f@clsa#...@a Extent=[13:8 - 13:13] +// CHECK: usrs.cpp c:usrs....@13:1...@c@c...@f@clsa#...@b Extent=[13:15 - 13:20] // CHECK: usrs.cpp c:@n...@foo Extent=[16:11 - 22:2] // CHECK: usrs.cpp c:@n...@foo@c...@clsb Extent=[17:3 - 21:4] // CHECK: usrs.cpp c:@n...@foo@c...@clsb@f...@clsb Extent=[19:5 - 19:27] @@ -73,19 +77,20 @@ // CHECK: usrs.cpp c:@n...@foo Extent=[35:11 - 40:2] // CHECK: usrs.cpp c:@n...@foo@n...@taz Extent=[35:27 - 39:2] // CHECK: usrs.cpp c:@n...@foo@n...@taz@x Extent=[36:3 - 36:8] -// CHECK: usrs.cpp c:usrs....@37:2...@n@f...@n@t...@f@add Extent=[37:21 - 37:56] -// CHECK: usrs.cpp c:usrs....@37:2...@n@f...@n@t...@f@a...@a Extent=[37:25 - 37:30] -// CHECK: usrs.cpp c:usrs....@37:3...@n@f...@n@t...@f@a...@b Extent=[37:32 - 37:37] -// CHECK: usrs.cpp c:@n...@foo@n...@taz@f...@sub Extent=[38:8 - 38:25] -// CHECK: usrs.cpp c:usrs....@38:1...@n@f...@n@t...@f@s...@a Extent=[38:12 - 38:17] -// CHECK: usrs.cpp c:usrs....@38:1...@n@f...@n@t...@f@s...@b Extent=[38:19 - 38:24] +// CHECK: usrs.cpp c:usrs....@37:2...@n@f...@n@t...@f@add#I#I Extent=[37:21 - 37:56] +// CHECK: usrs.cpp c:usrs....@37:2...@n@f...@n@t...@f@add#...@a Extent=[37:25 - 37:30] +// CHECK: usrs.cpp c:usrs....@37:3...@n@f...@n@t...@f@add#...@b Extent=[37:32 - 37:37] +// CHECK: usrs.cpp c:@n...@foo@n...@taz@f...@sub#i#i Extent=[38:8 - 38:25] +// CHECK: usrs.cpp c:usrs....@38:1...@n@f...@n@t...@f@sub#...@a Extent=[38:12 - 38:17] +// CHECK: usrs.cpp c:usrs....@38:1...@n@f...@n@t...@f@sub#...@b Extent=[38:19 - 38:24] // CHECK: usrs.cpp c:@n...@foo Extent=[42:11 - 48:3] // CHECK: usrs.cpp c:@n...@foo@n...@taz Extent=[42:27 - 48:2] // CHECK: usrs.cpp c:@n...@foo@n...@taz@c...@clsd Extent=[43:3 - 47:4] -// CHECK: usrs.cpp c:@n...@foo@n...@taz@c...@clsd@f...@operator= Extent=[45:11 - 45:52] -// CHECK: usrs.cpp c:usrs....@45:2...@n@f...@n@t...@c@c...@f@operat...@x Extent=[45:21 - 45:26] -// CHECK: usrs.cpp c:@n...@foo@n...@taz@c...@clsd@f...@operator= Extent=[46:11 - 46:61] -// CHECK: usrs.cpp c:usrs....@46:2...@n@f...@n@t...@c@c...@f@operat...@x Extent=[46:21 - 46:29] - - +// CHECK: usrs.cpp c:@n...@foo@n...@taz@c...@clsd@f...@operator=#i Extent=[45:11 - 45:52] +// CHECK: usrs.cpp c:usrs....@45:2...@n@f...@n@t...@c@c...@f@operator...@x Extent=[45:21 - 45:26] +// CHECK: usrs.cpp c:@n...@foo@n...@taz@c...@clsd@f...@operator=#d Extent=[46:11 - 46:61] +// CHECK: usrs.cpp c:usrs....@46:2...@n@f...@n@t...@c@c...@f@operator...@x Extent=[46:21 - 46:29] +// CHECK: usrs.cpp c:@f...@rez Extent=[51:8 - 51:25] +// CHECK: usrs.cpp c:usrs....@51:1...@f@r...@a Extent=[51:12 - 51:17] +// CHECK: usrs.cpp c:usrs....@51:1...@f@r...@b Extent=[51:19 - 51:24] Modified: cfe/trunk/tools/libclang/CIndexUSRs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexUSRs.cpp?rev=103225&r1=103224&r2=103225&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndexUSRs.cpp (original) +++ cfe/trunk/tools/libclang/CIndexUSRs.cpp Thu May 6 20:04:32 2010 @@ -53,6 +53,10 @@ void VisitTagDecl(TagDecl *D); void VisitTypedefDecl(TypedefDecl *D); void VisitVarDecl(VarDecl *D); + void VisitLinkageSpecDecl(LinkageSpecDecl *D) { + IgnoreResults = true; + return; + } /// Generate the string component containing the location of the /// declaration. @@ -82,6 +86,8 @@ void GenObjCProperty(llvm::StringRef prop); /// Generate a USR for an Objective-C protocol. void GenObjCProtocol(llvm::StringRef prot); + + void VisitType(QualType T); }; class StringUSRGenerator { @@ -147,6 +153,20 @@ VisitDeclContext(D->getDeclContext()); Out << "@F@" << D->getNameAsString(); + + ASTContext &Ctx = AU->getASTContext(); + if (!Ctx.getLangOptions().CPlusPlus || D->isExternC()) + return; + + // Mangle in type information for the arguments. + for (FunctionDecl::param_iterator I = D->param_begin(), E = D->param_end(); + I != E; ++I) { + Out << '#'; + if (ParmVarDecl *PD = *I) + VisitType(PD->getType()); + } + if (D->isVariadic()) + Out << '.'; } void USRGenerator::VisitNamedDecl(NamedDecl *D) { @@ -274,7 +294,7 @@ // translation units. if (ShouldGenerateLocation(D) && GenLoc(D)) return; - + D = D->getCanonicalDecl(); VisitDeclContext(D->getDeclContext()); @@ -336,10 +356,126 @@ Out << '@' << SM.getLineNumber(Decomposed.first, Decomposed.second) << ':' << SM.getColumnNumber(Decomposed.first, Decomposed.second); - + return IgnoreResults; } +void USRGenerator::VisitType(QualType T) { + // This method mangles in USR information for types. It can possibly + // just reuse the naming-mangling logic used by codegen, although the + // requirements for USRs might not be the same. + do { + T = T.getTypePtr()->getCanonicalTypeInternal(); + Qualifiers Q = T.getQualifiers(); + if (Q.hasConst()) + Out << '1'; + if (Q.hasVolatile()) + Out << '2'; + if (Q.hasRestrict()) + Out << '3'; + + // Mangle in ObjC GC qualifiers? + + if (const PointerType *PT = T->getAs<PointerType>()) { + Out << '*'; + T = PT->getPointeeType(); + continue; + } + if (const ReferenceType *RT = T->getAs<ReferenceType>()) { + Out << '&'; + T = RT->getPointeeType(); + continue; + } + if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) { + Out << 'F'; + VisitType(FT->getResultType()); + for (FunctionProtoType::arg_type_iterator + I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) { + VisitType(*I); + } + if (FT->isVariadic()) + Out << '.'; + return; + } + if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) { + Out << 'B'; + T = BT->getPointeeType(); + continue; + } + if (const BuiltinType *BT = T->getAs<BuiltinType>()) { + unsigned char c = '\0'; + switch (BT->getKind()) { + case BuiltinType::Void: + c = 'v'; break; + case BuiltinType::Bool: + c = 'b'; break; + case BuiltinType::Char_U: + case BuiltinType::UChar: + c = 'c'; break; + case BuiltinType::Char16: + c = 'q'; break; + case BuiltinType::Char32: + c = 'w'; break; + case BuiltinType::UShort: + c = 's'; break; + case BuiltinType::UInt: + c = 'i'; break; + case BuiltinType::ULong: + c = 'l'; break; + case BuiltinType::ULongLong: + c = 'k'; break; + case BuiltinType::UInt128: + c = 'j'; break; + case BuiltinType::Char_S: + case BuiltinType::SChar: + c = 'C'; break; + case BuiltinType::WChar: + c = 'W'; break; + case BuiltinType::Short: + c = 'S'; break; + case BuiltinType::Int: + c = 'I'; break; + case BuiltinType::Long: + c = 'L'; break; + case BuiltinType::LongLong: + c = 'K'; break; + case BuiltinType::Int128: + c = 'J'; break; + case BuiltinType::Float: + c = 'f'; break; + case BuiltinType::Double: + c = 'd'; break; + case BuiltinType::LongDouble: + c = 'D'; break; + case BuiltinType::NullPtr: + c = 'n'; break; + case BuiltinType::Overload: + case BuiltinType::Dependent: + case BuiltinType::UndeducedAuto: + IgnoreResults = true; + return; + case BuiltinType::ObjCId: + c = 'o'; break; + case BuiltinType::ObjCClass: + c = 'O'; break; + case BuiltinType::ObjCSel: + c = 'e'; break; + } + Out << c; + return; + } + if (const ComplexType *CT = T->getAs<ComplexType>()) { + Out << '<'; + T = CT->getElementType(); + continue; + } + + // Unhandled type. + Out << ' '; + break; + } while (true); +} + //===----------------------------------------------------------------------===// // General purpose USR generation methods. //===----------------------------------------------------------------------===// _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits