diff options
Diffstat (limited to 'lib/Index')
-rw-r--r-- | lib/Index/ASTLocation.cpp | 2 | ||||
-rw-r--r-- | lib/Index/ASTVisitor.h | 8 | ||||
-rw-r--r-- | lib/Index/DeclReferenceMap.cpp | 8 | ||||
-rw-r--r-- | lib/Index/Entity.cpp | 8 | ||||
-rw-r--r-- | lib/Index/GlobalSelector.cpp | 10 | ||||
-rw-r--r-- | lib/Index/ResolveLocation.cpp | 66 |
6 files changed, 70 insertions, 32 deletions
diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index 6294d69..c24f3bf 100644 --- a/lib/Index/ASTLocation.cpp +++ b/lib/Index/ASTLocation.cpp @@ -101,7 +101,7 @@ void ASTLocation::print(llvm::raw_ostream &OS) const { break; case N_Type: { - QualType T = AsTypeLoc().getSourceType(); + QualType T = AsTypeLoc().getType(); OS << "[Type: " << T->getTypeClassName() << " " << T.getAsString(); } } diff --git a/lib/Index/ASTVisitor.h b/lib/Index/ASTVisitor.h index e18aa57..0ae78fb 100644 --- a/lib/Index/ASTVisitor.h +++ b/lib/Index/ASTVisitor.h @@ -123,14 +123,14 @@ public: BaseTypeLocVisitor::Visit(TL); } - void VisitArrayLoc(ArrayLoc TL) { - BaseTypeLocVisitor::VisitArrayLoc(TL); + void VisitArrayLoc(ArrayTypeLoc TL) { + BaseTypeLocVisitor::VisitArrayTypeLoc(TL); if (TL.getSizeExpr()) Visit(TL.getSizeExpr()); } - void VisitFunctionLoc(FunctionLoc TL) { - BaseTypeLocVisitor::VisitFunctionLoc(TL); + void VisitFunctionTypeLoc(FunctionTypeLoc TL) { + BaseTypeLocVisitor::VisitFunctionTypeLoc(TL); for (unsigned i = 0; i != TL.getNumArgs(); ++i) Visit(TL.getArg(i)); } diff --git a/lib/Index/DeclReferenceMap.cpp b/lib/Index/DeclReferenceMap.cpp index 0e48a36..366cf1b 100644 --- a/lib/Index/DeclReferenceMap.cpp +++ b/lib/Index/DeclReferenceMap.cpp @@ -31,8 +31,8 @@ public: void VisitMemberExpr(MemberExpr *Node); void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node); - void VisitTypedefLoc(TypedefLoc TL); - void VisitObjCInterfaceLoc(ObjCInterfaceLoc TL); + void VisitTypedefTypeLoc(TypedefTypeLoc TL); + void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL); }; } // anonymous namespace @@ -55,12 +55,12 @@ void RefMapper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { Map.insert(std::make_pair(Node->getDecl(), ASTLocation(CurrentDecl, Node))); } -void RefMapper::VisitTypedefLoc(TypedefLoc TL) { +void RefMapper::VisitTypedefTypeLoc(TypedefTypeLoc TL) { NamedDecl *ND = TL.getTypedefDecl(); Map.insert(std::make_pair(ND, ASTLocation(CurrentDecl, ND, TL.getNameLoc()))); } -void RefMapper::VisitObjCInterfaceLoc(ObjCInterfaceLoc TL) { +void RefMapper::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { NamedDecl *ND = TL.getIFaceDecl(); Map.insert(std::make_pair(ND, ASTLocation(CurrentDecl, ND, TL.getNameLoc()))); } diff --git a/lib/Index/Entity.cpp b/lib/Index/Entity.cpp index 77d7a84..03fe9f7 100644 --- a/lib/Index/Entity.cpp +++ b/lib/Index/Entity.cpp @@ -72,7 +72,8 @@ Entity EntityGetter::VisitNamedDecl(NamedDecl *D) { if (IdentifierInfo *II = LocalName.getAsIdentifierInfo()) { IdentifierInfo *GlobII = - &ProgImpl.getIdents().get(II->getName(), II->getName() + II->getLength()); + &ProgImpl.getIdents().get(II->getNameStart(), + II->getNameStart() + II->getLength()); GlobName = DeclarationName(GlobII); } else { Selector LocalSel = LocalName.getObjCSelector(); @@ -139,8 +140,9 @@ Decl *EntityImpl::getDecl(ASTContext &AST) { DeclarationName LocalName; if (IdentifierInfo *GlobII = Name.getAsIdentifierInfo()) { - IdentifierInfo &II = AST.Idents.get(GlobII->getName(), - GlobII->getName() + GlobII->getLength()); + IdentifierInfo &II = + AST.Idents.get(GlobII->getNameStart(), + GlobII->getNameStart() + GlobII->getLength()); LocalName = DeclarationName(&II); } else { Selector GlobSel = Name.getObjCSelector(); diff --git a/lib/Index/GlobalSelector.cpp b/lib/Index/GlobalSelector.cpp index f3ec41d..2b2ca6d 100644 --- a/lib/Index/GlobalSelector.cpp +++ b/lib/Index/GlobalSelector.cpp @@ -29,8 +29,9 @@ Selector GlobalSelector::getSelector(ASTContext &AST) const { for (unsigned i = 0, e = GlobSel.isUnarySelector() ? 1 : GlobSel.getNumArgs(); i != e; ++i) { IdentifierInfo *GlobII = GlobSel.getIdentifierInfoForSlot(i); - IdentifierInfo *II = &AST.Idents.get(GlobII->getName(), - GlobII->getName() + GlobII->getLength()); + IdentifierInfo *II = + &AST.Idents.get(GlobII->getNameStart(), + GlobII->getNameStart() + GlobII->getLength()); Ids.push_back(II); } @@ -57,8 +58,9 @@ GlobalSelector GlobalSelector::get(Selector Sel, Program &Prog) { for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs(); i != e; ++i) { IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i); - IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName(), - II->getName() + II->getLength()); + IdentifierInfo *GlobII = + &ProgImpl.getIdents().get(II->getNameStart(), + II->getNameStart() + II->getLength()); Ids.push_back(GlobII); } diff --git a/lib/Index/ResolveLocation.cpp b/lib/Index/ResolveLocation.cpp index 229669d..8edd634 100644 --- a/lib/Index/ResolveLocation.cpp +++ b/lib/Index/ResolveLocation.cpp @@ -120,11 +120,12 @@ public: TypeLocResolver(ASTContext &ctx, SourceLocation loc, Decl *pd) : LocResolverBase(ctx, loc), ParentDecl(pd) { } - ASTLocation VisitTypedefLoc(TypedefLoc TL); - ASTLocation VisitFunctionLoc(FunctionLoc TL); - ASTLocation VisitArrayLoc(ArrayLoc TL); - ASTLocation VisitObjCInterfaceLoc(ObjCInterfaceLoc TL); - ASTLocation VisitObjCProtocolListLoc(ObjCProtocolListLoc TL); + ASTLocation VisitBuiltinTypeLoc(BuiltinTypeLoc TL); + ASTLocation VisitTypedefTypeLoc(TypedefTypeLoc TL); + ASTLocation VisitFunctionTypeLoc(FunctionTypeLoc TL); + ASTLocation VisitArrayTypeLoc(ArrayTypeLoc TL); + ASTLocation VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL); + ASTLocation VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL); ASTLocation VisitTypeLoc(TypeLoc TL); }; @@ -349,7 +350,25 @@ ASTLocation DeclLocResolver::VisitDecl(Decl *D) { return ASTLocation(D); } -ASTLocation TypeLocResolver::VisitTypedefLoc(TypedefLoc TL) { +ASTLocation TypeLocResolver::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { + // Continue the 'id' magic by making the builtin type (which cannot + // actually be spelled) map to the typedef. + BuiltinType *T = TL.getTypePtr(); + if (T->getKind() == BuiltinType::ObjCId) { + TypedefDecl *D = Ctx.getObjCIdType()->getAs<TypedefType>()->getDecl(); + return ASTLocation(ParentDecl, D, TL.getNameLoc()); + } + + // Same thing with 'Class'. + if (T->getKind() == BuiltinType::ObjCClass) { + TypedefDecl *D = Ctx.getObjCClassType()->getAs<TypedefType>()->getDecl(); + return ASTLocation(ParentDecl, D, TL.getNameLoc()); + } + + return ASTLocation(ParentDecl, TL); +} + +ASTLocation TypeLocResolver::VisitTypedefTypeLoc(TypedefTypeLoc TL) { assert(ContainsLocation(TL) && "Should visit only after verifying that loc is in range"); if (ContainsLocation(TL.getNameLoc())) @@ -357,7 +376,7 @@ ASTLocation TypeLocResolver::VisitTypedefLoc(TypedefLoc TL) { return ASTLocation(ParentDecl, TL); } -ASTLocation TypeLocResolver::VisitFunctionLoc(FunctionLoc TL) { +ASTLocation TypeLocResolver::VisitFunctionTypeLoc(FunctionTypeLoc TL) { assert(ContainsLocation(TL) && "Should visit only after verifying that loc is in range"); @@ -373,7 +392,7 @@ ASTLocation TypeLocResolver::VisitFunctionLoc(FunctionLoc TL) { return ASTLocation(ParentDecl, TL); } -ASTLocation TypeLocResolver::VisitArrayLoc(ArrayLoc TL) { +ASTLocation TypeLocResolver::VisitArrayTypeLoc(ArrayTypeLoc TL) { assert(ContainsLocation(TL) && "Should visit only after verifying that loc is in range"); @@ -384,17 +403,11 @@ ASTLocation TypeLocResolver::VisitArrayLoc(ArrayLoc TL) { return ASTLocation(ParentDecl, TL); } -ASTLocation TypeLocResolver::VisitObjCInterfaceLoc(ObjCInterfaceLoc TL) { +ASTLocation TypeLocResolver::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { assert(ContainsLocation(TL) && "Should visit only after verifying that loc is in range"); if (ContainsLocation(TL.getNameLoc())) return ASTLocation(ParentDecl, TL.getIFaceDecl(), TL.getNameLoc()); - return ASTLocation(ParentDecl, TL); -} - -ASTLocation TypeLocResolver::VisitObjCProtocolListLoc(ObjCProtocolListLoc TL) { - assert(ContainsLocation(TL) && - "Should visit only after verifying that loc is in range"); for (unsigned i = 0; i != TL.getNumProtocols(); ++i) { SourceLocation L = TL.getProtocolLoc(i); @@ -408,6 +421,24 @@ ASTLocation TypeLocResolver::VisitObjCProtocolListLoc(ObjCProtocolListLoc TL) { return ASTLocation(ParentDecl, TL); } +ASTLocation TypeLocResolver::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { + assert(ContainsLocation(TL) && + "Should visit only after verifying that loc is in range"); + + if (TL.hasProtocolsAsWritten()) { + for (unsigned i = 0; i != TL.getNumProtocols(); ++i) { + SourceLocation L = TL.getProtocolLoc(i); + RangePos RP = CheckRange(L); + if (RP == AfterLoc) + break; + if (RP == ContainsLoc) + return ASTLocation(ParentDecl, TL.getProtocol(i), L); + } + } + + return ASTLocation(ParentDecl, TL); +} + ASTLocation TypeLocResolver::VisitTypeLoc(TypeLoc TL) { assert(ContainsLocation(TL) && "Should visit only after verifying that loc is in range"); @@ -497,9 +528,12 @@ void LocResolverBase::print(Stmt *Node) { /// \brief Returns the AST node that a source location points to. /// -ASTLocation idx::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) { +ASTLocation idx::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc, + Decl *RelativeToDecl) { if (Loc.isInvalid()) return ASTLocation(); + if (RelativeToDecl) + return DeclLocResolver(Ctx, Loc).Visit(RelativeToDecl); return DeclLocResolver(Ctx, Loc).Visit(Ctx.getTranslationUnitDecl()); } |