mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Changes to C99 parser (in anticipation of adding C++ support): simplified the keyword maps, extracted a base class for the parser actions, created a better way to map tokens.
This commit is contained in:
parent
04e799d307
commit
8f87510587
4 changed files with 79 additions and 79 deletions
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.upc;
|
||||
|
||||
import org.eclipse.cdt.core.dom.parser.c99.LPGKeywordMap;
|
||||
import org.eclipse.cdt.core.dom.parser.c99.C99KeywordMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym;
|
||||
|
||||
|
@ -21,82 +22,84 @@ import org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym;
|
|||
*
|
||||
* @author Mike Kucera
|
||||
*/
|
||||
public class UPCKeywordMap extends C99KeywordMap {
|
||||
|
||||
|
||||
public static final String
|
||||
MYTHREAD = "MYTHREAD",//$NON-NLS-1$
|
||||
THREADS = "THREADS",//$NON-NLS-1$
|
||||
UPC_MAX_BLOCKSIZE = "UPC_MAX_BLOCKSIZE",//$NON-NLS-1$
|
||||
relaxed = "relaxed",//$NON-NLS-1$
|
||||
shared = "shared",//$NON-NLS-1$
|
||||
strict = "strict",//$NON-NLS-1$
|
||||
upc_barrier = "upc_barrier",//$NON-NLS-1$
|
||||
upc_localsizeof = "upc_localsizeof",//$NON-NLS-1$
|
||||
upc_blocksizeof = "upc_blocksizeof",//$NON-NLS-1$
|
||||
upc_elemsizeof = "upc_elemsizeof",//$NON-NLS-1$
|
||||
upc_notify = "upc_notify",//$NON-NLS-1$
|
||||
upc_fence = "upc_fence",//$NON-NLS-1$
|
||||
upc_wait = "upc_wait",//$NON-NLS-1$
|
||||
upc_forall = "upc_forall";//$NON-NLS-1$
|
||||
public class UPCKeywordMap extends LPGKeywordMap {
|
||||
|
||||
|
||||
public UPCKeywordMap() {
|
||||
putKeyword(MYTHREAD, UPCParsersym.TK_MYTHREAD);
|
||||
putKeyword(THREADS, UPCParsersym.TK_THREADS);
|
||||
putKeyword(UPC_MAX_BLOCKSIZE, UPCParsersym.TK_UPC_MAX_BLOCKSIZE);
|
||||
putKeyword(relaxed, UPCParsersym.TK_relaxed);
|
||||
putKeyword(shared, UPCParsersym.TK_shared);
|
||||
putKeyword(strict, UPCParsersym.TK_strict);
|
||||
putKeyword(upc_barrier, UPCParsersym.TK_upc_barrier);
|
||||
putKeyword(upc_localsizeof, UPCParsersym.TK_upc_localsizeof);
|
||||
putKeyword(upc_blocksizeof, UPCParsersym.TK_upc_blocksizeof);
|
||||
putKeyword(upc_elemsizeof, UPCParsersym.TK_upc_elemsizeof);
|
||||
putKeyword(upc_notify, UPCParsersym.TK_upc_notify);
|
||||
putKeyword(upc_fence, UPCParsersym.TK_upc_fence);
|
||||
putKeyword(upc_wait, UPCParsersym.TK_upc_wait);
|
||||
putKeyword(upc_forall, UPCParsersym.TK_upc_forall);
|
||||
putKeyword(UPCParsersym.TK_MYTHREAD);
|
||||
putKeyword(UPCParsersym.TK_THREADS);
|
||||
putKeyword(UPCParsersym.TK_UPC_MAX_BLOCKSIZE);
|
||||
putKeyword(UPCParsersym.TK_relaxed);
|
||||
putKeyword(UPCParsersym.TK_shared);
|
||||
putKeyword(UPCParsersym.TK_strict);
|
||||
putKeyword(UPCParsersym.TK_upc_barrier);
|
||||
putKeyword(UPCParsersym.TK_upc_localsizeof);
|
||||
putKeyword(UPCParsersym.TK_upc_blocksizeof);
|
||||
putKeyword(UPCParsersym.TK_upc_elemsizeof);
|
||||
putKeyword(UPCParsersym.TK_upc_notify);
|
||||
putKeyword(UPCParsersym.TK_upc_fence);
|
||||
putKeyword(UPCParsersym.TK_upc_wait);
|
||||
putKeyword(UPCParsersym.TK_upc_forall);
|
||||
|
||||
// The keyword token mappings from the superclass must be overridden.
|
||||
// This is because LPG generates totally different values for token
|
||||
// kinds every time you genereate a parser.
|
||||
putKeyword(AUTO, UPCParsersym.TK_auto);
|
||||
putKeyword(BREAK, UPCParsersym.TK_break);
|
||||
putKeyword(CASE, UPCParsersym.TK_case);
|
||||
putKeyword(CHAR, UPCParsersym.TK_char);
|
||||
putKeyword(CONST, UPCParsersym.TK_const);
|
||||
putKeyword(CONTINUE, UPCParsersym.TK_continue);
|
||||
putKeyword(DEFAULT, UPCParsersym.TK_default);
|
||||
putKeyword(DO, UPCParsersym.TK_do);
|
||||
putKeyword(DOUBLE, UPCParsersym.TK_double);
|
||||
putKeyword(ELSE, UPCParsersym.TK_else);
|
||||
putKeyword(ENUM, UPCParsersym.TK_enum);
|
||||
putKeyword(EXTERN, UPCParsersym.TK_extern);
|
||||
putKeyword(FLOAT, UPCParsersym.TK_float);
|
||||
putKeyword(FOR, UPCParsersym.TK_for);
|
||||
putKeyword(GOTO, UPCParsersym.TK_goto);
|
||||
putKeyword(IF, UPCParsersym.TK_if);
|
||||
putKeyword(INLINE, UPCParsersym.TK_inline);
|
||||
putKeyword(INT, UPCParsersym.TK_int);
|
||||
putKeyword(LONG, UPCParsersym.TK_long);
|
||||
putKeyword(REGISTER, UPCParsersym.TK_register);
|
||||
putKeyword(RESTRICT, UPCParsersym.TK_restrict);
|
||||
putKeyword(RETURN, UPCParsersym.TK_return);
|
||||
putKeyword(SHORT, UPCParsersym.TK_short);
|
||||
putKeyword(SIGNED, UPCParsersym.TK_signed);
|
||||
putKeyword(SIZEOF, UPCParsersym.TK_sizeof);
|
||||
putKeyword(STATIC, UPCParsersym.TK_static);
|
||||
putKeyword(STRUCT, UPCParsersym.TK_struct);
|
||||
putKeyword(SWITCH, UPCParsersym.TK_switch);
|
||||
putKeyword(TYPEDEF, UPCParsersym.TK_typedef);
|
||||
putKeyword(UNION, UPCParsersym.TK_union);
|
||||
putKeyword(UNSIGNED, UPCParsersym.TK_unsigned);
|
||||
putKeyword(VOID, UPCParsersym.TK_void);
|
||||
putKeyword(VOLATILE, UPCParsersym.TK_volatile);
|
||||
putKeyword(WHILE, UPCParsersym.TK_while);
|
||||
putKeyword(_BOOL, UPCParsersym.TK__Bool);
|
||||
putKeyword(_COMPLEX, UPCParsersym.TK__Complex);
|
||||
putKeyword(_IMAGINARY, UPCParsersym.TK__Imaginary);
|
||||
// kinds every time you generate a parser.
|
||||
putKeyword(UPCParsersym.TK_auto);
|
||||
putKeyword(UPCParsersym.TK_break);
|
||||
putKeyword(UPCParsersym.TK_case);
|
||||
putKeyword(UPCParsersym.TK_char);
|
||||
putKeyword(UPCParsersym.TK_const);
|
||||
putKeyword(UPCParsersym.TK_continue);
|
||||
putKeyword(UPCParsersym.TK_default);
|
||||
putKeyword(UPCParsersym.TK_do);
|
||||
putKeyword(UPCParsersym.TK_double);
|
||||
putKeyword(UPCParsersym.TK_else);
|
||||
putKeyword(UPCParsersym.TK_enum);
|
||||
putKeyword(UPCParsersym.TK_extern);
|
||||
putKeyword(UPCParsersym.TK_float);
|
||||
putKeyword(UPCParsersym.TK_for);
|
||||
putKeyword(UPCParsersym.TK_goto);
|
||||
putKeyword(UPCParsersym.TK_if);
|
||||
putKeyword(UPCParsersym.TK_inline);
|
||||
putKeyword(UPCParsersym.TK_int);
|
||||
putKeyword(UPCParsersym.TK_long);
|
||||
putKeyword(UPCParsersym.TK_register);
|
||||
putKeyword(UPCParsersym.TK_restrict);
|
||||
putKeyword(UPCParsersym.TK_return);
|
||||
putKeyword(UPCParsersym.TK_short);
|
||||
putKeyword(UPCParsersym.TK_signed);
|
||||
putKeyword(UPCParsersym.TK_sizeof);
|
||||
putKeyword(UPCParsersym.TK_static);
|
||||
putKeyword(UPCParsersym.TK_struct);
|
||||
putKeyword(UPCParsersym.TK_switch);
|
||||
putKeyword(UPCParsersym.TK_typedef);
|
||||
putKeyword(UPCParsersym.TK_union);
|
||||
putKeyword(UPCParsersym.TK_unsigned);
|
||||
putKeyword(UPCParsersym.TK_void);
|
||||
putKeyword(UPCParsersym.TK_volatile);
|
||||
putKeyword(UPCParsersym.TK_while);
|
||||
putKeyword(UPCParsersym.TK__Bool);
|
||||
putKeyword(UPCParsersym.TK__Complex);
|
||||
putKeyword(UPCParsersym.TK__Imaginary);
|
||||
|
||||
|
||||
addBuiltinType(UPCParsersym.TK_char);
|
||||
addBuiltinType(UPCParsersym.TK_double);
|
||||
addBuiltinType(UPCParsersym.TK_float);
|
||||
addBuiltinType(UPCParsersym.TK_int);
|
||||
addBuiltinType(UPCParsersym.TK_long);
|
||||
addBuiltinType(UPCParsersym.TK_short);
|
||||
addBuiltinType(UPCParsersym.TK_signed);
|
||||
addBuiltinType(UPCParsersym.TK_unsigned);
|
||||
addBuiltinType(UPCParsersym.TK_void);
|
||||
addBuiltinType(UPCParsersym.TK__Bool);
|
||||
addBuiltinType(UPCParsersym.TK__Complex);
|
||||
addBuiltinType(UPCParsersym.TK__Imaginary);
|
||||
}
|
||||
|
||||
|
||||
protected String[] getOrderedTerminalSymbols() {
|
||||
return UPCParsersym.orderedTerminalSymbols;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,12 +42,11 @@ import org.eclipse.cdt.internal.core.dom.parser.upc.UPCParsersym;
|
|||
public class UPCParserAction extends C99ParserAction {
|
||||
|
||||
private final UPCASTNodeFactory nodeFactory;
|
||||
private final ASTStack astStack;
|
||||
|
||||
|
||||
public UPCParserAction(IParserActionTokenProvider parser, ITokenMap tokenMap) {
|
||||
super(parser, tokenMap);
|
||||
this.astStack = super.getASTStack();
|
||||
public UPCParserAction(IParserActionTokenProvider parser) {
|
||||
super(parser);
|
||||
super.setTokenMap(UPCParsersym.orderedTerminalSymbols);
|
||||
this.nodeFactory = (UPCASTNodeFactory) super.getNodeFactory();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ 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
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ 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
|
||||
{
|
||||
|
@ -92,7 +91,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()]);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
@ -173,7 +172,7 @@ public class UPCParser extends PrsStream implements RuleAction , IParserActionTo
|
|||
}
|
||||
|
||||
|
||||
private UPCParserAction action = new UPCParserAction (this, new C99TokenMap(UPCParserprs.orderedTerminalSymbols));
|
||||
private UPCParserAction action = new UPCParserAction (this);
|
||||
private List commentTokens = new ArrayList();
|
||||
private IKeywordMap keywordMap = new UPCKeywordMap ();
|
||||
|
||||
|
@ -203,7 +202,7 @@ public List getCommentTokens() {
|
|||
|
||||
public void resetTokenStream() {
|
||||
super.resetTokenStream();
|
||||
action = new UPCParserAction (this, new C99TokenMap(UPCParserprs.orderedTerminalSymbols));
|
||||
action = new UPCParserAction (this);
|
||||
commentTokens = new ArrayList();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue