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

Refactored the C99 preprocessor to use IPPTokenComparator, removes dependancy on the C99 parser token types

This commit is contained in:
Mike Kucera 2007-07-10 20:25:33 +00:00
parent 975140ab8a
commit 27da9e732e
5 changed files with 75 additions and 57 deletions

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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();
}

View file

@ -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;
}
}