[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] macro definitions for static analysis
|
Hi Nate, thanks for your response.
> Perhaps you can parse the file twice, once with the relevant macros
> defined and once with them not defined?
Sure, but in the cases were a project has "n" directives, I would have to compile 2^n possible configurations, right? So this approach probably does not scale.
> The resulting AST could very easily be ill-formed.
I agree. Perhaps, I would have to pick up a specific configuration before applying static analysis of preprocessing based c++ code.
Regards,
Rodrigo.
Sent from my iPad
On 07/01/2014, at 22:06, Nathan Ridge <zeratul976@xxxxxxxxxxx> wrote:
>> I am implementing a simple C++ static analysis tool using CDT. Is it possible to configure the scanner / parser to visit all statements, independently of the preprocessing directives? I mean, I have a peace of code such as:
>>
>>
>> #if ((defined __MINGW32__) || (defined _MSC_VER)) // *** changed in 1.4.0 and 1.4.1
>> // "A" statements here...
>> // ....
>> #else
>> // "B" statements here
>> //....
>> #endif
>>
>> I would like to collect some data related to both "A" statements and "B" statements. How can I force the scanner to ignore the macro definitions? Bellow, I present the code that I am using to parse a translation unit.
>>
>> public IASTTranslationUnit parse(char[] code) throws Exception {
>> FileContent fc = FileContent.create("", code);
>> Map<String, String> macroDefinitions = new HashMap<String, String>();
>> String[] includeSearchPath = new String[0];
>> IScannerInfo si = new ScannerInfo(macroDefinitions, includeSearchPath);
>> IncludeFileContentProvider ifcp = IncludeFileContentProvider.getEmptyFilesProvider();
>> IIndex idx = null;
>> int options = ILanguage.OPTION_PARSE_INACTIVE_CODE;
>> IParserLogService log = new DefaultLogService();
>> return GPPLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp, idx, options, log);
>> }
>>
>> All the best,
>>
>> Rodrigo.
>
> Perhaps you can parse the file twice, once with the relevant macros
> defined and once with them not defined?
>
> I don't think that trying to force the parser to construct an AST that
> includes both branches of a preprocessor conditional is a good idea.
> The resulting AST could very easily be ill-formed.
>
> Regards,
> Nate
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev