1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

bug 233307, LR parser should use its own scanner extension configuration for now

This commit is contained in:
Mike Kucera 2008-05-22 18:23:31 +00:00
parent 171c01a9ac
commit c911a780f7
11 changed files with 318 additions and 44 deletions

View file

@ -105,4 +105,24 @@ public class LRCPPTests extends AST2CPPTests {
} catch(AssertionFailedError _) {
}
}
@Override
public void testBug99262B() throws Exception { // gcc
try {
super.testBug99262B();
fail();
} catch(AssertionFailedError _) {
}
}
@Override
public void testLiteralsViaOverloads_225534() throws Exception { // gcc, I think
try {
super.testLiteralsViaOverloads_225534();
fail();
} catch(AssertionFailedError _) {
}
}
}

View file

@ -126,7 +126,20 @@ public class LRCompleteParser2Tests extends CompleteParser2Tests {
try {
super.testGNUASMExtension();
fail();
} catch(AssertionFailedError _) { }
} catch(AssertionFailedError _) {
} catch(AssertionError _) {
}
}
@Override
public void testBug39551B() throws Exception {
try {
super.testBug39551B();
fail();
} catch(AssertionFailedError _) { }
}
}

View file

@ -76,5 +76,15 @@ public class LRDOMLocationTests extends DOMLocationTests {
}
catch(AssertionFailedError e) {}
}
@Override
public void testBug120607() throws Exception { // #assert and #unassert are gcc extensions
try {
super.testBug120607();
fail();
}
catch(AssertionFailedError e) {}
}
}

View file

@ -141,6 +141,42 @@ public class LRQuickParser2Tests extends QuickParser2Tests {
}
@Override
public void testBug40007() throws Exception { // gcc extension
try {
super.testBug40007();
fail();
} catch(AssertionFailedError _) {
} catch(AssertionError _) {
}
}
@Override
public void testBug39703() throws Exception { // gcc extension
try {
super.testBug39703();
fail();
} catch(AssertionFailedError _) { }
}
@Override
public void testBug39554() throws Exception { // gcc extension
try {
super.testBug39554();
fail();
} catch(AssertionFailedError _) { }
}
@Override
public void testBug39686() throws Exception { // gcc extension
try {
super.testBug39686();
fail();
} catch(AssertionFailedError _) { }
}
}

View file

@ -262,4 +262,14 @@ public class LRTests extends AST2Tests {
fail();
} catch(Throwable _) { }
}
@Override
public void testRedefinePtrdiff_Bug230895() throws Exception {
try {
super.testRedefinePtrdiff_Bug230895();
fail();
} catch(Throwable _) { }
}
}

View file

@ -15,7 +15,6 @@ import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
@ -45,6 +44,9 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
private static final boolean DEBUG_PRINT_GCC_AST = false;
private static final boolean DEBUG_PRINT_AST = false;
private final ICLanguageKeywords keywords;
/**
* Retrieve the parser (runs after the preprocessor runs).
*
@ -79,7 +81,21 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
* an instance of CPreprocessor.
*
*/
protected abstract ParserLanguage getParserLanguageForPreprocessor();
protected abstract ParserLanguage getParserLanguage();
/**
* Returns the scanner extension configuration for this language, may not return null
*/
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
public BaseExtensibleLanguage() {
ParserLanguage lang = getParserLanguage();
IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
keywords = new CLanguageKeywords(lang, config);
}
@SuppressWarnings("unchecked")
@ -113,9 +129,9 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
}
// TODO temporary
IScannerExtensionConfiguration config = new GCCScannerExtensionConfiguration();
IScannerExtensionConfiguration config = new ScannerExtensionConfiguration();
ParserLanguage pl = getParserLanguageForPreprocessor();
ParserLanguage pl = getParserLanguage();
IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
preprocessor.setScanComments((options & OPTION_ADD_COMMENTS) != 0);
preprocessor.setComputeImageLocations((options & ILanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
@ -162,9 +178,9 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
}
// TODO temporary
IScannerExtensionConfiguration config = new GCCScannerExtensionConfiguration();
IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
ParserLanguage pl = getParserLanguageForPreprocessor();
ParserLanguage pl = getParserLanguage();
IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
preprocessor.setContentAssistMode(offset);
@ -189,4 +205,16 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
public String[] getBuiltinTypes() {
return keywords.getBuiltinTypes();
}
public String[] getKeywords() {
return keywords.getKeywords();
}
public String[] getPreprocessorKeywords() {
return keywords.getPreprocessorKeywords();
}
}

