Java Code Examples for org.eclipse.cdt.core.dom.ast.IASTTranslationUnit

The following examples show how to use org.eclipse.cdt.core.dom.ast.IASTTranslationUnit. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: depends   Source File: CommentManager.java    License: MIT License 6 votes vote down vote up
public CommentManager(IASTTranslationUnit translationUnit) {
	this.translationUnit = translationUnit;
	comments = ((ASTTranslationUnit) translationUnit).getComments();
	joinWithNext = new boolean[comments.length];
	
	
	for (int i=1;i<comments.length;i++) {
		IASTComment previous = comments[i-1];
		int previousEnd = (previous.getFileLocation().getNodeOffset()+
				previous.getFileLocation().getNodeLength());
		IASTComment current = comments[i];
		if (current.getFileLocation().getNodeOffset()-previousEnd<5)
			joinWithNext[i-1] = true;
		else
			joinWithNext[i-1] = false;
	}
	joinWithNext[comments.length-1] = false;
}
 
Example 2
Source Project: depends   Source File: CDTParser.java    License: MIT License 5 votes vote down vote up
public IASTTranslationUnit parse(String file, Map<String, String> macroMap   ) {
	try {
		this.macroMap = macroMap;
		return getTranslationUnitofCPP(file);
	} catch (IOException e) {
	}
	return new CASTTranslationUnit();
}
 
Example 3
Source Project: depends   Source File: CDTParser.java    License: MIT License 5 votes vote down vote up
public IASTTranslationUnit getTranslationUnitofCPP(String file) throws IOException {
	
	IScanner scanner = Scanner.buildScanner(file,macroMap,sysIncludePath,false);
	if (scanner==null) return null;

	AbstractGNUSourceCodeParser sourceCodeParser = new GNUCPPSourceParser(
			scanner, ParserMode.COMPLETE_PARSE,  new NullLogService(),
			new GPPParserExtensionConfigurationExtension(), null);
	IASTTranslationUnit tu =  sourceCodeParser.parse();
	return tu;
}
 
Example 4
Source Project: depends   Source File: CdtCppFileParser.java    License: MIT License 5 votes vote down vote up
/**
 * 
 * @param isInScope whether the parse is invoked by project file or an 'indirect' included file
 * @return 
 */
public void parse(boolean isInScope,Map<String, String> macroMap) {
	/** If file already exist, skip it */
	Entity fileEntity = entityRepo.getEntity(fileFullPath);
	if (fileEntity!=null && fileEntity instanceof FileEntity) {
		FileEntity t = ((FileEntity)fileEntity);
		if (!t.isInProjectScope() && isInScope)
			t.setInProjectScope(true);
		return;
	}
	
	CppVisitor bridge = new CppVisitor(fileFullPath, entityRepo, preprocessorHandler,inferer);
	IASTTranslationUnit tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
	boolean containsIncludes = false;
	for (String incl:preprocessorHandler.getDirectIncludedFiles(tu.getAllPreprocessorStatements(),fileFullPath)) {
		CdtCppFileParser importedParser = new CdtCppFileParser(incl, entityRepo, preprocessorHandler,inferer,macroRepo);
		importedParser.parse(false,macroMap);
		Map<String, String> macros = macroRepo.get(incl);
		if (macros!=null)
			macroMap.putAll(macros);
		containsIncludes = true;
	}
	if (containsIncludes) {
		tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
	}
	macroRepo.putMacros(this.fileFullPath,macroMap,tu.getMacroDefinitions());
	tu.accept(bridge);
	fileEntity = entityRepo.getEntity(fileFullPath);
	((FileEntity)fileEntity).cacheAllExpressions();
	bridge.done();
	return;
}
 
Example 5
Source Project: api-mining   Source File: CppASTExtractor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected IASTTranslationUnit getAstForLanguage(final FileContent fc,
		final IScannerInfo si, final IncludeFileContentProvider ifcp,
		final IIndex idx, final int options, final IParserLogService log)
		throws CoreException {
	return GPPLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp,
			idx, options, log);
}
 
Example 6
Source Project: api-mining   Source File: CAstExtractor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected IASTTranslationUnit getAstForLanguage(final FileContent fc,
		final IScannerInfo si, final IncludeFileContentProvider ifcp,
		final IIndex idx, final int options, final IParserLogService log)
		throws CoreException {
	return GCCLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp,
			idx, options, log);
}
 
Example 7
/**
 * Return an AST for the following CDT-compatible code;
 * 
 * @param code
 * @return
 * @throws CoreException
 */
public final IASTTranslationUnit getAST(final char[] code,
		final String baseIncludePath) throws CoreException {
	final FileContent fc = FileContent.create(baseIncludePath, code);
	final Map<String, String> macroDefinitions = Maps.newHashMap();
	final String[] includeSearchPaths = new String[0];
	final IScannerInfo si = new ScannerInfo(macroDefinitions,
			includeSearchPaths);
	final IncludeFileContentProvider ifcp = IncludeFileContentProvider
			.getEmptyFilesProvider();
	final IIndex idx = null;
	final int options = ILanguage.OPTION_IS_SOURCE_UNIT;
	final IParserLogService log = new DefaultLogService();
	return getAstForLanguage(fc, si, ifcp, idx, options, log);
}
 
Example 8
@Override
protected IASTTranslationUnit getAstForLanguage(final FileContent fc,
		final IScannerInfo si, final IncludeFileContentProvider ifcp,
		final IIndex idx, final int options, final IParserLogService log)
		throws CoreException {
	return GPPLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp,
			idx, options, log);
}
 
