From e6baa5b577c4df7d1878235621b4c365d53a0fd0 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 25 Jun 2008 11:55:36 +0000 Subject: [PATCH] Support for @ in identifiers, bug 237028. --- .../core/parser/tests/ast2/AST2BaseTest.java | 4 +- .../tests/scanner/ExpansionExplorerTests.java | 2 +- .../core/parser/tests/scanner/LexerTests.java | 2 +- .../tests/scanner/PreprocessorSpeedTest.java | 6 +- .../tests/scanner/PreprocessorTestsBase.java | 4 +- .../cdt/core/dom/ast/gnu/c/GCCLanguage.java | 18 ++- .../cdt/core/dom/ast/gnu/cpp/GPPLanguage.java | 17 ++- ...AbstractScannerExtensionConfiguration.java | 124 ++++++++++++----- .../GNUScannerExtensionConfiguration.java | 126 ++++++++++-------- .../IScannerExtensionConfiguration.java | 24 ++-- ...AbstractCParserExtensionConfiguration.java | 18 +-- .../c/GCCParserExtensionConfiguration.java | 14 +- .../c/GCCScannerExtensionConfiguration.java | 42 ++---- .../c/ICParserExtensionConfiguration.java | 51 ++++--- ...stractCPPParserExtensionConfiguration.java | 19 +-- .../cpp/GPPParserExtensionConfiguration.java | 14 +- .../cpp/GPPScannerExtensionConfiguration.java | 30 ++--- .../cpp/ICPPParserExtensionConfiguration.java | 61 ++++----- .../POPCPPParserExtensionConfiguration.java | 28 ++++ .../POPCPPScannerExtensionConfiguration.java | 39 ++++++ .../parser/AbstractGNUSourceCodeParser.java | 22 ++- .../core/dom/parser/c/GNUCSourceParser.java | 36 ++--- .../dom/parser/cpp/GNUCPPSourceParser.java | 42 +++--- .../core/parser/scanner/CPreprocessor.java | 3 +- .../internal/core/parser/scanner/Lexer.java | 17 ++- .../core/dom/InternalASTServiceProvider.java | 4 +- .../ScannerExtensionConfiguration.java | 11 +- 27 files changed, 476 insertions(+), 302 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPScannerExtensionConfiguration.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index c39f444d8b7..bd330870184 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -165,9 +165,9 @@ public class AST2BaseTest extends BaseTestCase { IScannerInfo scannerInfo, boolean parseComments) { IScannerExtensionConfiguration configuration = null; if( lang == ParserLanguage.C ) - configuration = new GCCScannerExtensionConfiguration(); + configuration= GCCScannerExtensionConfiguration.getInstance(); else - configuration = new GPPScannerExtensionConfiguration(); + configuration= GPPScannerExtensionConfiguration.getInstance(); IScanner scanner; scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, FileCodeReaderFactory.getInstance()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/ExpansionExplorerTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/ExpansionExplorerTests.java index 25a81be249c..f47e241bc85 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/ExpansionExplorerTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/ExpansionExplorerTests.java @@ -85,7 +85,7 @@ public class ExpansionExplorerTests extends BaseTestCase { private MacroExpander createExpander(final String macrodefs) throws OffsetLimitReachedException { CPreprocessor cpp= new CPreprocessor(new CodeReader(macrodefs.toCharArray()), new ScannerInfo(), ParserLanguage.C, new NullLogService(), - new GCCScannerExtensionConfiguration(), NullCodeReaderFactory.getInstance()); + GCCScannerExtensionConfiguration.getInstance(), NullCodeReaderFactory.getInstance()); int type; do { type= cpp.nextTokenRaw().getType(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java index 4852ae633a3..182af970e23 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/LexerTests.java @@ -53,7 +53,7 @@ public class LexerTests extends BaseTestCase { private void init(String input, boolean dollar, boolean minmax) throws Exception { fLog.clear(); final LexerOptions lexerOptions = new LexerOptions(); - lexerOptions.fSupportDollarInitializers= dollar; + lexerOptions.fSupportDollarInIdentifiers= dollar; lexerOptions.fSupportMinAndMax= minmax; fLexer= new Lexer(input.toCharArray(), lexerOptions, fLog, null); fLexer.nextToken(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java index 6ffdaa012f6..a8e953d7fe1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -80,10 +80,10 @@ public class PreprocessorSpeedTest { ICodeReaderFactory readerFactory= FileCodeReaderFactory.getInstance(); IScannerExtensionConfiguration scannerConfig; if (lang == ParserLanguage.C) { - scannerConfig= new GCCScannerExtensionConfiguration(); + scannerConfig= GCCScannerExtensionConfiguration.getInstance(); } else { - scannerConfig= new GPPScannerExtensionConfiguration(); + scannerConfig= GPPScannerExtensionConfiguration.getInstance(); } ParserMode mode = ParserMode.COMPLETE_PARSE; CPreprocessor cpp= new CPreprocessor(reader, info, lang, new NullLogService(), scannerConfig, readerFactory); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java index 834b537cdde..8b36ddb7c21 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java @@ -67,10 +67,10 @@ public abstract class PreprocessorTestsBase extends BaseTestCase { IScannerExtensionConfiguration scannerConfig; if (lang == ParserLanguage.C) { - scannerConfig= new GCCScannerExtensionConfiguration(); + scannerConfig= GCCScannerExtensionConfiguration.getInstance(); } else { - scannerConfig= new GPPScannerExtensionConfiguration(); + scannerConfig= GPPScannerExtensionConfiguration.getInstance(); } fScanner= new CPreprocessor(input, scannerInfo, lang, NULL_LOG, scannerConfig, readerFactory); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java index cc7b7cffd0e..4a6046fa6fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems and others. + * Copyright (c) 2005, 2008 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,7 +12,6 @@ * Anton Leherbauer (Wind River Systems) * Mike Kucera - IBM *******************************************************************************/ - package org.eclipse.cdt.core.dom.ast.gnu.c; import org.eclipse.cdt.core.CCorePlugin; @@ -22,6 +21,7 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -37,8 +37,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory; */ public class GCCLanguage extends AbstractCLikeLanguage { - protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration(); - protected static final GCCParserExtensionConfiguration C_GNU_PARSER_EXTENSION = new GCCParserExtensionConfiguration(); + protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION= GCCScannerExtensionConfiguration.getInstance(); + protected static final GCCParserExtensionConfiguration C_GNU_PARSER_EXTENSION= GCCParserExtensionConfiguration.getInstance(); // Must match the id in the extension public static final String ID = CCorePlugin.PLUGIN_ID + ".gcc"; //$NON-NLS-1$ @@ -73,13 +73,19 @@ public class GCCLanguage extends AbstractCLikeLanguage { return C_GNU_SCANNER_EXTENSION; } + /** + * Returns the extension configuration used for creating the parser. + * @since 5.1 + */ + protected ICParserExtensionConfiguration getParserExtensionConfiguration() { + return C_GNU_PARSER_EXTENSION; + } @Override protected ISourceCodeParser createParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, IIndex index) { - return new GNUCSourceParser(scanner, parserMode, logService, C_GNU_PARSER_EXTENSION, index); + return new GNUCSourceParser(scanner, parserMode, logService, getParserExtensionConfiguration(), index); } - @Override protected ParserLanguage getParserLanguage() { return ParserLanguage.C; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java index 9bb52e90ab9..db3d66216c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems and others. + * Copyright (c) 2005, 2008 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -36,8 +37,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory; */ public class GPPLanguage extends AbstractCLikeLanguage { - protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration(); - protected static final GPPParserExtensionConfiguration CPP_GNU_PARSER_EXTENSION = new GPPParserExtensionConfiguration(); + protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION= GPPScannerExtensionConfiguration.getInstance(); + protected static final GPPParserExtensionConfiguration CPP_GNU_PARSER_EXTENSION= GPPParserExtensionConfiguration.getInstance(); public static final String ID = CCorePlugin.PLUGIN_ID + ".g++"; //$NON-NLS-1$ private static final GPPLanguage DEFAULT_INSTANCE = new GPPLanguage(); @@ -70,9 +71,17 @@ public class GPPLanguage extends AbstractCLikeLanguage { return CPP_GNU_SCANNER_EXTENSION; } + /** + * Returns the extension configuration used for creating the parser. + * @since 5.1 + */ + protected ICPPParserExtensionConfiguration getParserExtensionConfiguration() { + return CPP_GNU_PARSER_EXTENSION; + } + @Override protected ISourceCodeParser createParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, IIndex index) { - return new GNUCPPSourceParser(scanner, parserMode, logService, CPP_GNU_PARSER_EXTENSION, index); + return new GNUCPPSourceParser(scanner, parserMode, logService, getParserExtensionConfiguration(), index); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java index 1c9500711d5..2056e23c943 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java @@ -11,22 +11,23 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.parser; +import java.util.ArrayList; + import org.eclipse.cdt.core.parser.IMacro; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; /** * Abstract scanner extension configuration to help model C/C++ dialects. - * - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

- * * @since 4.0 */ public abstract class AbstractScannerExtensionConfiguration implements IScannerExtensionConfiguration { + private static final IMacro[] EMPTY_MACRO_ARRAY = new IMacro[0]; + private ArrayList fAddMacroList; + private IMacro[] fAddMacros; + private CharArrayIntMap fAddKeywords; + private CharArrayIntMap fAddPreprocessorKeywords; + protected static class MacroDefinition implements IMacro { private char[] fSignature; private char[] fExpansion; @@ -44,14 +45,9 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE } } - /** - * @deprecated see {@link IScannerExtensionConfiguration#initializeMacroValuesTo1()} - */ - @Deprecated - public boolean initializeMacroValuesTo1() { - return false; + public AbstractScannerExtensionConfiguration() { } - + /* * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#support$InIdentifiers() */ @@ -59,6 +55,14 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE return false; } + /** + * {@inheritDoc} + * @since 5.1 + */ + public boolean supportAtSignInIdentifiers() { + return false; + } + /* * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#supportAdditionalNumericLiteralSuffixes() */ @@ -73,41 +77,82 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#getAdditionalKeywords() - */ - public CharArrayIntMap getAdditionalKeywords() { - return null; + public CharArrayIntMap getAdditionalPreprocessorKeywords() { + return fAddPreprocessorKeywords; + } + + public CharArrayIntMap getAdditionalKeywords() { + return fAddKeywords; } - public IMacro[] getAdditionalMacros() { - return null; - } - - /* - * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#getAdditionalPreprocessorKeywords() - */ - public CharArrayIntMap getAdditionalPreprocessorKeywords() { - return null; + if (fAddMacros == null) { + if (fAddMacroList == null) { + fAddMacros= EMPTY_MACRO_ARRAY; + } else { + fAddMacros= fAddMacroList.toArray(new IMacro[fAddMacroList.size()]); + } + } + return fAddMacros; } /** - * Helper method to add an object style macro to the given map. + * Adds a macro to the list of additional macros. + * The macro can either be of object- or of function-style. + *
+	 * Example:
+	 *    addMacro("max(a,b)", "(((a)>(b) ? (a) : (b))");
+	 * 
* @param signature the signature of the macro, see {@link IMacro#getSignature()}. * @param value the macro value + * @since 5.1 */ + protected void addMacro(String signature, String value) { + if (fAddMacroList == null) { + fAddMacroList= new ArrayList(); + } + fAddMacroList.add(new MacroDefinition(signature.toCharArray(), value.toCharArray())); + fAddMacros= null; + } + + /** + * Adds a preprocessor keyword to the map of additional preprocessor keywords. + * @param name the name of the keyword + * @param tokenKind the kind of token the keyword is mapped to. See {@link IToken}. + * @since 5.1 + */ + protected void addPreprocessorKeyword(char[] name, int tokenKind) { + if (fAddPreprocessorKeywords == null) { + fAddPreprocessorKeywords= new CharArrayIntMap(10, -1); + } + fAddPreprocessorKeywords.put(name, tokenKind); + } + + /** + * Adds a keyword to the map of additional keywords. + * @param name the name of the keyword + * @param tokenKind the kind of token the keyword is mapped to. See {@link IToken}. + * @since 5.1 + */ + protected void addKeyword(char[] name, int tokenKind) { + if (fAddKeywords == null) { + fAddKeywords= new CharArrayIntMap(10, -1); + } + fAddKeywords.put(name, tokenKind); + } + + /** + * @deprecated use {@link #addMacro(String, String)} + */ + @Deprecated protected static IMacro createMacro(String signature, String value) { return new MacroDefinition(signature.toCharArray(), value.toCharArray()); } /** - * Helper method to add a function style macro to the given map. - * - * @param name the macro name - * @param value the macro value - * @param arguments the macro arguments + * @deprecated use {@link #addMacro(String, String)} */ + @Deprecated protected static IMacro createFunctionStyleMacro(String name, String value, String[] arguments) { StringBuffer buf= new StringBuffer(); buf.append(name); @@ -123,4 +168,13 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE buf.getChars(0, signature.length, signature, 0); return new MacroDefinition(signature, value.toCharArray()); } + + /** + * @deprecated see {@link IScannerExtensionConfiguration#initializeMacroValuesTo1()} + */ + @Deprecated + public boolean initializeMacroValuesTo1() { + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java index a93316e84a8..0c0973acafc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java @@ -21,47 +21,52 @@ import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; /** - * @author jcamelon + * Base class for all gnu scanner configurations. Provides gnu-specific macros and keywords. + * @since 5.0 */ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration { - - private static IMacro[] sAdditionalMacros= new IMacro[] { - createMacro("__complex__", "_Complex"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__extension__", ""), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__imag__", "(int)"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__null", "(void *)0"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__real__", "(int)"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__stdcall", ""), //$NON-NLS-1$ //$NON-NLS-2$ - - createMacro("__builtin_va_arg(ap,type)", "*(type *)ap"), //$NON-NLS-1$//$NON-NLS-2$ - createMacro("__builtin_constant_p(exp)", "0") //$NON-NLS-1$//$NON-NLS-2$ - }; - - public static IMacro[] getAdditionalGNUMacros() { - return sAdditionalMacros; - } + private static GNUScannerExtensionConfiguration sInstance; - public static void addAdditionalGNUKeywords(CharArrayIntMap target) { - target.put(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); - target.put(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); - target.put(GCCKeywords.cp__ASM, IToken.t_asm); - target.put(GCCKeywords.cp__ASM__, IToken.t_asm); - target.put(GCCKeywords.cp__ATTRIBUTE, IGCCToken.t__attribute__ ); - target.put(GCCKeywords.cp__ATTRIBUTE__, IGCCToken.t__attribute__ ); - target.put(GCCKeywords.cp__CONST, IToken.t_const); - target.put(GCCKeywords.cp__CONST__, IToken.t_const); - target.put(GCCKeywords.cp__DECLSPEC, IGCCToken.t__declspec ); - target.put(GCCKeywords.cp__INLINE, IToken.t_inline); - target.put(GCCKeywords.cp__INLINE__, IToken.t_inline); - target.put(GCCKeywords.cp__RESTRICT, IToken.t_restrict); - target.put(GCCKeywords.cp__RESTRICT__, IToken.t_restrict); - target.put(GCCKeywords.cp__VOLATILE, IToken.t_volatile); - target.put(GCCKeywords.cp__VOLATILE__, IToken.t_volatile); - target.put(GCCKeywords.cp__SIGNED, IToken.t_signed); - target.put(GCCKeywords.cp__SIGNED__, IToken.t_signed); - target.put(GCCKeywords.cp__TYPEOF, IGCCToken.t_typeof); - target.put(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof); - target.put(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof ); + @SuppressWarnings("nls") + public GNUScannerExtensionConfiguration() { + addMacro("__complex__", "_Complex"); + addMacro("__extension__", ""); + addMacro("__imag__", "(int)"); + addMacro("__null", "(void *)0"); + addMacro("__real__", "(int)"); + addMacro("__stdcall", ""); + + addMacro("__builtin_va_arg(ap,type)", "*(type *)ap"); + addMacro("__builtin_constant_p(exp)", "0"); + + addPreprocessorKeyword(Keywords.cINCLUDE_NEXT, IPreprocessorDirective.ppInclude_next); + addPreprocessorKeyword(Keywords.cIMPORT, IPreprocessorDirective.ppImport); + addPreprocessorKeyword(Keywords.cWARNING, IPreprocessorDirective.ppWarning); + addPreprocessorKeyword(Keywords.cIDENT, IPreprocessorDirective.ppIgnore); + addPreprocessorKeyword(Keywords.cSCCS, IPreprocessorDirective.ppIgnore); + addPreprocessorKeyword(Keywords.cASSERT, IPreprocessorDirective.ppIgnore); + addPreprocessorKeyword(Keywords.cUNASSERT, IPreprocessorDirective.ppIgnore); + + addKeyword(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); + addKeyword(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); + addKeyword(GCCKeywords.cp__ASM, IToken.t_asm); + addKeyword(GCCKeywords.cp__ASM__, IToken.t_asm); + addKeyword(GCCKeywords.cp__ATTRIBUTE, IGCCToken.t__attribute__ ); + addKeyword(GCCKeywords.cp__ATTRIBUTE__, IGCCToken.t__attribute__ ); + addKeyword(GCCKeywords.cp__CONST, IToken.t_const); + addKeyword(GCCKeywords.cp__CONST__, IToken.t_const); + addKeyword(GCCKeywords.cp__DECLSPEC, IGCCToken.t__declspec ); + addKeyword(GCCKeywords.cp__INLINE, IToken.t_inline); + addKeyword(GCCKeywords.cp__INLINE__, IToken.t_inline); + addKeyword(GCCKeywords.cp__RESTRICT, IToken.t_restrict); + addKeyword(GCCKeywords.cp__RESTRICT__, IToken.t_restrict); + addKeyword(GCCKeywords.cp__VOLATILE, IToken.t_volatile); + addKeyword(GCCKeywords.cp__VOLATILE__, IToken.t_volatile); + addKeyword(GCCKeywords.cp__SIGNED, IToken.t_signed); + addKeyword(GCCKeywords.cp__SIGNED__, IToken.t_signed); + addKeyword(GCCKeywords.cp__TYPEOF, IGCCToken.t_typeof); + addKeyword(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof); + addKeyword(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof ); } @Override @@ -73,25 +78,28 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx public char[] supportAdditionalNumericLiteralSuffixes() { return "ij".toCharArray(); //$NON-NLS-1$ } - - @Override - public IMacro[] getAdditionalMacros() { - return sAdditionalMacros; - } - - /* - * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#getAdditionalPreprocessorKeywords() - */ - @Override - public CharArrayIntMap getAdditionalPreprocessorKeywords() { - CharArrayIntMap additionalPPKeywords= new CharArrayIntMap(8, IPreprocessorDirective.ppInvalid); - additionalPPKeywords.put(Keywords.cINCLUDE_NEXT, IPreprocessorDirective.ppInclude_next); - additionalPPKeywords.put(Keywords.cIMPORT, IPreprocessorDirective.ppImport); - additionalPPKeywords.put(Keywords.cWARNING, IPreprocessorDirective.ppWarning); - additionalPPKeywords.put(Keywords.cIDENT, IPreprocessorDirective.ppIgnore); - additionalPPKeywords.put(Keywords.cSCCS, IPreprocessorDirective.ppIgnore); - additionalPPKeywords.put(Keywords.cASSERT, IPreprocessorDirective.ppIgnore); - additionalPPKeywords.put(Keywords.cUNASSERT, IPreprocessorDirective.ppIgnore); - return additionalPPKeywords; - } + + /** + * @deprecated simply derive from this class and use {@link #addMacro(String, String)} to + * add additional macros. + */ + @Deprecated + public static IMacro[] getAdditionalGNUMacros() { + if (sInstance == null) { + sInstance= new GNUScannerExtensionConfiguration() {}; + } + return sInstance.getAdditionalMacros(); + } + + /** + * @deprecated simply derive from this class and use {@link #addKeyword(char[], int)} to + * add additional keywords. + */ + @Deprecated + public static void addAdditionalGNUKeywords(CharArrayIntMap target) { + if (sInstance == null) { + sInstance= new GNUScannerExtensionConfiguration() {}; + } + target.putAll(sInstance.getAdditionalKeywords()); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java index cb6d91de4bd..c1fa5024e59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java @@ -18,19 +18,9 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; /** * Scanner extension configuration interface. - * - *

- * This interface is not intended to be implemented directly. Clients should - * subclass {@link AbstractScannerExtensionConfiguration} instead. - *

- *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

- * - * @author jcamelon + * + * @noimplement This interface is not intended to be implemented by clients. Clients can subclass + * {@link AbstractScannerExtensionConfiguration}, instead. */ public interface IScannerExtensionConfiguration { @@ -50,6 +40,14 @@ public interface IScannerExtensionConfiguration { */ public boolean support$InIdentifiers(); + /** + * Support for extension "At Signs in Identifier Names". If enabled, the '@' sign is treated as part of + * identifiers. + * @return true, if @ should be supported in identifiers + * @since 5.1 + */ + public boolean supportAtSignInIdentifiers(); + /** * Support for (deprecated) GNU minimum and maximum operators (<? * and >?). diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java index dc04f787875..42d1d3819b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.c; @@ -17,14 +18,6 @@ import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; /** * Abstract C parser extension configuration to help model C dialects. - * - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

- * * @since 4.0 */ public abstract class AbstractCParserExtensionConfiguration implements ICParserExtensionConfiguration { @@ -95,4 +88,11 @@ public abstract class AbstractCParserExtensionConfiguration implements ICParserE return null; } + /** + * {@inheritDoc} + * @since 5.1 + */ + public boolean supportParameterInfoBlock() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java index f08db291398..5df338d2a0b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.c; @@ -16,9 +17,16 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; /** - * @author jcamelon + * Configures the parser for c-source code as accepted by gcc. */ public class GCCParserExtensionConfiguration extends AbstractCParserExtensionConfiguration { + private static GCCParserExtensionConfiguration sInstance= new GCCParserExtensionConfiguration(); + /** + * @since 5.1 + */ + public static GCCParserExtensionConfiguration getInstance() { + return sInstance; + } /* * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportStatementsInExpressions() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java index 5fb3e258dbc..57de27534cd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java @@ -13,24 +13,22 @@ package org.eclipse.cdt.core.dom.parser.c; import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration; -import org.eclipse.cdt.core.parser.IMacro; -import org.eclipse.cdt.core.parser.util.CharArrayIntMap; /** - * @author jcamelon + * Configures the preprocessor for parsing c-sources as accepted by gcc. */ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { - private static IMacro[] sAdditionalMacros; - private static CharArrayIntMap sAdditionalKeywords; - static { - final IMacro[] macros = GNUScannerExtensionConfiguration.getAdditionalGNUMacros(); - sAdditionalMacros= new IMacro[macros.length+1]; - System.arraycopy(macros, 0, sAdditionalMacros, 0, macros.length); - sAdditionalMacros[macros.length]= createMacro("_Pragma(arg)", ""); //$NON-NLS-1$//$NON-NLS-2$ - - sAdditionalKeywords= new CharArrayIntMap(10, -1); - GNUScannerExtensionConfiguration.addAdditionalGNUKeywords(sAdditionalKeywords); + private static GCCScannerExtensionConfiguration sInstance= new GCCScannerExtensionConfiguration(); + /** + * @since 5.1 + */ + public static GCCScannerExtensionConfiguration getInstance() { + return sInstance; + } + + public GCCScannerExtensionConfiguration() { + addMacro("_Pragma(arg)", ""); //$NON-NLS-1$//$NON-NLS-2$ } /* (non-Javadoc) @@ -40,22 +38,4 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu public boolean supportMinAndMaxOperators() { return false; } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros() - */ - @Override - public IMacro[] getAdditionalMacros() { - return sAdditionalMacros; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalKeywords() - */ - @Override - public CharArrayIntMap getAdditionalKeywords() { - return sAdditionalKeywords; - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java index b5de8aa47bd..52a6109ad1f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java @@ -6,9 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) - * Anton Leherbauer (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.c; @@ -17,20 +18,10 @@ import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; /** * C parser extension configuration interface. * - *

- * This interface is not intended to be implemented directly. Clients should - * subclass {@link AbstractCParserExtensionConfiguration} instead. - *

- *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

+ * @noimplement This interface is not intended to be implemented by clients. + * Clients can subclass {@link AbstractCParserExtensionConfiguration} instead. * * @see "http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html" - * - * @author jcamelon * @since 4.0 */ public interface ICParserExtensionConfiguration { @@ -78,17 +69,6 @@ public interface ICParserExtensionConfiguration { */ public boolean supportKnRC(); - /** - * See http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for more - * information on GCC's Other Built-in Symbols. - * - * @return true if support for the extension should be - * enabled - * @deprecated use {@link #getBuiltinBindingsProvider()} instead. - */ - @Deprecated - public boolean supportGCCOtherBuiltinSymbols(); - /** * See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html for more * information on GCC's Attribute Specifiers. @@ -113,4 +93,23 @@ public interface ICParserExtensionConfiguration { * null */ public IBuiltinBindingsProvider getBuiltinBindingsProvider(); + + /** + * Skips information in brackets provided at the beginning of a parameter declaration: + *
+ * void accelerate([proc=marsh] const Speed &data); + * @since 5.1 + */ + public boolean supportParameterInfoBlock(); + + /** + * See http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for more + * information on GCC's Other Built-in Symbols. + * + * @return true if support for the extension should be + * enabled + * @deprecated use {@link #getBuiltinBindingsProvider()} instead. + */ + @Deprecated + public boolean supportGCCOtherBuiltinSymbols(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java index 5bd847a0f25..e0f5baa02e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.cpp; @@ -19,13 +20,6 @@ import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; /** * Abstract C++ parser extension configuration to help model C++ dialects. * - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

- * * @since 4.0 */ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPParserExtensionConfiguration { @@ -121,6 +115,14 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar return false; } + /** + * {@inheritDoc} + * @since 5.1 + */ + public boolean supportParameterInfoBlock() { + return false; + } + /* * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider() */ @@ -130,5 +132,4 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar } return null; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java index 799ed3c9694..80441e92c9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.cpp; @@ -16,9 +17,16 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; /** - * @author jcamelon + * Configures the parser for c++-sources as accepted by g++. */ public class GPPParserExtensionConfiguration extends AbstractCPPParserExtensionConfiguration { + private static GPPParserExtensionConfiguration sInstance= new GPPParserExtensionConfiguration(); + /** + * @since 5.1 + */ + public static GPPParserExtensionConfiguration getInstance() { + return sInstance; + } /* * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#allowRestrictPointerOperators() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java index 9eabc9da3c8..7fed446553f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java @@ -16,20 +16,24 @@ package org.eclipse.cdt.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.Keywords; -import org.eclipse.cdt.core.parser.util.CharArrayIntMap; /** - * @author jcamelon + * Configures the preprocessor for c++-sources as accepted by g++. */ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { - private static CharArrayIntMap sAdditionalKeywords; - static { - sAdditionalKeywords= new CharArrayIntMap(10, -1); - GNUScannerExtensionConfiguration.addAdditionalGNUKeywords(sAdditionalKeywords); - sAdditionalKeywords.put( Keywords.cRESTRICT, IToken.t_restrict ); - sAdditionalKeywords.put( Keywords.c_COMPLEX, IToken.t__Complex ); - sAdditionalKeywords.put( Keywords.c_IMAGINARY, IToken.t__Imaginary ); + private static GPPScannerExtensionConfiguration sInstance= new GPPScannerExtensionConfiguration(); + /** + * @since 5.1 + */ + public static GPPScannerExtensionConfiguration getInstance() { + return sInstance; + } + + public GPPScannerExtensionConfiguration() { + addKeyword(Keywords.cRESTRICT, IToken.t_restrict); + addKeyword(Keywords.c_COMPLEX, IToken.t__Complex); + addKeyword(Keywords.c_IMAGINARY, IToken.t__Imaginary); } /* (non-Javadoc) @@ -39,12 +43,4 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu public boolean supportMinAndMaxOperators() { return true; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalKeywords() - */ - @Override - public CharArrayIntMap getAdditionalKeywords() { - return sAdditionalKeywords; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java index c9a105af324..917ddc16351 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java @@ -6,9 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) - * Anton Leherbauer (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.cpp; @@ -18,21 +19,11 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; /** * C++ parser extension configuration interface. * - *

- * This interface is not intended to be implemented directly. Clients should - * subclass {@link AbstractCPPParserExtensionConfiguration} instead. - *

- *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

+ * @noimplement This interface is not intended to be implemented by clients. + * Clients can subclass {@link AbstractCPPParserExtensionConfiguration} instead. * * @see "http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html" * @see "http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Extensions.html" - * - * @author jcamelon * @since 4.0 */ public interface ICPPParserExtensionConfiguration { @@ -76,16 +67,6 @@ public interface ICPPParserExtensionConfiguration { */ public boolean supportComplexNumbers(); - /** - * Support for the GNU __restrict__ keyword. - * - * @return true if support for the extension should be - * enabled - * @deprecated configure extra keywords, via {@link IScannerExtensionConfiguration#getAdditionalKeywords()} - */ - @Deprecated - public boolean supportRestrictKeyword(); - /** * Support for GNU long long types. * @@ -129,16 +110,6 @@ public interface ICPPParserExtensionConfiguration { */ public boolean supportKnRC(); - /** - * See http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for more - * information on GCC's Other Built-in Symbols. - * - * @return true if support for the extension should be enabled - * @deprecated use {@link #getBuiltinBindingsProvider()} instead. - */ - @Deprecated - public boolean supportGCCOtherBuiltinSymbols(); - /** * See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html for more * information on GCC's Attribute Specifiers. @@ -163,4 +134,24 @@ public interface ICPPParserExtensionConfiguration { * null */ public IBuiltinBindingsProvider getBuiltinBindingsProvider(); + + /** + * Skips information in brackets provided at the beginning of a parameter declaration: + *
+ * void accelerate([proc=marsh] const Speed &data); + * @since 5.1 + */ + public boolean supportParameterInfoBlock(); + + /** + * @deprecated configure extra keywords, via {@link IScannerExtensionConfiguration#getAdditionalKeywords()} + */ + @Deprecated + public boolean supportRestrictKeyword(); + + /** + * @deprecated use {@link #getBuiltinBindingsProvider()} instead. + */ + @Deprecated + public boolean supportGCCOtherBuiltinSymbols(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..840331fe2d8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPParserExtensionConfiguration.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +/** + * Configures the parser to accept POP C++, + * see Documentation + * @since 5.1 + */ +public class POPCPPParserExtensionConfiguration extends GPPParserExtensionConfiguration { + private static POPCPPParserExtensionConfiguration sInstance= new POPCPPParserExtensionConfiguration(); + public static POPCPPParserExtensionConfiguration getInstance() { + return sInstance; + } + + @Override + public boolean supportParameterInfoBlock() { + return true; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPScannerExtensionConfiguration.java new file mode 100644 index 00000000000..370a7fc7dde --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/POPCPPScannerExtensionConfiguration.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +import org.eclipse.cdt.core.parser.IToken; + +/** + * Configures the preprocessor for parsing POP C++, + * see Documentation + * @since 5.1 + */ +public class POPCPPScannerExtensionConfiguration extends GPPScannerExtensionConfiguration { + private static POPCPPScannerExtensionConfiguration sInstance= new POPCPPScannerExtensionConfiguration(); + public static POPCPPScannerExtensionConfiguration getInstance() { + return sInstance; + } + @SuppressWarnings("nls") + protected POPCPPScannerExtensionConfiguration() { + addMacro("@pack(...)", ""); + addMacro("__concat__(x,y)", "x##y"); + addMacro("__xconcat__(x,y)", "__concat__(x,y)"); + addMacro("@", "; void __xconcat__(@, __LINE__)()"); + + addKeyword("parclass".toCharArray(), IToken.t_class); + } + + @Override + public boolean supportAtSignInIdentifiers() { + return true; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 9d472e19119..e3d6be83577 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -92,6 +92,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final boolean supportKnRC; protected final boolean supportAttributeSpecifiers; protected final boolean supportDeclspecSpecifiers; + protected boolean supportParameterInfoBlock; protected final IBuiltinBindingsProvider builtinBindingsProvider; /** @@ -124,7 +125,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { this.supportDeclspecSpecifiers = supportDeclspecSpecifiers; this.builtinBindingsProvider= builtinBindingsProvider; } - + private AbstractParserLogService wrapLogService(IParserLogService logService) { if (logService instanceof AbstractParserLogService) { return (AbstractParserLogService) logService; @@ -2188,4 +2189,23 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return false; } } + + protected void skipBrackets(int left, int right) throws EndOfFileException, BacktrackException { + consume(left); + int nesting= 0; + while(true) { + final int lt1= LT(1); + if (lt1 == IToken.tEOC) + throwBacktrack(LA(1)); + + consume(); + if (lt1 == left) { + nesting++; + } else if (lt1 == right) { + if (--nesting < 0) { + return; + } + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 92b3ef61357..90aca7d97f7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -146,6 +146,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { config.supportDeclspecSpecifiers(), config.getBuiltinBindingsProvider()); supportGCCStyleDesignators = config.supportGCCStyleDesignators(); + supportParameterInfoBlock= config.supportParameterInfoBlock(); this.index= index; } @@ -434,22 +435,24 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { endOffset= figureEndOffset(declSpec, declarators); break; default: - insertSemi= true; - if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { - if (markBeforDtor != null) { - backup(markBeforDtor); + if (declOption != DeclarationOptions.LOCAL) { + insertSemi= true; + if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { + if (markBeforDtor != null) { + backup(markBeforDtor); + } + declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + endOffset= calculateEndOffset(declSpec); + break; + } + endOffset= figureEndOffset(declSpec, declarators); + if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { + break; + } + if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { + break; } - declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - endOffset= calculateEndOffset(declSpec); - break; } - endOffset= figureEndOffset(declSpec, declarators); - if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { - break; - } - if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { - break; - } throwBacktrack(LA(1)); } @@ -2014,7 +2017,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { protected IASTParameterDeclaration parameterDeclaration(DeclarationOptions option) throws BacktrackException, EndOfFileException { final IToken current = LA(1); int startingOffset = current.getOffset(); - + if (current.getType() == IToken.tLBRACKET && supportParameterInfoBlock) { + skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET); + } + IASTDeclSpecifier declSpec = null; IASTDeclarator declarator = null; IASTDeclSpecifier altDeclSpec = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 969d5c9decc..4f2ef749642 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -1775,6 +1775,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { supportExtendedTemplateSyntax = config.supportExtendedTemplateSyntax(); supportMinAndMaxOperators = config.supportMinAndMaxOperators(); supportLongLong = config.supportLongLongs(); + supportParameterInfoBlock= config.supportParameterInfoBlock(); this.index= index; } @@ -2558,26 +2559,28 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IToken.tLBRACE: return functionDefinition(firstOffset, declSpec, declarators, false); default: - insertSemi= true; - if (validWithoutDtor(declOption, declSpec)) { - // class definition without semicolon - if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { - if (markBeforDtor != null) { - backup(markBeforDtor); + if (declOption != DeclarationOptions.LOCAL) { + insertSemi= true; + if (validWithoutDtor(declOption, declSpec)) { + // class definition without semicolon + if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { + if (markBeforDtor != null) { + backup(markBeforDtor); + } + declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; + endOffset= calculateEndOffset(declSpec); + break; } - declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - endOffset= calculateEndOffset(declSpec); + } + endOffset= figureEndOffset(declSpec, declarators); + if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { + insertSemi= true; break; } - } - endOffset= figureEndOffset(declSpec, declarators); - if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { - insertSemi= true; - break; - } - if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { - break; - } + if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { + break; + } + } throwBacktrack(LA(1)); } @@ -2756,6 +2759,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected ICPPASTParameterDeclaration parameterDeclaration() throws BacktrackException, EndOfFileException { final int startOffset= LA(1).getOffset(); + if (LT(1) == IToken.tLBRACKET && supportParameterInfoBlock) { + skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET); + } + IASTDeclSpecifier declSpec; IASTDeclarator declarator; try { @@ -2776,7 +2783,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return parm; } - protected ICPPASTParameterDeclaration createParameterDeclaration() { return new CPPASTParameterDeclaration(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 776a4fe3837..00fbff1eed0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -147,7 +147,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { IScannerExtensionConfiguration configuration, ICodeReaderFactory readerFactory) { fLog = log; fAdditionalNumericLiteralSuffixes= nonNull(configuration.supportAdditionalNumericLiteralSuffixes()); - fLexOptions.fSupportDollarInitializers= configuration.support$InIdentifiers(); + fLexOptions.fSupportDollarInIdentifiers= configuration.support$InIdentifiers(); + fLexOptions.fSupportAtSignInIdentifiers= configuration.supportAtSignInIdentifiers(); fLexOptions.fSupportMinAndMax = configuration.supportMinAndMaxOperators(); fKeywords= new CharArrayIntMap(40, -1); fPPKeywords= new CharArrayIntMap(40, -1); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java index 9e53248fc1d..16356d36c4f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -46,7 +46,8 @@ final public class Lexer { private static final int ORIGIN_LEXER = OffsetLimitReachedException.ORIGIN_LEXER; public final static class LexerOptions implements Cloneable { - public boolean fSupportDollarInitializers= true; + public boolean fSupportDollarInIdentifiers= true; + public boolean fSupportAtSignInIdentifiers= true; public boolean fSupportMinAndMax= true; public boolean fCreateImageLocations= true; @@ -357,7 +358,12 @@ final public class Lexer { return identifier(start, 1); case '$': - if (fOptions.fSupportDollarInitializers) { + if (fOptions.fSupportDollarInIdentifiers) { + return identifier(start, 1); + } + break; + case '@': + if (fOptions.fSupportAtSignInIdentifiers) { return identifier(start, 1); } break; @@ -820,7 +826,10 @@ final public class Lexer { break; case '$': - isPartOfIdentifier= fOptions.fSupportDollarInitializers; + isPartOfIdentifier= fOptions.fSupportDollarInIdentifiers; + break; + case '@': + isPartOfIdentifier= fOptions.fSupportAtSignInIdentifiers; break; case '{': case '}': case '[': case ']': case '#': case '(': case ')': case '<': case '>': diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index 84736d7b0f8..d50e5f145af 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -50,8 +50,8 @@ import org.eclipse.core.runtime.content.IContentType; */ public class InternalASTServiceProvider implements IASTServiceProvider { - protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration(); - protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration(); + protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = GCCScannerExtensionConfiguration.getInstance(); + protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = GPPScannerExtensionConfiguration.getInstance(); private static final String[] dialects = { "C99", //$NON-NLS-1$ "C++98", //$NON-NLS-1$ diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java index 273e687571e..e63178b4322 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java @@ -8,7 +8,7 @@ ******************************************************************************/ package org.eclipse.cdt.core.dom.lrparser; -import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.AbstractScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; @@ -19,32 +19,39 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; * @author Mike Kucera * */ -public class ScannerExtensionConfiguration implements IScannerExtensionConfiguration { +public class ScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration { + @Override public CharArrayIntMap getAdditionalKeywords() { return null; } + @Override public IMacro[] getAdditionalMacros() { return null; } + @Override public CharArrayIntMap getAdditionalPreprocessorKeywords() { return null; } + @Override public boolean initializeMacroValuesTo1() { return false; } + @Override public boolean support$InIdentifiers() { return true; } + @Override public char[] supportAdditionalNumericLiteralSuffixes() { return null; } + @Override public boolean supportMinAndMaxOperators() { return false; }