View file

@ -0,0 +1,104 @@
/*******************************************************************************
* Copyright (c) 2006, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
/**
* This class allows provides a reusable implementation of ICLanguageKeywords
* for use by ILanguage implementations.
*
* Note: this code was mostly copied from AbstractCLikeLanguage.
*
*
* TODO move this into the core and use it with AbstractCLikeLanguage.
*
* @author Mike Kucera
*/
@SuppressWarnings({"restriction", "nls"})
class CLanguageKeywords implements ICLanguageKeywords {
private final ParserLanguage language;
private final IScannerExtensionConfiguration config;
// lazily initialized
private String[] keywords = null;
private String[] builtinTypes = null;
private String[] preprocessorKeywords = null;
/**
* @throws NullPointerException if either parameter is null
*/
public CLanguageKeywords(ParserLanguage language, IScannerExtensionConfiguration config) {
if(language == null)
throw new NullPointerException("language is null");
if(config == null)
throw new NullPointerException("config is null");
this.language = language;
this.config = config;
}
public String[] getKeywords() {
if(keywords == null) {
Set<String> keywordSet = new HashSet<String>(KeywordSets.getKeywords(KeywordSetKey.KEYWORDS, language));
CharArrayIntMap additionalKeywords = config.getAdditionalKeywords();
if (additionalKeywords != null) {
for (Iterator<char[]> iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) {
char[] name = iterator.next();
keywordSet.add(new String(name));
}
}
keywords = keywordSet.toArray(new String[keywordSet.size()]);
}
return keywords;
}
public String[] getBuiltinTypes() {
if(builtinTypes == null) {
Set<String> types = KeywordSets.getKeywords(KeywordSetKey.TYPES, language);
builtinTypes = types.toArray(new String[types.size()]);
}
return builtinTypes;
}
public String[] getPreprocessorKeywords() {
if(preprocessorKeywords == null) {
Set<String> keywords = new HashSet<String>(KeywordSets.getKeywords(KeywordSetKey.PP_DIRECTIVE, language));
CharArrayIntMap additionalKeywords= config.getAdditionalPreprocessorKeywords();
if (additionalKeywords != null) {
for (Iterator<char[]> iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) {
char[] name = iterator.next();
keywords.add(new String(name));
}
}
preprocessorKeywords = keywords.toArray(new String[keywords.size()]);
}
return preprocessorKeywords;
}
}

View file

@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 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 http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
/**
* A minimalistic scanner configuration for the LR parser.
*
* @author Mike Kucera
*
*/
public class ScannerExtensionConfiguration implements IScannerExtensionConfiguration {
public CharArrayIntMap getAdditionalKeywords() {
return null;
}
public IMacro[] getAdditionalMacros() {
return null;
}
public CharArrayIntMap getAdditionalPreprocessorKeywords() {
return null;
}
public boolean initializeMacroValuesTo1() {
return false;
}
public boolean support$InIdentifiers() {
return true;
}
public char[] supportAdditionalNumericLiteralSuffixes() {
return null;
}
public boolean supportMinAndMaxOperators() {
return false;
}
}

View file

@ -17,7 +17,9 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.ScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99ASTNodeFactory;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
@ -38,8 +40,7 @@ public class C99Language extends BaseExtensibleLanguage {
public static final String ID = PLUGIN_ID + ".c99"; //$NON-NLS-1$
private static final IDOMTokenMap TOKEN_MAP = DOMToC99TokenMap.DEFAULT_MAP;
private static GCCLanguage GCC_LANGUAGE = GCCLanguage.getDefault();
private static final IScannerExtensionConfiguration SCANNER_CONFIGURATION = new ScannerExtensionConfiguration();
private static C99Language DEFAULT = new C99Language();
@ -58,6 +59,11 @@ public class C99Language extends BaseExtensibleLanguage {
return TOKEN_MAP;
}
@Override
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return SCANNER_CONFIGURATION;
}
public IContributedModelBuilder createModelBuilder(@SuppressWarnings("unused") ITranslationUnit tu) {
return null;
}
@ -71,23 +77,11 @@ public class C99Language extends BaseExtensibleLanguage {
}
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
return GCC_LANGUAGE.getSelectedNames(ast, start, length);
}
public String[] getBuiltinTypes() {
return GCC_LANGUAGE.getBuiltinTypes();
}
public String[] getKeywords() {
return GCC_LANGUAGE.getKeywords();
}
public String[] getPreprocessorKeywords() {
return GCC_LANGUAGE.getPreprocessorKeywords();
return GCCLanguage.getDefault().getSelectedNames(ast, start, length);
}
@Override
protected ParserLanguage getParserLanguageForPreprocessor() {
protected ParserLanguage getParserLanguage() {
return ParserLanguage.C;
}
@ -103,6 +97,8 @@ public class C99Language extends BaseExtensibleLanguage {
}
return tu;
}
}

