Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 1 | //===--- ResolveLocation.cpp - Source location resolver ---------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This defines the ResolveLocationInAST function, which resolves a |
Argiris Kirtzidis | 98eec71 | 2009-07-06 21:35:02 +0000 | [diff] [blame] | 11 | // source location into a ASTLocation. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Argiris Kirtzidis | 98eec71 | 2009-07-06 21:35:02 +0000 | [diff] [blame] | 15 | #include "clang/Index/Utils.h" |
Argiris Kirtzidis | 75abd9c | 2009-07-06 21:34:47 +0000 | [diff] [blame] | 16 | #include "clang/Index/ASTLocation.h" |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclVisitor.h" |
| 18 | #include "clang/AST/StmtVisitor.h" |
| 19 | #include "clang/Lex/Lexer.h" |
| 20 | #include "clang/Basic/SourceManager.h" |
| 21 | #include "llvm/Support/Compiler.h" |
| 22 | using namespace clang; |
Argiris Kirtzidis | 75abd9c | 2009-07-06 21:34:47 +0000 | [diff] [blame] | 23 | using namespace idx; |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
| 27 | /// \brief Base for the LocResolver classes. Mostly does source range checking. |
| 28 | class VISIBILITY_HIDDEN LocResolverBase { |
| 29 | protected: |
| 30 | ASTContext &Ctx; |
| 31 | SourceLocation Loc; |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 32 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 33 | enum RangePos { |
| 34 | BeforeLoc, |
| 35 | ContainsLoc, |
| 36 | AfterLoc |
| 37 | }; |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 38 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 39 | RangePos CheckRange(SourceRange Range); |
| 40 | RangePos CheckRange(Decl *D) { return CheckRange(D->getSourceRange()); } |
| 41 | RangePos CheckRange(Stmt *Node) { return CheckRange(Node->getSourceRange()); } |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 42 | |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 43 | template <typename T> |
| 44 | bool isBeforeLocation(T *Node) { |
| 45 | return CheckRange(Node) == BeforeLoc; |
| 46 | } |
| 47 | |
| 48 | template <typename T> |
| 49 | bool ContainsLocation(T *Node) { |
| 50 | return CheckRange(Node) == ContainsLoc; |
| 51 | } |
| 52 | |
| 53 | template <typename T> |
| 54 | bool isAfterLocation(T *Node) { |
| 55 | return CheckRange(Node) == AfterLoc; |
| 56 | } |
| 57 | |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 58 | public: |
| 59 | LocResolverBase(ASTContext &ctx, SourceLocation loc) |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 60 | : Ctx(ctx), Loc(loc) {} |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 61 | |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 62 | /// \brief Debugging output. |
| 63 | void print(Decl *D); |
| 64 | /// \brief Debugging output. |
| 65 | void print(Stmt *Node); |
| 66 | }; |
| 67 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 68 | /// \brief Searches a statement for the ASTLocation that corresponds to a source |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 69 | /// location. |
| 70 | class VISIBILITY_HIDDEN StmtLocResolver : public LocResolverBase, |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 71 | public StmtVisitor<StmtLocResolver, |
| 72 | ASTLocation > { |
| 73 | Decl *Parent; |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 74 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 75 | public: |
| 76 | StmtLocResolver(ASTContext &ctx, SourceLocation loc, Decl *parent) |
| 77 | : LocResolverBase(ctx, loc), Parent(parent) {} |
| 78 | |
| 79 | ASTLocation VisitDeclStmt(DeclStmt *Node); |
| 80 | ASTLocation VisitStmt(Stmt *Node); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 83 | /// \brief Searches a declaration for the ASTLocation that corresponds to a |
| 84 | /// source location. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 85 | class VISIBILITY_HIDDEN DeclLocResolver : public LocResolverBase, |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 86 | public DeclVisitor<DeclLocResolver, |
| 87 | ASTLocation > { |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 88 | public: |
| 89 | DeclLocResolver(ASTContext &ctx, SourceLocation loc) |
| 90 | : LocResolverBase(ctx, loc) {} |
| 91 | |
Argiris Kirtzidis | 875544f | 2009-07-14 03:18:17 +0000 | [diff] [blame] | 92 | ASTLocation VisitDeclContext(DeclContext *DC); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 93 | ASTLocation VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
Argiris Kirtzidis | 875544f | 2009-07-14 03:18:17 +0000 | [diff] [blame] | 94 | ASTLocation VisitRecordDecl(RecordDecl *D); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 95 | ASTLocation VisitVarDecl(VarDecl *D); |
| 96 | ASTLocation VisitFunctionDecl(FunctionDecl *D); |
| 97 | ASTLocation VisitDecl(Decl *D); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // anonymous namespace |
| 101 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 102 | ASTLocation StmtLocResolver::VisitDeclStmt(DeclStmt *Node) { |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 103 | assert(ContainsLocation(Node) && |
| 104 | "Should visit only after verifying that loc is in range"); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 105 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 106 | // Search all declarations of this DeclStmt. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 107 | for (DeclStmt::decl_iterator |
| 108 | I = Node->decl_begin(), E = Node->decl_end(); I != E; ++I) { |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 109 | RangePos RP = CheckRange(*I); |
| 110 | if (RP == AfterLoc) |
| 111 | break; |
| 112 | if (RP == ContainsLoc) |
| 113 | return DeclLocResolver(Ctx, Loc).Visit(*I); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 114 | } |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 115 | |
| 116 | return ASTLocation(Parent, Node); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 119 | ASTLocation StmtLocResolver::VisitStmt(Stmt *Node) { |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 120 | assert(ContainsLocation(Node) && |
| 121 | "Should visit only after verifying that loc is in range"); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 122 | |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 123 | // Search the child statements. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 124 | for (Stmt::child_iterator |
| 125 | I = Node->child_begin(), E = Node->child_end(); I != E; ++I) { |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 126 | RangePos RP = CheckRange(*I); |
| 127 | if (RP == AfterLoc) |
| 128 | break; |
| 129 | if (RP == ContainsLoc) |
| 130 | return Visit(*I); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 131 | } |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 132 | |
| 133 | return ASTLocation(Parent, Node); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Argiris Kirtzidis | 875544f | 2009-07-14 03:18:17 +0000 | [diff] [blame] | 136 | ASTLocation DeclLocResolver::VisitDeclContext(DeclContext *DC) { |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 137 | for (DeclContext::decl_iterator |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 138 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 139 | RangePos RP = CheckRange(*I); |
| 140 | if (RP == AfterLoc) |
| 141 | break; |
| 142 | if (RP == ContainsLoc) |
| 143 | return Visit(*I); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 144 | } |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 145 | |
Argiris Kirtzidis | 875544f | 2009-07-14 03:18:17 +0000 | [diff] [blame] | 146 | return ASTLocation(cast<Decl>(DC)); |
| 147 | } |
| 148 | |
| 149 | ASTLocation DeclLocResolver::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
| 150 | ASTLocation ASTLoc = VisitDeclContext(TU); |
| 151 | if (ASTLoc.getDecl() == TU) |
| 152 | return ASTLocation(); |
| 153 | return ASTLoc; |
| 154 | } |
| 155 | |
| 156 | ASTLocation DeclLocResolver::VisitRecordDecl(RecordDecl *D) { |
| 157 | assert(ContainsLocation(D) && |
| 158 | "Should visit only after verifying that loc is in range"); |
| 159 | return VisitDeclContext(D); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 162 | ASTLocation DeclLocResolver::VisitFunctionDecl(FunctionDecl *D) { |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 163 | assert(ContainsLocation(D) && |
| 164 | "Should visit only after verifying that loc is in range"); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 165 | |
| 166 | // First, search through the parameters of the function. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 167 | for (FunctionDecl::param_iterator |
| 168 | I = D->param_begin(), E = D->param_end(); I != E; ++I) { |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 169 | RangePos RP = CheckRange(*I); |
| 170 | if (RP == AfterLoc) |
| 171 | return ASTLocation(D); |
| 172 | if (RP == ContainsLoc) |
| 173 | return Visit(*I); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 176 | // We didn't find the location in the parameters and we didn't get passed it. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 177 | |
Argiris Kirtzidis | 4770f5e | 2009-07-05 22:21:17 +0000 | [diff] [blame] | 178 | if (!D->isThisDeclarationADefinition()) |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 179 | return ASTLocation(D); |
Argiris Kirtzidis | 4770f5e | 2009-07-05 22:21:17 +0000 | [diff] [blame] | 180 | |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 181 | // Second, search through the declarations that are part of the function. |
| 182 | // If we find he location there, we won't have to search through its body. |
Argiris Kirtzidis | 7283e46 | 2009-07-05 22:21:46 +0000 | [diff] [blame] | 183 | |
Argiris Kirtzidis | 7283e46 | 2009-07-05 22:21:46 +0000 | [diff] [blame] | 184 | for (DeclContext::decl_iterator |
| 185 | I = D->decls_begin(), E = D->decls_end(); I != E; ++I) { |
| 186 | if (isa<ParmVarDecl>(*I)) |
| 187 | continue; // We already searched through the parameters. |
| 188 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 189 | RangePos RP = CheckRange(*I); |
| 190 | if (RP == AfterLoc) |
| 191 | break; |
| 192 | if (RP == ContainsLoc) |
| 193 | return Visit(*I); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 194 | } |
Argiris Kirtzidis | 7283e46 | 2009-07-05 22:21:46 +0000 | [diff] [blame] | 195 | |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 196 | // We didn't find a declaration that corresponds to the source location. |
| 197 | |
| 198 | // Finally, search through the body of the function. |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 199 | Stmt *Body = D->getBody(); |
| 200 | assert(Body && "Expected definition"); |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 201 | assert(!isBeforeLocation(Body) && |
| 202 | "This function is supposed to contain the loc"); |
| 203 | if (isAfterLocation(Body)) |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 204 | return ASTLocation(D); |
| 205 | |
| 206 | // The body contains the location. |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 207 | assert(ContainsLocation(Body)); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 208 | return StmtLocResolver(Ctx, Loc, D).Visit(Body); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 211 | ASTLocation DeclLocResolver::VisitVarDecl(VarDecl *D) { |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 212 | assert(ContainsLocation(D) && |
| 213 | "Should visit only after verifying that loc is in range"); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 214 | |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 215 | // Check whether the location points to the init expression. |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 216 | Expr *Init = D->getInit(); |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 217 | if (Init && ContainsLocation(Init)) |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 218 | return StmtLocResolver(Ctx, Loc, D).Visit(Init); |
| 219 | |
| 220 | return ASTLocation(D); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 223 | ASTLocation DeclLocResolver::VisitDecl(Decl *D) { |
Argiris Kirtzidis | 8be9dda | 2009-07-10 03:41:26 +0000 | [diff] [blame] | 224 | assert(ContainsLocation(D) && |
| 225 | "Should visit only after verifying that loc is in range"); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 226 | return ASTLocation(D); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 229 | LocResolverBase::RangePos LocResolverBase::CheckRange(SourceRange Range) { |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 230 | if (!Range.isValid()) |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 231 | return BeforeLoc; // Keep looking. |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 232 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 233 | // Update the end source range to cover the full length of the token |
| 234 | // positioned at the end of the source range. |
| 235 | // |
| 236 | // e.g., |
| 237 | // int foo |
| 238 | // ^ ^ |
| 239 | // |
| 240 | // will be updated to |
| 241 | // int foo |
| 242 | // ^ ^ |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 243 | unsigned TokSize = Lexer::MeasureTokenLength(Range.getEnd(), |
| 244 | Ctx.getSourceManager(), |
| 245 | Ctx.getLangOptions()); |
| 246 | Range.setEnd(Range.getEnd().getFileLocWithOffset(TokSize-1)); |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 247 | |
| 248 | SourceManager &SourceMgr = Ctx.getSourceManager(); |
| 249 | if (SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), Loc)) |
| 250 | return BeforeLoc; |
| 251 | |
| 252 | if (SourceMgr.isBeforeInTranslationUnit(Loc, Range.getBegin())) |
| 253 | return AfterLoc; |
| 254 | |
| 255 | return ContainsLoc; |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void LocResolverBase::print(Decl *D) { |
| 259 | llvm::raw_ostream &OS = llvm::outs(); |
| 260 | OS << "#### DECL ####\n"; |
Argiris Kirtzidis | 9a6fb96 | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 261 | D->print(OS); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 262 | OS << " <"; |
| 263 | D->getLocStart().print(OS, Ctx.getSourceManager()); |
| 264 | OS << " > - <"; |
| 265 | D->getLocEnd().print(OS, Ctx.getSourceManager()); |
| 266 | OS << ">\n\n"; |
| 267 | OS.flush(); |
| 268 | } |
| 269 | |
| 270 | void LocResolverBase::print(Stmt *Node) { |
| 271 | llvm::raw_ostream &OS = llvm::outs(); |
| 272 | OS << "#### STMT ####\n"; |
Chris Lattner | 7099c78 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 273 | Node->printPretty(OS, Ctx, 0, PrintingPolicy(Ctx.getLangOptions())); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 274 | OS << " <"; |
| 275 | Node->getLocStart().print(OS, Ctx.getSourceManager()); |
| 276 | OS << " > - <"; |
| 277 | Node->getLocEnd().print(OS, Ctx.getSourceManager()); |
| 278 | OS << ">\n\n"; |
| 279 | OS.flush(); |
| 280 | } |
| 281 | |
| 282 | |
| 283 | /// \brief Returns the AST node that a source location points to. |
| 284 | /// |
Argiris Kirtzidis | 98eec71 | 2009-07-06 21:35:02 +0000 | [diff] [blame] | 285 | ASTLocation idx::ResolveLocationInAST(ASTContext &Ctx, SourceLocation Loc) { |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 286 | if (Loc.isInvalid()) |
Argiris Kirtzidis | 2fcbc1e | 2009-07-06 21:34:20 +0000 | [diff] [blame] | 287 | return ASTLocation(); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 288 | |
Argiris Kirtzidis | 3ed0753 | 2009-07-07 00:53:31 +0000 | [diff] [blame] | 289 | return DeclLocResolver(Ctx, Loc).Visit(Ctx.getTranslationUnitDecl()); |
Argiris Kirtzidis | 40bf283 | 2009-06-25 18:22:41 +0000 | [diff] [blame] | 290 | } |