Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/upc
diff options
context:
space:
mode:
authorMike Kucera2007-07-10 20:25:33 +0000
committerMike Kucera2007-07-10 20:25:33 +0000
commit27da9e732eaf1b62b99a30d807c21122ea8736b1 (patch)
treefc0ba2fc94be0c53e4d3732880bbf79b6d481209 /upc
parent975140ab8abe1e699334b53c4895f82c22d107a5 (diff)
downloadorg.eclipse.cdt-27da9e732eaf1b62b99a30d807c21122ea8736b1.tar.gz
org.eclipse.cdt-27da9e732eaf1b62b99a30d807c21122ea8736b1.tar.xz
org.eclipse.cdt-27da9e732eaf1b62b99a30d807c21122ea8736b1.zip
Refactored the C99 preprocessor to use IPPTokenComparator, removes dependancy on the C99 parser token types
Diffstat (limited to 'upc')
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java10
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCPPTokenComparator.java65
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.g1
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.java7
-rw-r--r--upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCTokenMap.java49
5 files changed, 75 insertions, 57 deletions
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java
index aba0324d724..35320d73bdd 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/core/dom/upc/UPCLanguage.java
@@ -13,14 +13,14 @@ package org.eclipse.cdt.core.dom.upc;
import org.eclipse.cdt.core.dom.c99.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.c99.IKeywordMap;
import org.eclipse.cdt.core.dom.c99.ILexerFactory;
+import org.eclipse.cdt.core.dom.c99.IPPTokenComparator;
import org.eclipse.cdt.core.dom.c99.IParser;
import org.eclipse.cdt.core.dom.c99.IPreprocessorExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c99.GCCPreprocessorExtensionConfiguration;
-import org.eclipse.cdt.core.dom.parser.c99.ITokenMap;
import org.eclipse.cdt.core.dom.parser.upc.UPCKeywordMap;
import org.eclipse.cdt.internal.core.dom.parser.upc.UPCLexerFactory;
+import org.eclipse.cdt.internal.core.dom.parser.upc.UPCPPTokenComparator;
import org.eclipse.cdt.internal.core.dom.parser.upc.UPCParser;
-import org.eclipse.cdt.internal.core.dom.parser.upc.UPCTokenMap;
/**
@@ -72,8 +72,8 @@ public class UPCLanguage extends BaseExtensibleLanguage {
protected ILexerFactory getLexerFactory() {
return new UPCLexerFactory();
}
-
- protected ITokenMap getTokenMap() {
- return new UPCTokenMap();
+
+ protected IPPTokenComparator getTokenComparator() {
+ return new UPCPPTokenComparator();
}
}
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCPPTokenComparator.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCPPTokenComparator.java
new file mode 100644
index 00000000000..4b2ccdccb1b
--- /dev/null
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCPPTokenComparator.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+* Copyright (c) 2006, 2007 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.internal.core.dom.parser.upc;
+
+import org.eclipse.cdt.core.dom.c99.IPPTokenComparator;
+import org.eclipse.cdt.core.dom.parser.c99.IToken;
+import org.eclipse.cdt.core.dom.parser.c99.PPToken;
+
+public class UPCPPTokenComparator implements IPPTokenComparator {
+
+ public boolean compare(PPToken pptoken, IToken token) {
+ if(token == null)
+ return false;
+
+ switch(token.getKind()) {
+ case UPCParsersym.TK_Hash : return pptoken == PPToken.HASH;
+ case UPCParsersym.TK_HashHash : return pptoken == PPToken.HASHHASH;
+ case UPCParsersym.TK_LeftParen : return pptoken == PPToken.LPAREN;
+ case UPCParsersym.TK_NewLine : return pptoken == PPToken.NEWLINE;
+ case UPCParsersym.TK_Comma : return pptoken == PPToken.COMMA;
+ case UPCParsersym.TK_RightParen : return pptoken == PPToken.RPAREN;
+ case UPCParsersym.TK_DotDotDot : return pptoken == PPToken.DOTDOTDOT;
+ case UPCParsersym.TK_EOF_TOKEN : return pptoken == PPToken.EOF;
+ case UPCParsersym.TK_stringlit : return pptoken == PPToken.STRINGLIT;
+ case UPCParsersym.TK_integer : return pptoken == PPToken.INTEGER;
+ case UPCParsersym.TK_LT : return pptoken == PPToken.LEFT_ANGLE_BRACKET;
+ case UPCParsersym.TK_GT : return pptoken == PPToken.RIGHT_ANGLE_BRACKET;
+ case UPCParsersym.TK_SingleLineComment : return pptoken == PPToken.SINGLE_LINE_COMMENT;
+ case UPCParsersym.TK_MultiLineComment : return pptoken == PPToken.MULTI_LINE_COMMENT;
+ // an identifier might be a preprocessing directive like #if or #include
+ case UPCParsersym.TK_identifier :
+ PPToken result = PPToken.getDirective(token.toString());
+ return pptoken == ((result == null) ? PPToken.IDENT : result);
+ }
+ return false;
+ }
+
+
+ public int getKind(int tokenToMake) {
+ switch(tokenToMake) {
+ case KIND_IDENTIFIER : return UPCParsersym.TK_identifier;
+ case KIND_EOF : return UPCParsersym.TK_EOF_TOKEN;
+ case KIND_COMPLETION : return UPCParsersym.TK_Completion;
+ case KIND_END_OF_COMPLETION : return UPCParsersym.TK_EndOfCompletion;
+ case KIND_INTEGER : return UPCParsersym.TK_integer;
+ case KIND_STRINGLIT : return UPCParsersym.TK_stringlit;
+ case KIND_INVALID : return UPCParsersym.TK_Invalid;
+ default : return UPCParsersym.TK_Invalid;
+ }
+ }
+
+
+ public String[] getLPGOrderedTerminalSymbols() {
+ return UPCParsersym.orderedTerminalSymbols;
+ }
+}
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.g b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.g
index 0d05e725d99..e67ec75c7aa 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.g
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.g
@@ -30,6 +30,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c99.C99Lexer;
import org.eclipse.cdt.internal.core.dom.parser.c99.C99Parsersym;
import org.eclipse.cdt.core.dom.parser.upc.UPCKeywordMap;
import org.eclipse.cdt.core.dom.parser.upc.UPCParserAction;
+import org.eclipse.cdt.internal.core.dom.parser.c99.C99TokenMap;
./
$End
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.java
index 66b1ed7ef15..6c5850a5e3d 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.java
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCParser.java
@@ -34,6 +34,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c99.C99Lexer;
import org.eclipse.cdt.internal.core.dom.parser.c99.C99Parsersym;
import org.eclipse.cdt.core.dom.parser.upc.UPCKeywordMap;
import org.eclipse.cdt.core.dom.parser.upc.UPCParserAction;
+import org.eclipse.cdt.internal.core.dom.parser.c99.C99TokenMap;
public class UPCParser extends PrsStream implements RuleAction , IParserActionTokenProvider, IParser
{
@@ -91,7 +92,7 @@ public class UPCParser extends PrsStream implements RuleAction , IParserActionTo
for (int i = 0; i < unimplemented_symbols.size(); i++)
{
Integer id = (Integer) unimplemented_symbols.get(i);
- System.out.println(" " + UPCParsersym.orderedTerminalSymbols[id.intValue()]);//$NON-NLS-1$
+ System.out.println(" " + UPCParsersym.orderedTerminalSymbols[id.intValue()]); //$NON-NLS-1$
}
System.out.println();
}
@@ -172,7 +173,7 @@ public class UPCParser extends PrsStream implements RuleAction , IParserActionTo
}
-private UPCParserAction action = new UPCParserAction (this, new UPCTokenMap ());
+private UPCParserAction action = new UPCParserAction (this, new C99TokenMap(UPCParserprs.orderedTerminalSymbols));
private List commentTokens = new ArrayList();
private IKeywordMap keywordMap = new UPCKeywordMap ();
@@ -202,7 +203,7 @@ public List getCommentTokens() {
public void resetTokenStream() {
super.resetTokenStream();
- action = new UPCParserAction (this, new UPCTokenMap ());
+ action = new UPCParserAction (this, new C99TokenMap(UPCParserprs.orderedTerminalSymbols));
commentTokens = new ArrayList();
}
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCTokenMap.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCTokenMap.java
deleted file mode 100644
index bff71c08ff2..00000000000
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/UPCTokenMap.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2006, 2007 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.internal.core.dom.parser.upc;
-
-import org.eclipse.cdt.core.dom.parser.c99.TokenMap;
-
-public class UPCTokenMap extends TokenMap {
-
- public UPCTokenMap() {
- super(UPCParsersym.orderedTerminalSymbols);
- }
-
- public int getCompletionTokenKind() {
- return UPCParsersym.TK_Completion;
- }
-
- public int getEOFTokenKind() {
- return UPCParsersym.TK_EOF_TOKEN;
- }
-
- public int getEndOfCompletionTokenKind() {
- return UPCParsersym.TK_EndOfCompletion;
- }
-
- public int getIntegerTokenKind() {
- return UPCParsersym.TK_integer;
- }
-
- public int getInvalidTokenKind() {
- return UPCParsersym.TK_Invalid;
- }
-
- public int getStringLitTokenKind() {
- return UPCParsersym.TK_stringlit;
- }
-
- public int getIdentifierTokenKind() {
- return UPCParsersym.TK_identifier;
- }
-
-}

Back to the top