Fix regression; did not gen enter/exit in alt label structs.
This commit is contained in:
parent
c6fd897287
commit
71b75c88dd
|
@ -5,16 +5,8 @@ s : e ;
|
|||
e : e '*' e -> Mult
|
||||
| e '+' e -> Add
|
||||
| INT -> primary
|
||||
| ID -> primary
|
||||
| '(' e ')' -> Parens
|
||||
;
|
||||
|
||||
/*
|
||||
primary : EEE;
|
||||
|
||||
add : A ;
|
||||
*/
|
||||
|
||||
ID : [a-z]+ ;
|
||||
INT : [0-9]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import org.antlr.v4.runtime.tree.*;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public interface AVisitor<T> {
|
||||
T visitMult(AParser.MultContext ctx);
|
||||
T visitParens(AParser.ParensContext ctx);
|
||||
|
|
|
@ -33,24 +33,27 @@ public class TestVisitor {
|
|||
public static class MyVisitor extends ABaseVisitor<Integer> implements AVisitor<Integer> {
|
||||
@Override
|
||||
public Integer visitAdd(AParser.AddContext ctx) {
|
||||
return ctx.e(0).accept(this) + ctx.e(1).accept(this);
|
||||
return visit(ctx.e(0)) + visit(ctx.e(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitMult(AParser.MultContext ctx) {
|
||||
// return ctx.e(0).accept(this) * ctx.e(1).accept(this);
|
||||
return visit(ctx.e(0)) * visit(ctx.e(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitParens(AParser.ParensContext ctx) {
|
||||
return ctx.e().accept(this);
|
||||
return visit(ctx.e());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitS(AParser.SContext ctx) {
|
||||
return visit(ctx.e());
|
||||
//return ctx.e().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visitPrimary(AParser.PrimaryContext ctx) {
|
||||
return Integer.valueOf(ctx.INT().getText());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,11 @@
|
|||
package org.antlr.v4.codegen.model.decl;
|
||||
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.codegen.model.VisitorDispatchMethod;
|
||||
import org.antlr.v4.codegen.model.*;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** A StructDecl to handle a -> label on alt */
|
||||
public class AltLabelStructDecl extends StructDecl {
|
||||
public int altNum;
|
||||
|
@ -42,13 +44,15 @@ public class AltLabelStructDecl extends StructDecl {
|
|||
super(factory, r);
|
||||
this.altNum = altNum;
|
||||
this.name = // override name set in super to the label ctx
|
||||
factory.getGenerator().target.getAltLabelContextStructName(label);
|
||||
factory.getGenerator().target.getAltLabelContextStructName(label);
|
||||
derivedFromName = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDispatchMethods(Rule r) {
|
||||
super.addDispatchMethods(r);
|
||||
dispatchMethods = new ArrayList<DispatchMethod>();
|
||||
dispatchMethods.add(new ListenerDispatchMethod(factory, true));
|
||||
dispatchMethods.add(new ListenerDispatchMethod(factory, false));
|
||||
if ( factory.getGrammar().tool.gen_visitor ) {
|
||||
dispatchMethods.add(new VisitorDispatchMethod(factory));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue