1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 214127: merge AbstractCLanguage and AbstractCPPLanguage into one class

This commit is contained in:
Mike Kucera 2008-01-07 16:11:41 +00:00
parent d2c442c373
commit a710c823c8
5 changed files with 251 additions and 426 deletions

View file

@ -10,35 +10,55 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Mike Kucera - IBM
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.gnu.c; package org.eclipse.cdt.core.dom.ast.gnu.c;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.parser.AbstractCLikeLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c.AbstractCLanguage; 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.GCCParserExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; 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;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
/** /**
* @author Doug Schaefer * Concrete ILanguage implementation for the DOM C parser.
* *
*/ */
public class GCCLanguage extends AbstractCLanguage { public class GCCLanguage extends AbstractCLikeLanguage {
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration(); protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
protected static final GCCParserExtensionConfiguration C_GNU_PARSER_EXTENSION = new GCCParserExtensionConfiguration(); protected static final GCCParserExtensionConfiguration C_GNU_PARSER_EXTENSION = new GCCParserExtensionConfiguration();
// Must match the id in the extension // Must match the id in the extension
public static final String ID = CCorePlugin.PLUGIN_ID + ".gcc"; //$NON-NLS-1$ public static final String ID = CCorePlugin.PLUGIN_ID + ".gcc"; //$NON-NLS-1$
private static final GCCLanguage myDefault = new GCCLanguage(); private static final GCCLanguage DEFAULT_INSTANCE = new GCCLanguage();
public static GCCLanguage getDefault() { public static GCCLanguage getDefault() {
return myDefault; return DEFAULT_INSTANCE;
} }
@Override
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
if (adapter == IPDOMLinkageFactory.class) {
return new PDOMCLinkageFactory();
}
return super.getAdapter(adapter);
}
public String getId() { public String getId() {
return ID; return ID;
} }
@ -47,18 +67,26 @@ public class GCCLanguage extends AbstractCLanguage {
return ILinkage.C_LINKAGE_ID; return ILinkage.C_LINKAGE_ID;
} }
/*
* @see org.eclipse.cdt.core.dom.parser.c.AbstractCLanguage#getScannerExtensionConfiguration() @Override
*/
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() { protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return C_GNU_SCANNER_EXTENSION; return C_GNU_SCANNER_EXTENSION;
} }
/*
* @see org.eclipse.cdt.core.dom.parser.c.AbstractCLanguage#getParserExtensionConfiguration() @Override
*/ protected ISourceCodeParser createParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, IIndex index) {
protected ICParserExtensionConfiguration getParserExtensionConfiguration() { return new GNUCSourceParser(scanner, parserMode, logService, C_GNU_PARSER_EXTENSION, index);
return C_GNU_PARSER_EXTENSION;
} }
@Override
protected ParserLanguage getParserLanguage() {
return ParserLanguage.C;
}
} }

View file

@ -10,31 +10,50 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Mike Kucera - IBM
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.gnu.cpp; package org.eclipse.cdt.core.dom.ast.gnu.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.parser.AbstractCLikeLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPLanguage; import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; 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.GPPScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
/** /**
* @author Doug Schaefer * Concrete ILanguage implementation for the DOM C++ parser.
* *
*/ */
public class GPPLanguage extends AbstractCPPLanguage { public class GPPLanguage extends AbstractCLikeLanguage {
protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration(); protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration();
protected static final GPPParserExtensionConfiguration CPP_GNU_PARSER_EXTENSION = new GPPParserExtensionConfiguration(); protected static final GPPParserExtensionConfiguration CPP_GNU_PARSER_EXTENSION = new GPPParserExtensionConfiguration();
public static final String ID = CCorePlugin.PLUGIN_ID + ".g++"; //$NON-NLS-1$ public static final String ID = CCorePlugin.PLUGIN_ID + ".g++"; //$NON-NLS-1$
private static final GPPLanguage myDefault = new GPPLanguage(); private static final GPPLanguage DEFAULT_INSTANCE = new GPPLanguage();
public static GPPLanguage getDefault() { public static GPPLanguage getDefault() {
return myDefault; return DEFAULT_INSTANCE;
}
@Override
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
if (adapter == IPDOMLinkageFactory.class) {
return new PDOMCPPLinkageFactory();
}
return super.getAdapter(adapter);
} }
public String getId() { public String getId() {
@ -46,18 +65,19 @@ public class GPPLanguage extends AbstractCPPLanguage {
return ILinkage.CPP_LINKAGE_ID; return ILinkage.CPP_LINKAGE_ID;
} }
/* @Override
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPLanguage#getScannerExtensionConfiguration()
*/
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() { protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return CPP_GNU_SCANNER_EXTENSION; return CPP_GNU_SCANNER_EXTENSION;
} }
/* @Override
* @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPLanguage#getParserExtensionConfiguration() protected ISourceCodeParser createParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, IIndex index) {
*/ return new GNUCPPSourceParser(scanner, parserMode, logService, CPP_GNU_PARSER_EXTENSION, index);
protected AbstractCPPParserExtensionConfiguration getParserExtensionConfiguration() { }
return CPP_GNU_PARSER_EXTENSION;
@Override
protected ParserLanguage getParserLanguage() {
return ParserLanguage.CPP;
} }
} }

View file

