[cfe-dev] Are there plans for a libDriver?

Ted Kremenek kremenek at apple.com
Tue Aug 5 11:12:42 PDT 2008


On Aug 5, 2008, at 10:41 AM, Nico Weber wrote:

> On 05.08.2008, at 18:49, Ted Kremenek wrote:
>
>>
>> On Aug 4, 2008, at 1:55 PM, Nico Weber wrote:
>>
>>> On 04.08.2008, at 22:13, Ted Kremenek wrote:
>>>
>>>>
>>>> On Aug 4, 2008, at 1:07 PM, Nico Weber wrote:
>>>>
>>>>> Are there plans for a libDriver, which makes writing simple,  
>>>>> "one-off"
>>>>> clang clients easier? With this library, the amount of code of  
>>>>> this
>>>>> program could be reduced by a whole order of magnitude (only the
>>>>> ASTConsumer, two short loops for the -D and -I options, and the  
>>>>> call
>>>>> to ParseAST would be left).
>>>>
>>>> Hi Nico,
>>>>
>>>> You are not alone.  There is a lot of interest in doing this, but  
>>>> nobody has gotten around to doing it yet.  If you are interested,  
>>>> feel free to drive some work on this by submitting patches, etc.
>>>
>>> The attached patch adds directories and Makefiles for a libDriver  
>>> and moves the TextDiagnostic classes over there for starters. I  
>>> hope `svn diff` encodes `svn mv` information correctly.
>>
>> As far as this patch is concerned, I think it is a good start.  One  
>> problem I see is that TextDiagnostPrinter.cpp currently depends on  
>> CommandLine.h, and has static variables to register command line  
>> options:
>>
>> static llvm::cl::opt<bool>
>> NoShowColumn("fno-show-column",
>>              llvm::cl::desc("Do not include column number on  
>> diagnostics"));
>> static llvm::cl::opt<bool>
>> NoCaretDiagnostics("fno-caret-diagnostics",
>>                    llvm::cl::desc("Do not include source line and  
>> caret with"
>>                                   " diagnostics"));
>>
>> This is no good.  We don't want library code automatically  
>> registering command line options in this manner.  I'm not certain  
>> what the proper mechanism should be for registering options from  
>> code in libDriver, but this isn't it, and should definitely be  
>> discussed in more detail on cfe-dev.  Ultimately we want libDriver  
>> to be usable not only by command line drivers, but potentially from  
>> other drivers such as an IDE, a daemon process, a CGI program, etc.
>
> In this case, I moved the options to clang.cpp and added flags to  
> TextDiagnosticPrinter, so there are no options in libDriver now.
>
> Nico

Instead of setShowColumn, etc., it seems better just to set these  
values in the ctor of TextDiagnosticPrinter.  That would transform:

       TextDiagnosticPrinter* TextDiagPrinter = new  
TextDiagnosticPrinter;
       TextDiagPrinter->setShowColumn(!NoShowColumn);
       TextDiagPrinter->setShowCaretDiagnostics(!NoCaretDiagnostics);

into:

       TextDiagnosticPrinter* TextDiagPrinter = new  
TextDiagnosticPrinter(NoShowColumn, NoCaretDiagnostics);

It doesn't seem likely that carets/columns would be switched on/off  
after the printer is constructed.




More information about the cfe-dev mailing list