mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-22 03:29:59 +00:00
Succesfully made proof-of-concept for distinguishing type identifiers (typedefs) from other identifiers. #269
This commit is contained in:
parent
2de0744639
commit
8885aa0fbd
@ -17,10 +17,9 @@ public class TestTypedefParser {
|
||||
assertEquals("and((val:a),val:b)", parseExprTypedef("(a)&b"));
|
||||
// char is a simple type - resolving to cast of simple type
|
||||
assertEquals("cast(simpletype:char,addressof(val:b))", parseExprTypedef("(char)&b"));
|
||||
|
||||
// TODO: Fix typedef identification during lexer phase!
|
||||
// T is typedeffed - so this should resolve to a cast of typedef
|
||||
//assertEquals("cast(typedef:T,addressof(val:b))", parseExprTypedef("(T)&b"));
|
||||
assertEquals("cast(typedef:T,addressof(val:b))", parseExprTypedef("(T)&b"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,57 +1,32 @@
|
||||
/*
|
||||
[The "BSD licence"]
|
||||
Copyright (c) 2013 Sam Harwell
|
||||
All rights reserved.
|
||||
/**
|
||||
*
|
||||
* Minimal grammar illustrating the C typedef ambiguity problem
|
||||
* (x)&y can have two meanings:
|
||||
* - cast address-of y to type x
|
||||
* - binary and of x and y
|
||||
*
|
||||
* Resolving the ambiguity requires the compiler to know whether x is a type or a value.
|
||||
* This is handled using predicates during the Lexer Phase to create different tokens (IDENTIFIER vs TYPEDEF)
|
||||
*/
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/** C 2011 grammar built from the C11 Spec */
|
||||
grammar Typedef;
|
||||
|
||||
expr
|
||||
: valueName #exprValueName
|
||||
: '(' typeName ')' expr #exprCast
|
||||
| IDENTIFIER #exprValueName
|
||||
| '(' expr ')' #exprParenthesis
|
||||
| '&' expr #exprAddressOf
|
||||
| expr '&' expr #exprAnd
|
||||
| '(' typeName ')' expr #exprCast
|
||||
;
|
||||
|
||||
typeName
|
||||
: SIMPLETYPE #typeNameSimple
|
||||
| typedefName #typeNameTypedef
|
||||
;
|
||||
|
||||
typedefName
|
||||
: IDENTIFIER
|
||||
;
|
||||
|
||||
valueName
|
||||
: IDENTIFIER
|
||||
| TYPEIDENTIFIER #typeNameTypedef
|
||||
;
|
||||
|
||||
IDENTIFIER: [a-zA-Z_]+ {!getText().equals("T")}?;
|
||||
SIMPLETYPE: 'char' | 'int';
|
||||
IDENTIFIER : [a-zA-Z_]+ ;
|
||||
TYPEIDENTIFIER: [a-zA-Z_]+ {getText().equals("T")}?;
|
||||
WHITESPACE
|
||||
: [ \t\r\n]+
|
||||
-> skip
|
||||
|
@ -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
|
||||
|
@ -95,30 +95,6 @@ public class TypedefBaseListener implements TypedefListener {
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitTypeNameTypedef(TypedefParser.TypeNameTypedefContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterTypedefName(TypedefParser.TypedefNameContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitTypedefName(TypedefParser.TypedefNameContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterValueName(TypedefParser.ValueNameContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitValueName(TypedefParser.ValueNameContext ctx) { }
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -60,18 +60,4 @@ public class TypedefBaseVisitor<T> extends AbstractParseTreeVisitor<T> implement
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitTypeNameTypedef(TypedefParser.TypeNameTypedefContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitTypedefName(TypedefParser.TypedefNameContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitValueName(TypedefParser.ValueNameContext ctx) { return visitChildren(ctx); }
|
||||
}
|
@ -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\2\2\37\36\3\2\2\2 !\3\2\2\2!\37\3"+
|
||||
"\2\2\2!\"\3\2\2\2\"\f\3\2\2\2#%\t\3\2\2$#\3\2\2\2%&\3\2\2\2&$\3\2\2\2"+
|
||||
"&\'\3\2\2\2\'(\3\2\2\2()\b\7\2\2)\16\3\2\2\2\6\2\34!&\3\b\2\2";
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\t\65\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\4\b\t\b\3\2\3\2\3\3\3\3\3\4\3"+
|
||||
"\4\3\5\6\5\31\n\5\r\5\16\5\32\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\6\3\6\5\6"+
|
||||
"&\n\6\3\7\6\7)\n\7\r\7\16\7*\3\7\3\7\3\b\6\b\60\n\b\r\b\16\b\61\3\b\3"+
|
||||
"\b\2\2\t\3\3\5\4\7\5\t\6\13\7\r\b\17\t\3\2\4\5\2C\\aac|\5\2\13\f\17\17"+
|
||||
"\"\"\28\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\2\17\3\2\2\2\3\21\3\2\2\2\5\23\3\2\2\2\7\25\3\2\2\2\t\30\3"+
|
||||
"\2\2\2\13%\3\2\2\2\r(\3\2\2\2\17/\3\2\2\2\21\22\7*\2\2\22\4\3\2\2\2\23"+
|
||||
"\24\7+\2\2\24\6\3\2\2\2\25\26\7(\2\2\26\b\3\2\2\2\27\31\t\2\2\2\30\27"+
|
||||
"\3\2\2\2\31\32\3\2\2\2\32\30\3\2\2\2\32\33\3\2\2\2\33\34\3\2\2\2\34\35"+
|
||||
"\6\5\2\2\35\n\3\2\2\2\36\37\7e\2\2\37 \7j\2\2 !\7c\2\2!&\7t\2\2\"#\7k"+
|
||||
"\2\2#$\7p\2\2$&\7v\2\2%\36\3\2\2\2%\"\3\2\2\2&\f\3\2\2\2\')\t\2\2\2(\'"+
|
||||
"\3\2\2\2)*\3\2\2\2*(\3\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 {
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
@ -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 <T> T accept(ParseTreeVisitor<? extends T> visitor) {
|
||||
if ( visitor instanceof TypedefVisitor ) return ((TypedefVisitor<? extends T>)visitor).visitTypedefName(this);
|
||||
else return visitor.visitChildren(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final TypedefNameContext typedefName() throws RecognitionException {
|
||||
TypedefNameContext _localctx = new TypedefNameContext(_ctx, getState());
|
||||
enterRule(_localctx, 4, RULE_typedefName);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(35);
|
||||
match(IDENTIFIER);
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class ValueNameContext extends ParserRuleContext {
|
||||
public TerminalNode IDENTIFIER() { return getToken(TypedefParser.IDENTIFIER, 0); }
|
||||
public ValueNameContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_valueName; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof TypedefListener ) ((TypedefListener)listener).enterValueName(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof TypedefListener ) ((TypedefListener)listener).exitValueName(this);
|
||||
}
|
||||
@Override
|
||||
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
|
||||
if ( visitor instanceof TypedefVisitor ) return ((TypedefVisitor<? extends T>)visitor).visitValueName(this);
|
||||
else return visitor.visitChildren(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final ValueNameContext valueName() throws RecognitionException {
|
||||
ValueNameContext _localctx = new ValueNameContext(_ctx, getState());
|
||||
enterRule(_localctx, 6, RULE_valueName);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(37);
|
||||
match(IDENTIFIER);
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
|
||||
switch (ruleIndex) {
|
||||
case 0:
|
||||
@ -478,23 +392,22 @@ public class TypedefParser extends Parser {
|
||||
private boolean expr_sempred(ExprContext _localctx, int predIndex) {
|
||||
switch (predIndex) {
|
||||
case 0:
|
||||
return precpred(_ctx, 2);
|
||||
return precpred(_ctx, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\b*\4\2\t\2\4\3\t"+
|
||||
"\3\4\4\t\4\4\5\t\5\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2"+
|
||||
"\5\2\30\n\2\3\2\3\2\3\2\7\2\35\n\2\f\2\16\2 \13\2\3\3\3\3\5\3$\n\3\3\4"+
|
||||
"\3\4\3\5\3\5\3\5\2\3\2\6\2\4\6\b\2\2\2*\2\27\3\2\2\2\4#\3\2\2\2\6%\3\2"+
|
||||
"\2\2\b\'\3\2\2\2\n\13\b\2\1\2\13\30\5\b\5\2\f\r\7\3\2\2\r\16\5\2\2\2\16"+
|
||||
"\17\7\4\2\2\17\30\3\2\2\2\20\21\7\5\2\2\21\30\5\2\2\5\22\23\7\3\2\2\23"+
|
||||
"\24\5\4\3\2\24\25\7\4\2\2\25\26\5\2\2\3\26\30\3\2\2\2\27\n\3\2\2\2\27"+
|
||||
"\f\3\2\2\2\27\20\3\2\2\2\27\22\3\2\2\2\30\36\3\2\2\2\31\32\f\4\2\2\32"+
|
||||
"\33\7\5\2\2\33\35\5\2\2\5\34\31\3\2\2\2\35 \3\2\2\2\36\34\3\2\2\2\36\37"+
|
||||
"\3\2\2\2\37\3\3\2\2\2 \36\3\2\2\2!$\7\6\2\2\"$\5\6\4\2#!\3\2\2\2#\"\3"+
|
||||
"\2\2\2$\5\3\2\2\2%&\7\7\2\2&\7\3\2\2\2\'(\7\7\2\2(\t\3\2\2\2\5\27\36#";
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\t\"\4\2\t\2\4\3\t"+
|
||||
"\3\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\5\2\24\n\2\3\2"+
|
||||
"\3\2\3\2\7\2\31\n\2\f\2\16\2\34\13\2\3\3\3\3\5\3 \n\3\3\3\2\3\2\4\2\4"+
|
||||
"\2\2\2$\2\23\3\2\2\2\4\37\3\2\2\2\6\7\b\2\1\2\7\b\7\3\2\2\b\t\5\4\3\2"+
|
||||
"\t\n\7\4\2\2\n\13\5\2\2\7\13\24\3\2\2\2\f\24\7\6\2\2\r\16\7\3\2\2\16\17"+
|
||||
"\5\2\2\2\17\20\7\4\2\2\20\24\3\2\2\2\21\22\7\5\2\2\22\24\5\2\2\4\23\6"+
|
||||
"\3\2\2\2\23\f\3\2\2\2\23\r\3\2\2\2\23\21\3\2\2\2\24\32\3\2\2\2\25\26\f"+
|
||||
"\3\2\2\26\27\7\5\2\2\27\31\5\2\2\4\30\25\3\2\2\2\31\34\3\2\2\2\32\30\3"+
|
||||
"\2\2\2\32\33\3\2\2\2\33\3\3\2\2\2\34\32\3\2\2\2\35 \7\7\2\2\36 \7\b\2"+
|
||||
"\2\37\35\3\2\2\2\37\36\3\2\2\2 \5\3\2\2\2\5\23\32\37";
|
||||
public static final ATN _ATN =
|
||||
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
|
||||
static {
|
||||
|
@ -59,16 +59,4 @@ public interface TypedefVisitor<T> extends ParseTreeVisitor<T> {
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitTypeNameTypedef(TypedefParser.TypeNameTypedefContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link TypedefParser#typedefName}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitTypedefName(TypedefParser.TypedefNameContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link TypedefParser#valueName}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitValueName(TypedefParser.ValueNameContext ctx);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user