@ -1,15 +1,16 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation * Anton Leherbauer (Wind River Systems) - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Mike Kucera (IBM)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.parser.c; package org.eclipse.cdt.core.dom.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -18,14 +19,11 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.parser.AbstractScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage; import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ICLanguageKeywords; import org.eclipse.cdt.core.model.ICLanguageKeywords;
@ -39,17 +37,18 @@ import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* Abstract C language. Derived classes need only implement * This class provides a skeletal implementation of the ILanguage interface
* {@link getScannerExtensionConfiguration()} and * for the DOM parser framework.
* {@link getParserExtensionConfiguration()}. *
* This class uses the template method pattern, derived classes need only implement
* {@link getScannerExtensionConfiguration()},
* {@link getParserLanguage()} and
* {@link createParser()}.
* *
* <p> * <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
@ -60,39 +59,57 @@ import org.eclipse.core.runtime.CoreException;
* *
* @see AbstractScannerExtensionConfiguration * @see AbstractScannerExtensionConfiguration
* *
* @since 4.0 * @since 5.0
*/ */
public abstract class AbstractCLanguage extends AbstractLanguage implements ICLanguageKeywords { public abstract class AbstractCLikeLanguage extends AbstractLanguage implements ICLanguageKeywords {
protected static class NameCollector extends CASTVisitor {
static class NameCollector extends ASTVisitor {
{ {
shouldVisitNames= true; shouldVisitNames= true;
} }
private List nameList= new ArrayList(); private List<IASTName> nameList= new ArrayList<IASTName>();
public int visit(IASTName name) { @Override public int visit(IASTName name) {
nameList.add(name); nameList.add(name);
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
public IASTName[] getNames() { public IASTName[] getNames() {
return (IASTName[]) nameList.toArray(new IASTName[nameList.size()]); return nameList.toArray(new IASTName[nameList.size()]);
} }
} }
public Object getAdapter(Class adapter) {
if (adapter == IPDOMLinkageFactory.class) { /**
return new PDOMCLinkageFactory(); * @return the scanner extension configuration for this language, may not
} * return <code>null</code>
return super.getAdapter(adapter); */
} protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
/**
* @returns the actual parser object.
*/
protected abstract ISourceCodeParser createParser(IScanner scanner, ParserMode parserMode,
IParserLogService logService, IIndex index);
/**
* @return The ParserLanguage value corresponding to the language supported.
*/
protected abstract ParserLanguage getParserLanguage();
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException { ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException {
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log); return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
} }
@Override
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException { ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException {
@ -107,6 +124,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
return ast; return ast;
} }
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException { ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
@ -122,38 +140,6 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
} }
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
IASTNode selectedNode= ast.selectNodeForLocation(ast.getFilePath(), start, length);
if (selectedNode == null)
return new IASTName[0];
if (selectedNode instanceof IASTName)
return new IASTName[] { (IASTName) selectedNode };
NameCollector collector= new NameCollector();
selectedNode.accept(collector);
return collector.getNames();
}
public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) {
// Use the default CDT model builder
return null;
}
/**
* Create the scanner to be used with the parser.
*
* @param reader the code reader for the main file
* @param scanInfo the scanner information (macros, include pathes)
* @param fileCreator the code reader factory for inclusions
* @param log the log for debugging
* @return an instance of IScanner
*/
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
return new CPreprocessor(reader, scanInfo, ParserLanguage.C, log, getScannerExtensionConfiguration(), fileCreator);
}
/** /**
* Create the parser. * Create the parser.
* *
@ -175,51 +161,68 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
else { else {
mode= ParserMode.COMPLETE_PARSE; mode= ParserMode.COMPLETE_PARSE;
} }
return new GNUCSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index); return createParser(scanner, mode, log, index);
} }
/**
* @return the scanner extension configuration for this language, may not
* return <code>null</code>
*/
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
/** /**
* @return the parser extension configuration for this language, may not * Create the scanner to be used with the parser.
* return <code>null</code> *
* @param reader the code reader for the main file
* @param scanInfo the scanner information (macros, include pathes)
* @param fileCreator the code reader factory for inclusions
* @param log the log for debugging
* @return an instance of IScanner
*/ */
protected abstract ICParserExtensionConfiguration getParserExtensionConfiguration(); protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
return new CPreprocessor(reader, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(), fileCreator);
}
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
IASTNode selectedNode= ast.selectNodeForLocation(ast.getFilePath(), start, length);
if (selectedNode == null)
return new IASTName[0];
if (selectedNode instanceof IASTName)
return new IASTName[] { (IASTName) selectedNode };
NameCollector collector = new NameCollector();
selectedNode.accept(collector);
return collector.getNames();
}
public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) {
// use default model builder
return null;
}
/*
* @see org.eclipse.cdt.core.model.ICLanguageKeywords#getKeywords()
*/
public String[] getKeywords() { public String[] getKeywords() {
Set keywords= KeywordSets.getKeywords(KeywordSetKey.KEYWORDS, ParserLanguage.C); Set<String> keywords = new HashSet<String>(KeywordSets.getKeywords(KeywordSetKey.KEYWORDS, getParserLanguage()));
keywords= new HashSet(keywords);
CharArrayIntMap additionalKeywords= getScannerExtensionConfiguration().getAdditionalKeywords(); CharArrayIntMap additionalKeywords = getScannerExtensionConfiguration().getAdditionalKeywords();
if (additionalKeywords != null) { if (additionalKeywords != null) {
for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) { for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) {
char[] name = (char[]) iterator.next(); char[] name = (char[]) iterator.next();
keywords.add(new String(name)); keywords.add(new String(name));
} }
} }
return (String[]) keywords.toArray(new String[keywords.size()]); return keywords.toArray(new String[keywords.size()]);
} }
/*
* @see org.eclipse.cdt.core.model.ICLanguageKeywords#getBuiltinTypes()
*/
public String[] getBuiltinTypes() { public String[] getBuiltinTypes() {
Set types= KeywordSets.getKeywords(KeywordSetKey.TYPES, ParserLanguage.C); Set<String> types = KeywordSets.getKeywords(KeywordSetKey.TYPES, getParserLanguage());
return (String[]) types.toArray(new String[types.size()]); return types.toArray(new String[types.size()]);
} }
/*
* @see org.eclipse.cdt.core.model.ICLanguageKeywords#getPreprocessorKeywords()
*/
public String[] getPreprocessorKeywords() { public String[] getPreprocessorKeywords() {
Set keywords= KeywordSets.getKeywords(KeywordSetKey.PP_DIRECTIVE, ParserLanguage.C); Set<String> keywords = new HashSet<String>(KeywordSets.getKeywords(KeywordSetKey.PP_DIRECTIVE, getParserLanguage()));
keywords= new HashSet(keywords);
CharArrayIntMap additionalKeywords= getScannerExtensionConfiguration().getAdditionalPreprocessorKeywords(); CharArrayIntMap additionalKeywords= getScannerExtensionConfiguration().getAdditionalPreprocessorKeywords();
if (additionalKeywords != null) { if (additionalKeywords != null) {
for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) { for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) {
@ -227,6 +230,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
keywords.add(new String(name)); keywords.add(new String(name));
} }
} }
return (String[]) keywords.toArray(new String[keywords.size()]); return keywords.toArray(new String[keywords.size()]);
} }
} }

