the expressionType and includePath of CDT parser

33 Views Asked by At

As we all know, we can retrieve the ExpressionType in certain cases. However, I am currently facing an issue where I need to retrieve the return type of functions like scanf and printf. I believe resolving the problem related to includePath in IScannerInfo could potentially solve this issue.

Unfortunately, I am encountering a lack of information regarding the CDT parser, which is hindering my progress. I am eager to find a solution.

Below is how I build the ICPPTranslationUnit. I have attempted to include the path to stdio.h in includePaths, but the ExpressionType of scanf remains ProblemType.

Additionally, it appears that the parser cannot recognize size_t. As a workaround, I have added it to defineSymbols, which seems to resolve the issue.

I appreciate any assistance or guidance on this matter. Thank you.

public ICPPASTTranslationUnit getASTTranslationUnit(String filePath) throws CoreException {
        FileContent fileContent = FileContent.createForExternalFileLocation(filePath);

        HashMap definedSymbols = new HashMap();
        definedSymbols.put("size_t", "unsigned");

        String path = "file path like stdio.h";
        String[] includePaths = {path};
        IScannerInfo info = new ScannerInfo(definedSymbols, includePaths);
        IParserLogService logger = new DefaultLogService();
        IncludeFileContentProvider emptyIncludes = IncludeFileContentProvider.getEmptyFilesProvider();

        int opts = ILanguage.OPTION_IS_SOURCE_UNIT;

        return (ICPPASTTranslationUnit) GPPLanguage.getDefault().getASTTranslationUnit(fileContent, info, emptyIncludes, null, opts, logger);
    }
0

There are 0 best solutions below