Example 9
Source Project: tassal   Source File: CAstExtractor.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected IASTTranslationUnit getAstForLanguage(final FileContent fc,
		final IScannerInfo si, final IncludeFileContentProvider ifcp,
		final IIndex idx, final int options, final IParserLogService log)
		throws CoreException {
	return GCCLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp,
			idx, options, log);
}
 
Example 10
/**
 * Return an AST for the following CDT-compatible code;
 * 
 * @param code
 * @return
 * @throws CoreException
 */
public final IASTTranslationUnit getAST(final char[] code,
		final String baseIncludePath) throws CoreException {
	final FileContent fc = FileContent.create(baseIncludePath, code);
	final Map<String, String> macroDefinitions = Maps.newHashMap();
	final String[] includeSearchPaths = new String[0];
	final IScannerInfo si = new ScannerInfo(macroDefinitions,
			includeSearchPaths);
	final IncludeFileContentProvider ifcp = IncludeFileContentProvider
			.getEmptyFilesProvider();
	final IIndex idx = null;
	final int options = ILanguage.OPTION_IS_SOURCE_UNIT;
	final IParserLogService log = new DefaultLogService();
	return getAstForLanguage(fc, si, ifcp, idx, options, log);
}
 
Example 11
Source Project: cdt-proc   Source File: ProCLanguage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IASTTranslationUnit getASTTranslationUnit(FileContent reader, IScannerInfo scanInfo,
		IncludeFileContentProvider fileCreator, IIndex index, int options, IParserLogService log)
		throws CoreException {

	//final IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
	final IScanner scanner= mycreateScanner(reader, scanInfo, fileCreator, log);
	scanner.setComputeImageLocations((options & OPTION_NO_IMAGE_LOCATIONS) == 0);
	scanner.setProcessInactiveCode((options & OPTION_PARSE_INACTIVE_CODE) != 0);

	IParserSettings parserSettings= null;
	if (scanInfo instanceof ExtendedScannerInfo) {
		ExtendedScannerInfo extendedScannerInfo = (ExtendedScannerInfo) scanInfo;
		parserSettings = extendedScannerInfo.getParserSettings();
	}
	final ISourceCodeParser parser= createParser(scanner, log, index, false, options, parserSettings);

	// Make it possible to cancel parser by reconciler - http://bugs.eclipse.org/226682
	ICanceler canceler= null;
	if (log instanceof ICanceler) {
		canceler= (ICanceler) log;
		canceler.setCancelable(new ICancelable() {
			@Override
			public void cancel() {
				scanner.cancel();
				parser.cancel();
			}});
	}

	try {
		// Parse
		IASTTranslationUnit ast= parser.parse();
		ast.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0);
		return ast;
	} finally {
		if (canceler != null) {
			canceler.setCancelable(null);
		}
	}
}
 
Example 12
@Override
protected IASTTranslationUnit getAstForLanguage(final FileContent fc,
		final IScannerInfo si, final IncludeFileContentProvider ifcp,
		final IIndex idx, final int options, final IParserLogService log)
		throws CoreException {
	return GPPLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp,
			idx, options, log);
}
 
Example 13
@Override
protected IASTTranslationUnit getAstForLanguage(final FileContent fc,
		final IScannerInfo si, final IncludeFileContentProvider ifcp,
		final IIndex idx, final int options, final IParserLogService log)
		throws CoreException {
	return GCCLanguage.getDefault().getASTTranslationUnit(fc, si, ifcp,
			idx, options, log);
}
 
Example 14
/**
 * Return an AST for the following CDT-compatible code;
 * 
 * @param code
 * @return
 * @throws CoreException
 */
public final IASTTranslationUnit getAST(final char[] code,
		final String baseIncludePath) throws CoreException {
	final FileContent fc = FileContent.create(baseIncludePath, code);
	final Map<String, String> macroDefinitions = Maps.newHashMap();
	final String[] includeSearchPaths = new String[0];
	final IScannerInfo si = new ScannerInfo(macroDefinitions,
			includeSearchPaths);
	final IncludeFileContentProvider ifcp = IncludeFileContentProvider
			.getEmptyFilesProvider();
	final IIndex idx = null;
	final int options = ILanguage.OPTION_IS_SOURCE_UNIT;
	final IParserLogService log = new DefaultLogService();
	return getAstForLanguage(fc, si, ifcp, idx, options, log);
}
 
Example 15
/**
 * To be overrided for each language.
 * 
 * @param fc
 * @param si
 * @param ifcp
 * @param idx
 * @param options
 * @param log
 * @return
 * @throws CoreException
 */
protected abstract IASTTranslationUnit getAstForLanguage(FileContent fc,
		IScannerInfo si, IncludeFileContentProvider ifcp, IIndex idx,
		int options, IParserLogService log) throws CoreException;
 
Example 16
/**
 * To be overrided for each language.
 * 
 * @param fc
 * @param si
 * @param ifcp
 * @param idx
 * @param options
 * @param log
 * @return
 * @throws CoreException
 */
protected abstract IASTTranslationUnit getAstForLanguage(FileContent fc,
		IScannerInfo si, IncludeFileContentProvider ifcp, IIndex idx,
		int options, IParserLogService log) throws CoreException;
 
Example 17
/**
 * To be overrided for each language.
 * 
 * @param fc
 * @param si
 * @param ifcp
 * @param idx
 * @param options
 * @param log
 * @return
 * @throws CoreException
 */
protected abstract IASTTranslationUnit getAstForLanguage(FileContent fc,
		IScannerInfo si, IncludeFileContentProvider ifcp, IIndex idx,
		int options, IParserLogService log) throws CoreException;