View file

@ -1,228 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007 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:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.parser.cpp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
import org.eclipse.core.runtime.CoreException;
/**
* Abstract C++ language. Derived classes need only implement
* {@link getScannerExtensionConfiguration()} and
* {@link getParserExtensionConfiguration()}.
*
* <p>
* <strong>EXPERIMENTAL</strong>. 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.
* </p>
*
* @see IScannerExtensionConfiguration
* @see ICPPParserExtensionConfiguration
*
* @since 4.0
*/
public abstract class AbstractCPPLanguage extends AbstractLanguage implements ICLanguageKeywords {
protected static class NameCollector extends CPPASTVisitor {
{
shouldVisitNames= true;
}
private List nameList= new ArrayList();
public int visit(IASTName name) {
nameList.add(name);
return PROCESS_CONTINUE;
}
public IASTName[] getNames() {
return (IASTName[]) nameList.toArray(new IASTName[nameList.size()]);
}
}
public Object getAdapter(Class adapter) {
if (adapter == IPDOMLinkageFactory.class) {
return new PDOMCPPLinkageFactory();
}
return super.getAdapter(adapter);
}
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory codeReaderFactory, IIndex index,IParserLogService log) throws CoreException {
return getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, 0, log);
}
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException {
IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log);
scanner.setScanComments((options & OPTION_ADD_COMMENTS) != 0);
ISourceCodeParser parser= createParser(scanner, log, index, false, options);
// Parse
IASTTranslationUnit ast= parser.parse();
return ast;
}
public IASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
scanner.setContentAssistMode(offset);
ISourceCodeParser parser= createParser(scanner, log, index, true, 0);
// Run the parse and return the completion node
parser.parse();
IASTCompletionNode node= parser.getCompletionNode();
return node;
}
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
IASTNode selectedNode= ast.selectNodeForLocation(ast.getFilePath(), start, length);
if (selectedNode == null)
return new IASTName[0];
if (selectedNode instanceof IASTName)
return new IASTName[] { (IASTName) selectedNode };
NameCollector collector= new NameCollector();
selectedNode.accept(collector);
return collector.getNames();
}
public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) {
// Use the default CDT model builder
return null;
}
/**
* Create the scanner to be used with the parser.
*
* @param reader the code reader for the main file
* @param scanInfo the scanner information (macros, include pathes)
* @param fileCreator the code reader factory for inclusions
* @param log the log for debugging
* @return an instance of IScanner
*/
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
return new CPreprocessor(reader, scanInfo, ParserLanguage.CPP, log, getScannerExtensionConfiguration(), fileCreator);
}
/**
* Create the parser.
*
* @param scanner the IScanner to get tokens from
* @param log the parser log service
* @param index the index to help resolve bindings
* @param forCompletion whether the parser is used for code completion
* @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
* @return an instance of ISourceCodeParser
*/
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
ParserMode mode= null;
if (forCompletion) {
mode= ParserMode.COMPLETION_PARSE;
}
else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) {
mode= ParserMode.STRUCTURAL_PARSE;
}
else {
mode= ParserMode.COMPLETE_PARSE;
}
return new GNUCPPSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index);
}
/**
* @return the scanner extension configuration for this language, may not
* return <code>null</code>
*/
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
/**
* @return the parser extension configuration for this language, may not
* return <code>null</code>
*/
protected abstract AbstractCPPParserExtensionConfiguration getParserExtensionConfiguration();
/*
* @see org.eclipse.cdt.core.model.ICLanguageKeywords#getKeywords()
*/
public String[] getKeywords() {
Set keywords= KeywordSets.getKeywords(KeywordSetKey.KEYWORDS, ParserLanguage.CPP);
keywords= new HashSet(keywords);
CharArrayIntMap additionalKeywords= getScannerExtensionConfiguration().getAdditionalKeywords();
if (additionalKeywords != null) {
for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) {
char[] name = (char[]) iterator.next();
keywords.add(new String(name));
}
}
return (String[]) keywords.toArray(new String[keywords.size()]);
}
/*
* @see org.eclipse.cdt.core.model.ICLanguageKeywords#getBuiltinTypes()
*/
public String[] getBuiltinTypes() {
Set types= KeywordSets.getKeywords(KeywordSetKey.TYPES, ParserLanguage.CPP);
return (String[]) types.toArray(new String[types.size()]);
}
/*
* @see org.eclipse.cdt.core.model.ICLanguageKeywords#getPreprocessorKeywords()
*/
public String[] getPreprocessorKeywords() {
Set keywords= KeywordSets.getKeywords(KeywordSetKey.PP_DIRECTIVE, ParserLanguage.CPP);
keywords= new HashSet(keywords);
CharArrayIntMap additionalKeywords= getScannerExtensionConfiguration().getAdditionalPreprocessorKeywords();
if (additionalKeywords != null) {
for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) {
char[] name = (char[]) iterator.next();
keywords.add(new String(name));
}
}
return (String[]) keywords.toArray(new String[keywords.size()]);
}
}

