Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339316 - IASTTranslationUnit.getRawSignature() return empty string.
Summary: IASTTranslationUnit.getRawSignature() return empty string.
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-09 01:06 EST by Alfred Wang CLA
Modified: 2011-05-26 15:11 EDT (History)
3 users (show)

See Also:


Attachments
fix (2.96 KB, patch)
2011-03-09 09:41 EST, Markus Schorn CLA
mschorn.eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alfred Wang CLA 2011-03-09 01:06:10 EST
Build Identifier: CDT 7.0, org.eclipse.cdt.core_5.2.0.201006141710.jar

A c++ source file, test.cpp is like this:
#define MACRO 1
int main()
{
   int i = MACRO;
   return i;
}

I use the following code to process this file:
private static IASTTranslationUnit parse(String filename,
		String[] incPaths, ParserLanguage lang, boolean useGNUExtensions,
		boolean expectNoProblems) throws ParserException {
	
	FileContent codeReader = FileContent.createForExternalFileLocation(filename);

	ScannerInfo scannerInfo = new ScannerInfo(null, incPaths);
	IScannerExtensionConfiguration configuration = null;
	if (lang == ParserLanguage.C)
		configuration = GCCScannerExtensionConfiguration.getInstance();
	else
		configuration = GPPScannerExtensionConfiguration.getInstance();

	IScanner scanner = new CPreprocessor(codeReader, scannerInfo, lang,
			NULL_LOG, configuration, IncludeFileContentProvider.getSavedFilesProvider());
	
	ISourceCodeParser parser2 = null;
	if (lang == ParserLanguage.CPP) {
		ICPPParserExtensionConfiguration config = null;
		if (useGNUExtensions)
			config = new GPPParserExtensionConfiguration();
		else
			config = new ANSICPPParserExtensionConfiguration();
		parser2 = new GNUCPPSourceParser(scanner,
				ParserMode.COMPLETE_PARSE, NULL_LOG, config);
	} else {
		ICParserExtensionConfiguration config = null;
		if (useGNUExtensions)
			config = new GCCParserExtensionConfiguration();
		else
			config = new ANSICParserExtensionConfiguration();

		parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE,
				NULL_LOG, config);
	}
	
	IASTTranslationUnit tu = parser2.parse();

	if (parser2.encounteredError()) {
		for (int i = 0; i < tu.getPreprocessorProblems().length; i++)
			if (tu.getPreprocessorProblems()[i].isError())
				System.err.println("Error:"
						+ tu.getPreprocessorProblems()[i].getMessage());
	}
	
	return tu;
}

public static void main(String[] args) {
	String inputFile = "/home/xxxx/test.cpp";
	String[] incPaths = null;
	try {
		IASTTranslationUnit tu = parse(inputFile, incPaths, ParserLanguage.CPP, true, true);
		String result = tu.getRawSignature();
		result.length();
	} catch (ParserException ex) {
		ex.printStackTrace();
	}
}

tu.getRawSignature() returns empty string.

Reproducible: Always
Comment 1 Markus Schorn CLA 2011-03-09 09:41:39 EST
Created attachment 190759 [details]
fix
Comment 2 Markus Schorn CLA 2011-03-09 09:42:15 EST
Fixed in 8.0.