[cfe-dev] Parsing All Comments

Chengnian Sun via cfe-dev cfe-dev at lists.llvm.org
Fri Oct 16 01:16:13 PDT 2015


Thank you for your reply. The comment is very simple. Each function
definition has a preceding comment, listing all the global variables used
in the function definition. I need to parse this comment to get the
variable list.

Yes, I actually found another old post mentioning
CommentOptions::ParseAllComments.
However I am new to LLVM/Clang, and I found out it was just a structure
defined in CommentOptions.h if I am not wrong.

The following shows the stub of my LitTooling code. Any advice will be
appreciated. Thank you.





class InstrumentAction : public ASTFrontendAction {
public:
  virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance
&CI,
                                                         StringRef InFile){
    errs() << "Processing " << InFile << "\n";
    return std::unique_ptr<ASTConsumer>(
      new Instrument(InFile, CI.getASTContext(), InstrumentProb));
  }
};

int main(int argc, const char **argv) {
  InstrumentProb.setCategory(MyToolCategory);
  CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
  ClangTool
Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList());
  return Tool.run(newFrontendActionFactory<InstrumentAction>().get());
}


On Fri, Oct 16, 2015 at 12:40 AM, James Dennett <james.dennett at gmail.com>
wrote:

> On Fri, Oct 16, 2015 at 12:29 AM, Chengnian Sun via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> Hi,
>>
>> I am trying to parse the comment attached to declarations. However, it
>> seems that clang only parses documentation comments, but not line comments
>> or block comments.
>>
>
> Can you give examples of what you're hoping to parse, and how you might
> access it?
>
>
>> Is there a way do enable the parser to parse all the comments?
>>
>> I am using LibTooling and new to it, and cannot find a way to this. Your
>> help is greatly appreciated.
>>
>> Thank you.
>>
>>
> You might look at CommentOptions::ParseAllComments in case that's related
> to what you're trying to do.
>
> -- James
>
>
>


-- 
Best Regards.

Chengnian SUN.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151016/b628d154/attachment.html>


More information about the cfe-dev mailing list