Java Code Examples for org.eclipse.cdt.core.parser.IScannerInfo

The following examples show how to use org.eclipse.cdt.core.parser.IScannerInfo. 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: cdt-proc   Source File: ProCLanguage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected IScanner mycreateScanner(
		FileContent content, IScannerInfo scanInfo, IncludeFileContentProvider fcp, IParserLogService log) {
	/*
	 * gccのプロジェクト設定(include path,マクロ定義etc)を元に
	 * ScannerInfoを作成してProCPreprocessorに渡す
	 */
	String afile = content.getFileLocation();
	IResource res = ParserUtil.getResourceForFilename(afile);
	if (res != null) {
		scanInfo =
			LanguageSettingsScannerInfoProvider.getScannerInformation(
					res, new String[]{"org.eclipse.cdt.core.gcc"});
	}
	return new ProCPreprocessor(
			content, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(scanInfo), fcp);
}
 
Example 2
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 3
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 4
/**
 * 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 5
@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: 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 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
Source Project: cdt-proc   Source File: ProCPreprocessor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public ProCPreprocessor(FileContent fileContent, IScannerInfo info,
		ParserLanguage language, IParserLogService log,
		IScannerExtensionConfiguration configuration,
		IncludeFileContentProvider readerFactory) {

	super(fileContent, info, language, log, configuration, readerFactory);

	addProCHeaderReplaces();
	addProCKeywords();
}
 
Example 9
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 10
@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 11
@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 12
/**
 * 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 13
Source Project: depends   Source File: Scanner.java    License: MIT License 4 votes vote down vote up
/**
 * Build a scanner used for parser
 * @param file -- the scanned source file
 * @param macroMap -- the macro maps
 * @param sysIncludePath -- the included paths 
 * @param shouldScanInclusionFiles -- whether to scan the included files
 * @return the scanner
 */
public static IScanner buildScanner(String file, Map<String, String> macroMap, List<String> sysIncludePath, boolean shouldScanInclusionFiles) {
	String content = "";
	try {
		CodeReader cr = new CodeReader(file);
		content = new String(cr.buffer);
	} catch (IOException e) {
	}
	IScannerInfo scannerInfo = new ScannerInfo(macroMap, sysIncludePath.toArray(new String[] {}));
	IScannerExtensionConfiguration configuration = GPPScannerExtensionConfiguration.getInstance(scannerInfo);
	InternalFileContentProvider ifcp = new InternalFileContentProvider() {
		@Override
		public InternalFileContent getContentForInclusion(String filePath, IMacroDictionary macroDictionary) {
			InternalFileContent ifc = null;
			if (!shouldScanInclusionFiles) {
				ifc =  new InternalFileContent(filePath, InclusionKind.SKIP_FILE); 
			}else {
				ifc = FileCache.getInstance().get(filePath);
			}
			if (ifc == null) {
				ifc = (InternalFileContent) FileContent.createForExternalFileLocation(filePath);
				FileCache.getInstance().put(filePath, ifc);
			}

			return ifc;
		}

		@Override
		public InternalFileContent getContentForInclusion(IIndexFileLocation ifl, String astPath) {
			InternalFileContent c = FileCache.getInstance().get(ifl);
			if (c == null) {
				c = (InternalFileContent) FileContent.create(ifl);
				FileCache.getInstance().put(ifl, c);
			}
			return c;
		}
	};
	ParserLanguage lang = ParserLanguage.CPP;
	if (file.endsWith(".c"))
		lang = ParserLanguage.C;
	IScanner scanner = new CPreprocessor(FileContent.create(file, content.toCharArray()), scannerInfo, lang,
			new NullLogService(), configuration, IncludeFileContentProvider.getEmptyFilesProvider());
	scanner.setProcessInactiveCode(true);
	return scanner;
}
 
Example 14
public static ProCScannerExtensionConfiguration getInstance(IScannerInfo info) {
	return getInstance();
}
 
Example 15
Source Project: cdt-proc   Source File: ProCLanguage.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected IScannerExtensionConfiguration getScannerExtensionConfiguration(IScannerInfo info) {
	return ProCScannerExtensionConfiguration.getInstance(info);
}
 
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;
 
Example 18
/**
 * 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;