View file

@ -10,8 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.token; package org.eclipse.cdt.internal.core.parser.token;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Hashtable; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -25,16 +26,16 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
*/ */
public class KeywordSets { public class KeywordSets {
public static Set getKeywords( KeywordSetKey kind, ParserLanguage language ) public static Set<String> getKeywords( KeywordSetKey kind, ParserLanguage language )
{ {
if( kind == KeywordSetKey.EMPTY ) if( kind == KeywordSetKey.EMPTY )
return EMPTY_TABLE; return EMPTY_TABLE;
if( kind == KeywordSetKey.DECL_SPECIFIER_SEQUENCE ) if( kind == KeywordSetKey.DECL_SPECIFIER_SEQUENCE )
return (Set) DECL_SPECIFIER_SEQUENCE_TABLE.get( language ); return DECL_SPECIFIER_SEQUENCE_TABLE.get( language );
if( kind == KeywordSetKey.DECLARATION ) if( kind == KeywordSetKey.DECLARATION )
return (Set) DECLARATION_TABLE.get( language ); return DECLARATION_TABLE.get( language );
if( kind == KeywordSetKey.STATEMENT ) if( kind == KeywordSetKey.STATEMENT )
return (Set) STATEMENT_TABLE.get( language ); return STATEMENT_TABLE.get( language );
if( kind == KeywordSetKey.BASE_SPECIFIER ) if( kind == KeywordSetKey.BASE_SPECIFIER )
return BASE_SPECIFIER_CPP; return BASE_SPECIFIER_CPP;
if( kind == KeywordSetKey.MEMBER ) if( kind == KeywordSetKey.MEMBER )
@ -46,46 +47,46 @@ public class KeywordSets {
if( kind == KeywordSetKey.POST_USING ) if( kind == KeywordSetKey.POST_USING )
return POST_USING_CPP; return POST_USING_CPP;
if( kind == KeywordSetKey.FUNCTION_MODIFIER ) if( kind == KeywordSetKey.FUNCTION_MODIFIER )
return (Set) FUNCTION_MODIFIER_TABLE.get( language ); return FUNCTION_MODIFIER_TABLE.get( language );
if( kind == KeywordSetKey.NAMESPACE_ONLY ) if( kind == KeywordSetKey.NAMESPACE_ONLY )
return NAMESPACE_ONLY_SET; return NAMESPACE_ONLY_SET;
if( kind == KeywordSetKey.MACRO ) if( kind == KeywordSetKey.MACRO )
return MACRO_ONLY; return MACRO_ONLY;
if( kind == KeywordSetKey.PP_DIRECTIVE ) if( kind == KeywordSetKey.PP_DIRECTIVE )
return (Set) PP_DIRECTIVES_TABLE.get( language ); return PP_DIRECTIVES_TABLE.get( language );
if( kind == KeywordSetKey.EXPRESSION ) if( kind == KeywordSetKey.EXPRESSION )
return (Set) EXPRESSION_TABLE.get( language ); return EXPRESSION_TABLE.get( language );
if( kind == KeywordSetKey.ALL ) if( kind == KeywordSetKey.ALL )
return (Set) ALL_TABLE.get( language ); return ALL_TABLE.get( language );
if( kind == KeywordSetKey.KEYWORDS ) if( kind == KeywordSetKey.KEYWORDS )
return (Set) KEYWORDS_TABLE.get( language ); return KEYWORDS_TABLE.get( language );
if( kind == KeywordSetKey.TYPES ) if( kind == KeywordSetKey.TYPES )
return (Set) TYPES_TABLE.get( language ); return TYPES_TABLE.get( language );
//TODO finish this //TODO finish this
return null; return null;
} }
private static final Set EMPTY_TABLE = new HashSet(0); private static final Set<String> EMPTY_TABLE = new HashSet<String>(0);
private static final Set NAMESPACE_ONLY_SET; private static final Set<String> NAMESPACE_ONLY_SET;
static static
{ {
NAMESPACE_ONLY_SET = new HashSet(1); NAMESPACE_ONLY_SET = new HashSet<String>(1);
NAMESPACE_ONLY_SET.add(Keywords.NAMESPACE ); NAMESPACE_ONLY_SET.add(Keywords.NAMESPACE );
} }
private static final Set MACRO_ONLY; private static final Set<String> MACRO_ONLY;
static static
{ {
MACRO_ONLY = new HashSet(1); MACRO_ONLY = new HashSet<String>(1);
MACRO_ONLY.add("defined()" ); //$NON-NLS-1$ MACRO_ONLY.add("defined()" ); //$NON-NLS-1$
} }
private static final Set DECL_SPECIFIER_SEQUENCE_C; private static final Set<String> DECL_SPECIFIER_SEQUENCE_C;
static static
{ {
DECL_SPECIFIER_SEQUENCE_C = new TreeSet(); DECL_SPECIFIER_SEQUENCE_C = new TreeSet<String>();
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.INLINE ); DECL_SPECIFIER_SEQUENCE_C.add( Keywords.INLINE );
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.AUTO); DECL_SPECIFIER_SEQUENCE_C.add( Keywords.AUTO);
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.REGISTER); DECL_SPECIFIER_SEQUENCE_C.add( Keywords.REGISTER);
@ -113,10 +114,10 @@ public class KeywordSets {
DECL_SPECIFIER_SEQUENCE_C.add( Keywords.ENUM); DECL_SPECIFIER_SEQUENCE_C.add( Keywords.ENUM);
} }
private static final Set DECL_SPECIFIER_SEQUENCE_CPP; private static final Set<String> DECL_SPECIFIER_SEQUENCE_CPP;
static static
{ {
DECL_SPECIFIER_SEQUENCE_CPP = new TreeSet(); DECL_SPECIFIER_SEQUENCE_CPP = new TreeSet<String>();
// add all of C then remove the ones we don't need // add all of C then remove the ones we don't need
DECL_SPECIFIER_SEQUENCE_CPP.addAll( DECL_SPECIFIER_SEQUENCE_C ); DECL_SPECIFIER_SEQUENCE_CPP.addAll( DECL_SPECIFIER_SEQUENCE_C );
DECL_SPECIFIER_SEQUENCE_CPP.remove( Keywords._COMPLEX); DECL_SPECIFIER_SEQUENCE_CPP.remove( Keywords._COMPLEX);
@ -132,18 +133,18 @@ public class KeywordSets {
DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.CLASS); DECL_SPECIFIER_SEQUENCE_CPP.add( Keywords.CLASS);
} }
private static final Hashtable DECL_SPECIFIER_SEQUENCE_TABLE; private static final Map<ParserLanguage,Set<String>> DECL_SPECIFIER_SEQUENCE_TABLE;
static static
{ {
DECL_SPECIFIER_SEQUENCE_TABLE = new Hashtable(); DECL_SPECIFIER_SEQUENCE_TABLE = new HashMap<ParserLanguage,Set<String>>();
DECL_SPECIFIER_SEQUENCE_TABLE.put( ParserLanguage.CPP, DECL_SPECIFIER_SEQUENCE_CPP ); DECL_SPECIFIER_SEQUENCE_TABLE.put( ParserLanguage.CPP, DECL_SPECIFIER_SEQUENCE_CPP );
DECL_SPECIFIER_SEQUENCE_TABLE.put( ParserLanguage.C, DECL_SPECIFIER_SEQUENCE_C ); DECL_SPECIFIER_SEQUENCE_TABLE.put( ParserLanguage.C, DECL_SPECIFIER_SEQUENCE_C );
} }
private static final Set DECLARATION_CPP; private static final Set<String> DECLARATION_CPP;
static static
{ {
DECLARATION_CPP = new TreeSet(); DECLARATION_CPP = new TreeSet<String>();
DECLARATION_CPP.addAll( DECL_SPECIFIER_SEQUENCE_CPP ); DECLARATION_CPP.addAll( DECL_SPECIFIER_SEQUENCE_CPP );
DECLARATION_CPP.add( Keywords.ASM ); DECLARATION_CPP.add( Keywords.ASM );
DECLARATION_CPP.add( Keywords.TEMPLATE ); DECLARATION_CPP.add( Keywords.TEMPLATE );
@ -152,26 +153,26 @@ public class KeywordSets {
DECLARATION_CPP.add( Keywords.EXPORT ); DECLARATION_CPP.add( Keywords.EXPORT );
} }
private static final Set DECLARATION_C; private static final Set<String> DECLARATION_C;
static static
{ {
DECLARATION_C = new TreeSet(); DECLARATION_C = new TreeSet<String>();
DECLARATION_C.addAll(DECL_SPECIFIER_SEQUENCE_C ); DECLARATION_C.addAll(DECL_SPECIFIER_SEQUENCE_C );
DECLARATION_C.add(Keywords.ASM ); DECLARATION_C.add(Keywords.ASM );
} }
private static final Hashtable DECLARATION_TABLE; private static final Map<ParserLanguage,Set<String>> DECLARATION_TABLE;
static static
{ {
DECLARATION_TABLE = new Hashtable(); DECLARATION_TABLE = new HashMap<ParserLanguage,Set<String>>();
DECLARATION_TABLE.put( ParserLanguage.CPP, DECLARATION_CPP ); DECLARATION_TABLE.put( ParserLanguage.CPP, DECLARATION_CPP );
DECLARATION_TABLE.put( ParserLanguage.C, DECLARATION_C ); DECLARATION_TABLE.put( ParserLanguage.C, DECLARATION_C );
} }
private static final Set EXPRESSION_C; private static final Set<String> EXPRESSION_C;
static static
{ {
EXPRESSION_C = new TreeSet(); EXPRESSION_C = new TreeSet<String>();
EXPRESSION_C.add( Keywords.CHAR ); EXPRESSION_C.add( Keywords.CHAR );
EXPRESSION_C.add( Keywords.WCHAR_T); EXPRESSION_C.add( Keywords.WCHAR_T);
EXPRESSION_C.add( Keywords.SHORT); EXPRESSION_C.add( Keywords.SHORT);
@ -185,10 +186,10 @@ public class KeywordSets {
} }
private static final Set EXPRESSION_CPP; private static final Set<String> EXPRESSION_CPP;
static static
{ {
EXPRESSION_CPP = new TreeSet(EXPRESSION_C); EXPRESSION_CPP = new TreeSet<String>(EXPRESSION_C);
EXPRESSION_CPP.add( Keywords.BOOL ); EXPRESSION_CPP.add( Keywords.BOOL );
EXPRESSION_CPP.add( Keywords.NEW ); EXPRESSION_CPP.add( Keywords.NEW );
EXPRESSION_CPP.add( Keywords.DELETE ); EXPRESSION_CPP.add( Keywords.DELETE );
@ -205,18 +206,18 @@ public class KeywordSets {
EXPRESSION_CPP.add( Keywords.THROW ); EXPRESSION_CPP.add( Keywords.THROW );
} }
private static final Hashtable EXPRESSION_TABLE; private static final Map<ParserLanguage,Set<String>> EXPRESSION_TABLE;
static static
{ {
EXPRESSION_TABLE = new Hashtable(); EXPRESSION_TABLE = new HashMap<ParserLanguage,Set<String>>();
EXPRESSION_TABLE.put( ParserLanguage.CPP, EXPRESSION_CPP ); EXPRESSION_TABLE.put( ParserLanguage.CPP, EXPRESSION_CPP );
EXPRESSION_TABLE.put( ParserLanguage.C, EXPRESSION_C ); EXPRESSION_TABLE.put( ParserLanguage.C, EXPRESSION_C );
} }
private static final Set STATEMENT_C; private static final Set<String> STATEMENT_C;
static static
{ {
STATEMENT_C= new TreeSet(); STATEMENT_C= new TreeSet<String>();
STATEMENT_C.addAll( DECLARATION_C ); STATEMENT_C.addAll( DECLARATION_C );
STATEMENT_C.addAll( EXPRESSION_C ); STATEMENT_C.addAll( EXPRESSION_C );
STATEMENT_C.add( Keywords.FOR ); STATEMENT_C.add( Keywords.FOR );
@ -233,10 +234,10 @@ public class KeywordSets {
STATEMENT_C.add( Keywords.DO); STATEMENT_C.add( Keywords.DO);
} }
private static final Set STATEMENT_CPP; private static final Set<String> STATEMENT_CPP;
static static
{ {
STATEMENT_CPP = new TreeSet( DECLARATION_CPP ); STATEMENT_CPP = new TreeSet<String>( DECLARATION_CPP );
STATEMENT_CPP.addAll( EXPRESSION_CPP ); STATEMENT_CPP.addAll( EXPRESSION_CPP );
STATEMENT_CPP.add( Keywords.TRY ); STATEMENT_CPP.add( Keywords.TRY );
STATEMENT_CPP.add( Keywords.FOR ); STATEMENT_CPP.add( Keywords.FOR );
@ -254,65 +255,65 @@ public class KeywordSets {
STATEMENT_CPP.add( Keywords.DO); STATEMENT_CPP.add( Keywords.DO);
} }
private static final Hashtable STATEMENT_TABLE; private static final Map<ParserLanguage,Set<String>> STATEMENT_TABLE;
static static
{ {
STATEMENT_TABLE = new Hashtable(); STATEMENT_TABLE = new HashMap<ParserLanguage,Set<String>>();
STATEMENT_TABLE.put( ParserLanguage.CPP, STATEMENT_CPP); STATEMENT_TABLE.put( ParserLanguage.CPP, STATEMENT_CPP);
STATEMENT_TABLE.put( ParserLanguage.C, STATEMENT_C ); STATEMENT_TABLE.put( ParserLanguage.C, STATEMENT_C );
} }
private static final Set BASE_SPECIFIER_CPP; private static final Set<String> BASE_SPECIFIER_CPP;
static static
{ {
BASE_SPECIFIER_CPP = new TreeSet(); BASE_SPECIFIER_CPP = new TreeSet<String>();
BASE_SPECIFIER_CPP.add(Keywords.PUBLIC); BASE_SPECIFIER_CPP.add(Keywords.PUBLIC);
BASE_SPECIFIER_CPP.add(Keywords.PROTECTED); BASE_SPECIFIER_CPP.add(Keywords.PROTECTED);
BASE_SPECIFIER_CPP.add(Keywords.PRIVATE); BASE_SPECIFIER_CPP.add(Keywords.PRIVATE);
BASE_SPECIFIER_CPP.add(Keywords.VIRTUAL); BASE_SPECIFIER_CPP.add(Keywords.VIRTUAL);
} }
private static final Set CLASS_MEMBER; private static final Set<String> CLASS_MEMBER;
static static
{ {
CLASS_MEMBER = new TreeSet(DECL_SPECIFIER_SEQUENCE_CPP); CLASS_MEMBER = new TreeSet<String>(DECL_SPECIFIER_SEQUENCE_CPP);
CLASS_MEMBER.add(Keywords.PUBLIC); CLASS_MEMBER.add(Keywords.PUBLIC);
CLASS_MEMBER.add(Keywords.PROTECTED); CLASS_MEMBER.add(Keywords.PROTECTED);
CLASS_MEMBER.add(Keywords.PRIVATE); CLASS_MEMBER.add(Keywords.PRIVATE);
} }
private static final Set POST_USING_CPP; private static final Set<String> POST_USING_CPP;
static static
{ {
POST_USING_CPP = new TreeSet(); POST_USING_CPP = new TreeSet<String>();
POST_USING_CPP.add(Keywords.NAMESPACE); POST_USING_CPP.add(Keywords.NAMESPACE);
POST_USING_CPP.add(Keywords.TYPENAME); POST_USING_CPP.add(Keywords.TYPENAME);
} }
private static final Set FUNCTION_MODIFIER_C = EMPTY_TABLE; private static final Set<String> FUNCTION_MODIFIER_C = EMPTY_TABLE;
private static final Set FUNCTION_MODIFIER_CPP; private static final Set<String> FUNCTION_MODIFIER_CPP;
static static
{ {
FUNCTION_MODIFIER_CPP = new TreeSet( FUNCTION_MODIFIER_C ); FUNCTION_MODIFIER_CPP = new TreeSet<String>( FUNCTION_MODIFIER_C );
FUNCTION_MODIFIER_CPP.add( Keywords.THROW); FUNCTION_MODIFIER_CPP.add( Keywords.THROW);
FUNCTION_MODIFIER_CPP.add( Keywords.TRY ); FUNCTION_MODIFIER_CPP.add( Keywords.TRY );
FUNCTION_MODIFIER_CPP.add( Keywords.VOLATILE ); FUNCTION_MODIFIER_CPP.add( Keywords.VOLATILE );
} }
private static final Hashtable FUNCTION_MODIFIER_TABLE; private static final Map<ParserLanguage,Set<String>> FUNCTION_MODIFIER_TABLE;
static static
{ {
FUNCTION_MODIFIER_TABLE= new Hashtable(2); FUNCTION_MODIFIER_TABLE= new HashMap<ParserLanguage,Set<String>>(2);
FUNCTION_MODIFIER_TABLE.put( ParserLanguage.CPP, FUNCTION_MODIFIER_CPP ); FUNCTION_MODIFIER_TABLE.put( ParserLanguage.CPP, FUNCTION_MODIFIER_CPP );
FUNCTION_MODIFIER_TABLE.put( ParserLanguage.C, FUNCTION_MODIFIER_C ); FUNCTION_MODIFIER_TABLE.put( ParserLanguage.C, FUNCTION_MODIFIER_C );
} }
private static final Set PP_DIRECTIVES_C; private static final Set<String> PP_DIRECTIVES_C;
static static
{ {
PP_DIRECTIVES_C = new TreeSet(); PP_DIRECTIVES_C = new TreeSet<String>();
PP_DIRECTIVES_C.add(Directives.POUND_BLANK); PP_DIRECTIVES_C.add(Directives.POUND_BLANK);
PP_DIRECTIVES_C.add(Directives.POUND_DEFINE); PP_DIRECTIVES_C.add(Directives.POUND_DEFINE);
PP_DIRECTIVES_C.add(Directives.POUND_UNDEF); PP_DIRECTIVES_C.add(Directives.POUND_UNDEF);
@ -330,10 +331,10 @@ public class KeywordSets {
} }
private static final Set PP_DIRECTIVES_CPP; private static final Set<String> PP_DIRECTIVES_CPP;
static static
{ {
PP_DIRECTIVES_CPP = new TreeSet(); PP_DIRECTIVES_CPP = new TreeSet<String>();
PP_DIRECTIVES_CPP.add(Directives.POUND_BLANK); PP_DIRECTIVES_CPP.add(Directives.POUND_BLANK);
PP_DIRECTIVES_CPP.add(Directives.POUND_DEFINE); PP_DIRECTIVES_CPP.add(Directives.POUND_DEFINE);
PP_DIRECTIVES_CPP.add(Directives.POUND_UNDEF); PP_DIRECTIVES_CPP.add(Directives.POUND_UNDEF);
@ -349,10 +350,10 @@ public class KeywordSets {
PP_DIRECTIVES_CPP.add(Directives.POUND_ELIF); PP_DIRECTIVES_CPP.add(Directives.POUND_ELIF);
} }
private static final Set ALL_C; private static final Set<String> ALL_C;
static static
{ {
ALL_C = new TreeSet(PP_DIRECTIVES_CPP); ALL_C = new TreeSet<String>(PP_DIRECTIVES_CPP);
ALL_C.add( Keywords.AUTO); ALL_C.add( Keywords.AUTO);
ALL_C.add( Keywords.BREAK); ALL_C.add( Keywords.BREAK);
ALL_C.add( Keywords.CASE); ALL_C.add( Keywords.CASE);
@ -393,10 +394,10 @@ public class KeywordSets {
ALL_C.add( Keywords._IMAGINARY); ALL_C.add( Keywords._IMAGINARY);
} }
private static final Set ALL_CPP; private static final Set<String> ALL_CPP;
static static
{ {
ALL_CPP = new TreeSet(PP_DIRECTIVES_CPP); ALL_CPP = new TreeSet<String>(PP_DIRECTIVES_CPP);
ALL_CPP.add( Keywords.AND ); ALL_CPP.add( Keywords.AND );
ALL_CPP.add( Keywords.AND_EQ); ALL_CPP.add( Keywords.AND_EQ);
ALL_CPP.add( Keywords.ASM); ALL_CPP.add( Keywords.ASM);
@ -473,18 +474,18 @@ public class KeywordSets {
ALL_CPP.add( Keywords.XOR_EQ); ALL_CPP.add( Keywords.XOR_EQ);
} }
private static final Hashtable ALL_TABLE; private static final Map<ParserLanguage,Set<String>> ALL_TABLE;
static static
{ {
ALL_TABLE = new Hashtable( 2 ); ALL_TABLE = new HashMap<ParserLanguage,Set<String>>( 2 );
ALL_TABLE.put( ParserLanguage.C, ALL_C ); ALL_TABLE.put( ParserLanguage.C, ALL_C );
ALL_TABLE.put( ParserLanguage.CPP, ALL_CPP ); ALL_TABLE.put( ParserLanguage.CPP, ALL_CPP );
} }
private static final Set KEYWORDS_CPP; private static final Set<String> KEYWORDS_CPP;
static static
{ {
KEYWORDS_CPP = new TreeSet(); KEYWORDS_CPP = new TreeSet<String>();
KEYWORDS_CPP.add( Keywords.AND ); KEYWORDS_CPP.add( Keywords.AND );
KEYWORDS_CPP.add( Keywords.AND_EQ ); KEYWORDS_CPP.add( Keywords.AND_EQ );
KEYWORDS_CPP.add( Keywords.ASM ); KEYWORDS_CPP.add( Keywords.ASM );
@ -552,10 +553,10 @@ public class KeywordSets {
} }
private static Set KEYWORDS_C; private static Set<String> KEYWORDS_C;
static static
{ {
KEYWORDS_C = new TreeSet(); KEYWORDS_C = new TreeSet<String>();
KEYWORDS_C.add( Keywords.ASM ); KEYWORDS_C.add( Keywords.ASM );
KEYWORDS_C.add( Keywords.AUTO ); KEYWORDS_C.add( Keywords.AUTO );
KEYWORDS_C.add( Keywords.BREAK ); KEYWORDS_C.add( Keywords.BREAK );
@ -586,18 +587,18 @@ public class KeywordSets {
private static final Hashtable KEYWORDS_TABLE; private static final Map<ParserLanguage,Set<String>> KEYWORDS_TABLE;
static static
{ {
KEYWORDS_TABLE = new Hashtable(2); KEYWORDS_TABLE = new HashMap<ParserLanguage,Set<String>>(2);
KEYWORDS_TABLE.put( ParserLanguage.C, KEYWORDS_C ); KEYWORDS_TABLE.put( ParserLanguage.C, KEYWORDS_C );
KEYWORDS_TABLE.put( ParserLanguage.CPP, KEYWORDS_CPP ); KEYWORDS_TABLE.put( ParserLanguage.CPP, KEYWORDS_CPP );
} }
private static final Set TYPES_C; private static final Set<String> TYPES_C;
static static
{ {
TYPES_C = new TreeSet(); TYPES_C = new TreeSet<String>();
TYPES_C.add( Keywords.CHAR ); TYPES_C.add( Keywords.CHAR );
TYPES_C.add( Keywords.DOUBLE ); TYPES_C.add( Keywords.DOUBLE );
TYPES_C.add( Keywords.FLOAT ); TYPES_C.add( Keywords.FLOAT );
@ -611,10 +612,10 @@ public class KeywordSets {
TYPES_C.add( Keywords._COMPLEX ); TYPES_C.add( Keywords._COMPLEX );
TYPES_C.add( Keywords._IMAGINARY ); TYPES_C.add( Keywords._IMAGINARY );
} }
private static final Set TYPES_CPP; private static final Set<String> TYPES_CPP;
static static
{ {
TYPES_CPP = new TreeSet(); TYPES_CPP = new TreeSet<String>();
TYPES_CPP.add( Keywords.BOOL ); TYPES_CPP.add( Keywords.BOOL );
TYPES_CPP.add( Keywords.CHAR ); TYPES_CPP.add( Keywords.CHAR );
TYPES_CPP.add( Keywords.DOUBLE ); TYPES_CPP.add( Keywords.DOUBLE );
@ -628,18 +629,18 @@ public class KeywordSets {
TYPES_CPP.add( Keywords.WCHAR_T ); TYPES_CPP.add( Keywords.WCHAR_T );
} }
private static Hashtable TYPES_TABLE; private static Map<ParserLanguage,Set<String>> TYPES_TABLE;
static static
{ {
TYPES_TABLE = new Hashtable( 2 ); TYPES_TABLE = new HashMap<ParserLanguage, Set<String>>( 2 );
TYPES_TABLE.put( ParserLanguage.C, TYPES_C ); TYPES_TABLE.put( ParserLanguage.C, TYPES_C );
TYPES_TABLE.put( ParserLanguage.CPP, TYPES_CPP ); TYPES_TABLE.put( ParserLanguage.CPP, TYPES_CPP );
} }
private static Hashtable PP_DIRECTIVES_TABLE; private static Map<ParserLanguage,Set<String>> PP_DIRECTIVES_TABLE;
static static
{ {
PP_DIRECTIVES_TABLE = new Hashtable( 2 ); PP_DIRECTIVES_TABLE = new HashMap<ParserLanguage,Set<String>>( 2 );
PP_DIRECTIVES_TABLE.put( ParserLanguage.C, PP_DIRECTIVES_C ); PP_DIRECTIVES_TABLE.put( ParserLanguage.C, PP_DIRECTIVES_C );
PP_DIRECTIVES_TABLE.put( ParserLanguage.CPP, PP_DIRECTIVES_CPP ); PP_DIRECTIVES_TABLE.put( ParserLanguage.CPP, PP_DIRECTIVES_CPP );
} }