From 8885aa0fbd8e4cbaf3c672bf98fab3256b99dd42 Mon Sep 17 00:00:00 2001
From: jespergravgaard The default implementation does nothing. The default implementation does nothing. The default implementation does nothing. The default implementation does nothing. The default implementation does nothing.
The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.
- */ - @Override public T visitTypedefName(TypedefParser.TypedefNameContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.
- */ - @Override public T visitValueName(TypedefParser.ValueNameContext ctx) { return visitChildren(ctx); } } \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.java b/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.java index 98b5fa25a..8113fb105 100644 --- a/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.java +++ b/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.java @@ -17,7 +17,8 @@ public class TypedefLexer extends Lexer { protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int - T__0=1, T__1=2, T__2=3, SIMPLETYPE=4, IDENTIFIER=5, WHITESPACE=6; + T__0=1, T__1=2, T__2=3, IDENTIFIER=4, SIMPLETYPE=5, TYPEIDENTIFIER=6, + WHITESPACE=7; public static String[] channelNames = { "DEFAULT_TOKEN_CHANNEL", "HIDDEN" }; @@ -27,14 +28,16 @@ public class TypedefLexer extends Lexer { }; public static final String[] ruleNames = { - "T__0", "T__1", "T__2", "SIMPLETYPE", "IDENTIFIER", "WHITESPACE" + "T__0", "T__1", "T__2", "IDENTIFIER", "SIMPLETYPE", "TYPEIDENTIFIER", + "WHITESPACE" }; private static final String[] _LITERAL_NAMES = { null, "'('", "')'", "'&'" }; private static final String[] _SYMBOLIC_NAMES = { - null, null, null, null, "SIMPLETYPE", "IDENTIFIER", "WHITESPACE" + null, null, null, null, "IDENTIFIER", "SIMPLETYPE", "TYPEIDENTIFIER", + "WHITESPACE" }; public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); @@ -93,19 +96,47 @@ public class TypedefLexer extends Lexer { @Override public ATN getATN() { return _ATN; } + @Override + public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { + switch (ruleIndex) { + case 3: + return IDENTIFIER_sempred((RuleContext)_localctx, predIndex); + case 5: + return TYPEIDENTIFIER_sempred((RuleContext)_localctx, predIndex); + } + return true; + } + private boolean IDENTIFIER_sempred(RuleContext _localctx, int predIndex) { + switch (predIndex) { + case 0: + return !getText().equals("T"); + } + return true; + } + private boolean TYPEIDENTIFIER_sempred(RuleContext _localctx, int predIndex) { + switch (predIndex) { + case 1: + return getText().equals("T"); + } + return true; + } + public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\b*\b\1\4\2\t\2\4"+ - "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5"+ - "\3\5\3\5\3\5\3\5\3\5\5\5\35\n\5\3\6\6\6 \n\6\r\6\16\6!\3\7\6\7%\n\7\r"+ - "\7\16\7&\3\7\3\7\2\2\b\3\3\5\4\7\5\t\6\13\7\r\b\3\2\4\5\2C\\aac|\5\2\13"+ - "\f\17\17\"\"\2,\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3"+ - "\2\2\2\2\r\3\2\2\2\3\17\3\2\2\2\5\21\3\2\2\2\7\23\3\2\2\2\t\34\3\2\2\2"+ - "\13\37\3\2\2\2\r$\3\2\2\2\17\20\7*\2\2\20\4\3\2\2\2\21\22\7+\2\2\22\6"+ - "\3\2\2\2\23\24\7(\2\2\24\b\3\2\2\2\25\26\7e\2\2\26\27\7j\2\2\27\30\7c"+ - "\2\2\30\35\7t\2\2\31\32\7k\2\2\32\33\7p\2\2\33\35\7v\2\2\34\25\3\2\2\2"+ - "\34\31\3\2\2\2\35\n\3\2\2\2\36 \t\2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\2\2\2*+\3\2\2\2+,\3\2\2\2,-\6\7\3\2-\16\3\2\2\2"+ + ".\60\t\3\2\2/.\3\2\2\2\60\61\3\2\2\2\61/\3\2\2\2\61\62\3\2\2\2\62\63\3"+ + "\2\2\2\63\64\b\b\2\2\64\20\3\2\2\2\7\2\32%*\61\3\b\2\2"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { diff --git a/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.tokens b/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.tokens index 4b6fb9d93..321e470ea 100644 --- a/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.tokens +++ b/src/test/java/dk/camelot64/kickc/parsing/TypedefLexer.tokens @@ -1,9 +1,10 @@ T__0=1 T__1=2 T__2=3 -SIMPLETYPE=4 -IDENTIFIER=5 -WHITESPACE=6 +IDENTIFIER=4 +SIMPLETYPE=5 +TYPEIDENTIFIER=6 +WHITESPACE=7 '('=1 ')'=2 '&'=3 diff --git a/src/test/java/dk/camelot64/kickc/parsing/TypedefListener.java b/src/test/java/dk/camelot64/kickc/parsing/TypedefListener.java index a17d49cd7..d2b276f06 100644 --- a/src/test/java/dk/camelot64/kickc/parsing/TypedefListener.java +++ b/src/test/java/dk/camelot64/kickc/parsing/TypedefListener.java @@ -91,24 +91,4 @@ public interface TypedefListener extends ParseTreeListener { * @param ctx the parse tree */ void exitTypeNameTypedef(TypedefParser.TypeNameTypedefContext ctx); - /** - * Enter a parse tree produced by {@link TypedefParser#typedefName}. - * @param ctx the parse tree - */ - void enterTypedefName(TypedefParser.TypedefNameContext ctx); - /** - * Exit a parse tree produced by {@link TypedefParser#typedefName}. - * @param ctx the parse tree - */ - void exitTypedefName(TypedefParser.TypedefNameContext ctx); - /** - * Enter a parse tree produced by {@link TypedefParser#valueName}. - * @param ctx the parse tree - */ - void enterValueName(TypedefParser.ValueNameContext ctx); - /** - * Exit a parse tree produced by {@link TypedefParser#valueName}. - * @param ctx the parse tree - */ - void exitValueName(TypedefParser.ValueNameContext ctx); } \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/parsing/TypedefParser.java b/src/test/java/dk/camelot64/kickc/parsing/TypedefParser.java index fe8df445a..4447d14e8 100644 --- a/src/test/java/dk/camelot64/kickc/parsing/TypedefParser.java +++ b/src/test/java/dk/camelot64/kickc/parsing/TypedefParser.java @@ -17,18 +17,20 @@ public class TypedefParser extends Parser { protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int - T__0=1, T__1=2, T__2=3, SIMPLETYPE=4, IDENTIFIER=5, WHITESPACE=6; + T__0=1, T__1=2, T__2=3, IDENTIFIER=4, SIMPLETYPE=5, TYPEIDENTIFIER=6, + WHITESPACE=7; public static final int - RULE_expr = 0, RULE_typeName = 1, RULE_typedefName = 2, RULE_valueName = 3; + RULE_expr = 0, RULE_typeName = 1; public static final String[] ruleNames = { - "expr", "typeName", "typedefName", "valueName" + "expr", "typeName" }; private static final String[] _LITERAL_NAMES = { null, "'('", "')'", "'&'" }; private static final String[] _SYMBOLIC_NAMES = { - null, null, null, null, "SIMPLETYPE", "IDENTIFIER", "WHITESPACE" + null, null, null, null, "IDENTIFIER", "SIMPLETYPE", "TYPEIDENTIFIER", + "WHITESPACE" }; public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); @@ -91,9 +93,7 @@ public class TypedefParser extends Parser { } } public static class ExprValueNameContext extends ExprContext { - public ValueNameContext valueName() { - return getRuleContext(ValueNameContext.class,0); - } + public TerminalNode IDENTIFIER() { return getToken(TypedefParser.IDENTIFIER, 0); } public ExprValueNameContext(ExprContext ctx) { copyFrom(ctx); } @Override public void enterRule(ParseTreeListener listener) { @@ -207,61 +207,61 @@ public class TypedefParser extends Parser { int _alt; enterOuterAlt(_localctx, 1); { - setState(21); + setState(17); _errHandler.sync(this); switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) { case 1: { - _localctx = new ExprValueNameContext(_localctx); + _localctx = new ExprCastContext(_localctx); _ctx = _localctx; _prevctx = _localctx; - setState(9); - valueName(); + setState(5); + match(T__0); + setState(6); + typeName(); + setState(7); + match(T__1); + setState(8); + expr(5); } break; case 2: { - _localctx = new ExprParenthesisContext(_localctx); + _localctx = new ExprValueNameContext(_localctx); _ctx = _localctx; _prevctx = _localctx; setState(10); - match(T__0); - setState(11); - expr(0); - setState(12); - match(T__1); + match(IDENTIFIER); } break; case 3: { - _localctx = new ExprAddressOfContext(_localctx); + _localctx = new ExprParenthesisContext(_localctx); _ctx = _localctx; _prevctx = _localctx; - setState(14); - match(T__2); - setState(15); - expr(3); + setState(11); + match(T__0); + setState(12); + expr(0); + setState(13); + match(T__1); } break; case 4: { - _localctx = new ExprCastContext(_localctx); + _localctx = new ExprAddressOfContext(_localctx); _ctx = _localctx; _prevctx = _localctx; + setState(15); + match(T__2); setState(16); - match(T__0); - setState(17); - typeName(); - setState(18); - match(T__1); - setState(19); - expr(1); + expr(2); } break; } _ctx.stop = _input.LT(-1); - setState(28); + setState(24); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input,1,_ctx); while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { @@ -272,16 +272,16 @@ public class TypedefParser extends Parser { { _localctx = new ExprAndContext(new ExprContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expr); - setState(23); - if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)"); - setState(24); + setState(19); + if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(20); match(T__2); - setState(25); - expr(3); + setState(21); + expr(2); } } } - setState(30); + setState(26); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input,1,_ctx); } @@ -310,9 +310,7 @@ public class TypedefParser extends Parser { } } public static class TypeNameTypedefContext extends TypeNameContext { - public TypedefNameContext typedefName() { - return getRuleContext(TypedefNameContext.class,0); - } + public TerminalNode TYPEIDENTIFIER() { return getToken(TypedefParser.TYPEIDENTIFIER, 0); } public TypeNameTypedefContext(TypeNameContext ctx) { copyFrom(ctx); } @Override public void enterRule(ParseTreeListener listener) { @@ -350,23 +348,23 @@ public class TypedefParser extends Parser { TypeNameContext _localctx = new TypeNameContext(_ctx, getState()); enterRule(_localctx, 2, RULE_typeName); try { - setState(33); + setState(29); _errHandler.sync(this); switch (_input.LA(1)) { case SIMPLETYPE: _localctx = new TypeNameSimpleContext(_localctx); enterOuterAlt(_localctx, 1); { - setState(31); + setState(27); match(SIMPLETYPE); } break; - case IDENTIFIER: + case TYPEIDENTIFIER: _localctx = new TypeNameTypedefContext(_localctx); enterOuterAlt(_localctx, 2); { - setState(32); - typedefName(); + setState(28); + match(TYPEIDENTIFIER); } break; default: @@ -384,90 +382,6 @@ public class TypedefParser extends Parser { return _localctx; } - public static class TypedefNameContext extends ParserRuleContext { - public TerminalNode IDENTIFIER() { return getToken(TypedefParser.IDENTIFIER, 0); } - public TypedefNameContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_typedefName; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof TypedefListener ) ((TypedefListener)listener).enterTypedefName(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof TypedefListener ) ((TypedefListener)listener).exitTypedefName(this); - } - @Override - public