mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:28:03 +00:00
Ids are gotten explicitly from the IDENTIFIER
This commit is contained in:
parent
dbca4ac327
commit
bbfdbd51dc
@ -24,16 +24,16 @@ public class ASTGenerator {
|
|||||||
if (ctx.meth() != null) {
|
if (ctx.meth() != null) {
|
||||||
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
|
meths = ctx.meth().stream().map(ASTGenerator::generateMethod).toList();
|
||||||
}
|
}
|
||||||
return new Class(ctx.id().getText(), declarations, meths, constructors);
|
return new Class(ctx.id().IDENTIFIER().getText(), declarations, meths, constructors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Declaration generateFieldVariable(DecafParser.FieldContext ctx) {
|
public static Declaration generateFieldVariable(DecafParser.FieldContext ctx) {
|
||||||
Type type = ASTGenerator.getType(ctx.type());
|
Type type = ASTGenerator.getType(ctx.type());
|
||||||
return new Declaration(ctx.id().getText(), type);
|
return new Declaration(ctx.id().IDENTIFIER().getText(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Parameter generateParameter(DecafParser.ParamContext ctx) {
|
public static Parameter generateParameter(DecafParser.ParamContext ctx) {
|
||||||
return new Parameter(ctx.id().getText(), getType(ctx.type()));
|
return new Parameter(ctx.id().IDENTIFIER().getText(), getType(ctx.type()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Method generateMethod(DecafParser.MethContext ctx) {
|
public static Method generateMethod(DecafParser.MethContext ctx) {
|
||||||
@ -42,7 +42,7 @@ public class ASTGenerator {
|
|||||||
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
|
params = ctx.params().param().stream().map(ASTGenerator::generateParameter).toList();
|
||||||
}
|
}
|
||||||
Block block = new BlockGenerator().visit(ctx.block());
|
Block block = new BlockGenerator().visit(ctx.block());
|
||||||
return new Method(getType(ctx.returntype()), ctx.id().getText(), params, block);
|
return new Method(getType(ctx.returntype()), ctx.id().IDENTIFIER().getText(), params, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Constructor generateConstructor(DecafParser.ConstructorContext ctx) {
|
public static Constructor generateConstructor(DecafParser.ConstructorContext ctx) {
|
||||||
|
@ -97,7 +97,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
Expression astExpr = expr.accept(this);
|
Expression astExpr = expr.accept(this);
|
||||||
args.add(astExpr);
|
args.add(astExpr);
|
||||||
}
|
}
|
||||||
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().getText()), args);
|
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().IDENTIFIER().getText()), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -118,7 +118,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
DecafParser.RecipientContext ctx = ctxList.get(0);
|
DecafParser.RecipientContext ctx = ctxList.get(0);
|
||||||
ctxList.remove(0);
|
ctxList.remove(0);
|
||||||
if (ctx.id() != null) {
|
if (ctx.id() != null) {
|
||||||
return new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.id().getText());
|
return new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.id().IDENTIFIER().getText());
|
||||||
}
|
}
|
||||||
if (ctx.methName() != null) {
|
if (ctx.methName() != null) {
|
||||||
List<Expression> args = new ArrayList<>();
|
List<Expression> args = new ArrayList<>();
|
||||||
@ -127,7 +127,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
Expression astExpr = expr.accept(new ExpressionGenerator());
|
Expression astExpr = expr.accept(new ExpressionGenerator());
|
||||||
args.add(astExpr);
|
args.add(astExpr);
|
||||||
}
|
}
|
||||||
return new MethodCall(new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.methName().id().getText()), args);
|
return new MethodCall(new FieldVarAccess(false, generateRecursiveOwnerChain(ctxList, recipient), ctx.methName().id().IDENTIFIER().getText()), args);
|
||||||
|
|
||||||
}
|
}
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
@ -75,7 +75,7 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
|||||||
private FieldVarAccess generateField(DecafParser.FieldVarAccessContext fieldIdContext) {
|
private FieldVarAccess generateField(DecafParser.FieldVarAccessContext fieldIdContext) {
|
||||||
return new FieldVarAccess(fieldIdContext.THIS() != null,
|
return new FieldVarAccess(fieldIdContext.THIS() != null,
|
||||||
ExpressionGenerator.generateRecursiveOwnerChain(fieldIdContext.recipient(),
|
ExpressionGenerator.generateRecursiveOwnerChain(fieldIdContext.recipient(),
|
||||||
null), fieldIdContext.id().getText());
|
null), fieldIdContext.id().IDENTIFIER().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
//StatementExpression
|
//StatementExpression
|
||||||
@ -92,7 +92,7 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
|||||||
Expression astExpr = expr.accept(new ExpressionGenerator());
|
Expression astExpr = expr.accept(new ExpressionGenerator());
|
||||||
args.add(astExpr);
|
args.add(astExpr);
|
||||||
}
|
}
|
||||||
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().getText()), args);
|
return new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().IDENTIFIER().getText()), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,6 +11,6 @@ public class VariableGenerator extends DecafBaseVisitor<Declaration> {
|
|||||||
@Override
|
@Override
|
||||||
public Declaration visitLocalVar(DecafParser.LocalVarContext ctx) {
|
public Declaration visitLocalVar(DecafParser.LocalVarContext ctx) {
|
||||||
Type type = ASTGenerator.getType(ctx.type());
|
Type type = ASTGenerator.getType(ctx.type());
|
||||||
return new Declaration(ctx.id().getText(), type);
|
return new Declaration(ctx.id().IDENTIFIER().getText(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user