[cfe-commits] r74198 - in /cfe/trunk: test/Index/ test/Index/resolve-loc.c tools/CMakeLists.txt tools/Makefile tools/index-test/ tools/index-test/CMakeLists.txt tools/index-test/Makefile tools/index-test/index-test.cpp

Argyrios Kyrtzidis kyrtzidis at apple.com
Thu Jun 25 16:26:23 PDT 2009


On Jun 25, 2009, at 3:43 PM, Douglas Gregor wrote:

>
>> +  struct ASTPoint {
>> +    Decl *D;
>> +    Stmt *Node;
>> +    ASTPoint() : D(0), Node(0) {}
>> +  };
>> +
>> +  ASTPoint Point;
>> +
>> +  if (!PointAtLocation.empty()) {
>> +    const std::string &Filename = PointAtLocation[0].FileName;
>> +    const FileEntry *File = FileMgr.getFile(Filename);
>> +    if (File == 0) {
>> +      llvm::errs() << "File '" << Filename << "' does not exist\n";
>> +      return 1;
>> +    }
>> +    unsigned Line = PointAtLocation[0].Line;
>> +    unsigned Col = PointAtLocation[0].Column;
>> +
>> +    SourceLocation Loc = AST->getSourceManager().getLocation(File,
>> Line, Col);
>> +    if (Loc.isInvalid()) {
>> +      llvm::errs() << "[" << InFile << "] Error: " <<
>> +        "Couldn't resolve source location (invalid location)\n";
>> +      return 1;
>> +    }
>> +
>> +    llvm::tie(Point.D, Point.Node) =
>> +      ResolveLocationInAST(AST->getASTContext(), Loc);
>
> Have you thought about what happens when the location points to a
> macro invocation?
> (I know that's something to be dealt with "later")

If you point at the start of the macro it's like pointing at the start  
of the text that it inserts. If you point inside the macro word, it's  
like pointing past the text.
Definitely needs specific handling.

-Argiris

>
>> +    if (Point.D == 0) {
>> +      llvm::errs() << "[" << InFile << "] Error: " <<
>> +        "Couldn't resolve source location (no declaration found)\n";
>> +      return 1;
>> +    }
>> +  }
>> +
>> +  if (Point.D) {
>> +    if (PointAtLocation.empty()) {
>> +      llvm::errs() << "'-print-point-info' should be used together "
>> +                      "with '-point-at'\n";
>> +      return 1;
>> +    }
>> +
>> +    llvm::raw_ostream &OS = llvm::outs();
>> +    assert(Point.D && "If no node was found we should have exited
>> with error");
>> +    OS << "Declaration node at point: " << Point.D->getDeclKindName
>> () << " ";
>> +    if (NamedDecl *ND = dyn_cast<NamedDecl>(Point.D))
>> +      OS << ND->getNameAsString();
>> +    OS << "\n";
>> +
>> +    if (Point.Node) {
>> +      OS << "Statement node at point: " << Point.Node-
>>> getStmtClassName()
>> +         << " ";
>> +      Point.Node->printPretty(OS, AST->getASTContext());
>> +      OS << "\n";
>> +    }
>> +  }
>
> This looks like a good test hardness. Great!
>
>   - Doug
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list