View file

@ -17,7 +17,9 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.ScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.lrparser.action.cpp.CPPASTNodeFactory;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
@ -38,7 +40,8 @@ public class ISOCPPLanguage extends BaseExtensibleLanguage {
public static final String ID = PLUGIN_ID + ".isocpp"; //$NON-NLS-1$
private static final IDOMTokenMap TOKEN_MAP = DOMToISOCPPTokenMap.DEFAULT_MAP;
private static GPPLanguage GPP_LANGUAGE = GPPLanguage.getDefault();
private static final IScannerExtensionConfiguration SCANNER_CONFIGURATION = new ScannerExtensionConfiguration();
private static ISOCPPLanguage DEFAULT = new ISOCPPLanguage();
@ -57,6 +60,11 @@ public class ISOCPPLanguage extends BaseExtensibleLanguage {
protected IDOMTokenMap getTokenMap() {
return TOKEN_MAP;
}
@Override
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return SCANNER_CONFIGURATION;
}
public IContributedModelBuilder createModelBuilder(@SuppressWarnings("unused") ITranslationUnit tu) {
return null;
@ -71,23 +79,12 @@ public class ISOCPPLanguage extends BaseExtensibleLanguage {
}
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
return GPP_LANGUAGE.getSelectedNames(ast, start, length);
return GPPLanguage.getDefault().getSelectedNames(ast, start, length);
}
public String[] getBuiltinTypes() {
return GPP_LANGUAGE.getBuiltinTypes();
}
public String[] getKeywords() {
return GPP_LANGUAGE.getKeywords();
}
public String[] getPreprocessorKeywords() {
return GPP_LANGUAGE.getPreprocessorKeywords();
}
@Override
protected ParserLanguage getParserLanguageForPreprocessor() {
protected ParserLanguage getParserLanguage() {
return ParserLanguage.CPP;
}

View file

@ -16,8 +16,10 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.ScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99ASTNodeFactory;
import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.upc.DOMToUPCTokenMap;
import org.eclipse.cdt.core.dom.parser.upc.UPCKeyword;
import org.eclipse.cdt.core.index.IIndex;
@ -44,8 +46,11 @@ public class UPCLanguage extends BaseExtensibleLanguage {
private static final C99Language C99_LANGUAGE = C99Language.getDefault();
private static final UPCLanguage myDefault = new UPCLanguage();
private static final String[] keywords = UPCKeyword.getAllKeywords();
private static final String[] upcKeywords = UPCKeyword.getAllKeywords();
private static final IScannerExtensionConfiguration SCANNER_CONFIGURATION = new ScannerExtensionConfiguration();
public static UPCLanguage getDefault() {
return myDefault;
@ -80,20 +85,23 @@ public class UPCLanguage extends BaseExtensibleLanguage {
return C99_LANGUAGE.getSelectedNames(ast, start, length);
}
@Override
public String[] getBuiltinTypes() {
return C99_LANGUAGE.getBuiltinTypes();
}
@Override
public String[] getKeywords() {
return keywords;
return upcKeywords;
}
@Override
public String[] getPreprocessorKeywords() {
return C99_LANGUAGE.getPreprocessorKeywords();
}
@Override
protected ParserLanguage getParserLanguageForPreprocessor() {
protected ParserLanguage getParserLanguage() {
return ParserLanguage.C;
}
@ -109,10 +117,10 @@ public class UPCLanguage extends BaseExtensibleLanguage {
}
return tu;
}
@Override
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return SCANNER_CONFIGURATION;
}
}