Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] macro definitions for static analysis

Dear all,

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. 

Sent from my iPad

Back to the top