Handling Merge

This commit is contained in:
Ahmad 2024-05-08 15:19:03 +02:00
commit b0fea68f05
10 changed files with 338 additions and 341 deletions

View File

@ -43,10 +43,10 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
@Override
public Expression visitIdentifier(DecafParser.IdentifierContext ctx) {
boolean isField = ctx.fieldId().THIS() != null;
boolean isField = ctx.fieldVarAccess().THIS() != null;
Expression recipient = null;
if (ctx.fieldId().recipient() != null) {
List<DecafParser.RecipientContext> recipientList = ctx.fieldId().recipient();
if (ctx.fieldVarAccess().recipient() != null) {
List<DecafParser.RecipientContext> recipientList = ctx.fieldVarAccess().recipient();
recipient = generateRecursiveOwnerChain(recipientList, null);
}
return new FieldVarAccess(isField, recipient, ctx.getText());

View File

@ -67,12 +67,12 @@ public class StatementGenerator extends DecafBaseVisitor<Statement> {
}
private Assignment generateAssign(DecafParser.AssignContext ctx) {
FieldVarAccess fieldVarAccess = generateField(ctx.fieldId());
FieldVarAccess fieldVarAccess = generateField(ctx.fieldVarAccess());
Expression expr = resolveFancyAssign(ctx.assignSign(), fieldVarAccess, new ExpressionGenerator().visit(ctx.expr()));
return new Assignment(fieldVarAccess, expr);
}
private FieldVarAccess generateField(DecafParser.FieldIdContext fieldIdContext) {
private FieldVarAccess generateField(DecafParser.FieldVarAccessContext fieldIdContext) {
return new FieldVarAccess(fieldIdContext.THIS() != null,
ExpressionGenerator.generateRecursiveOwnerChain(fieldIdContext.recipient(),
null), fieldIdContext.id().getText());

File diff suppressed because one or more lines are too long

View File

@ -401,13 +401,13 @@ public class DecafBaseListener implements DecafListener {
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterFieldId(DecafParser.FieldIdContext ctx) { }
@Override public void enterFieldVarAccess(DecafParser.FieldVarAccessContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitFieldId(DecafParser.FieldIdContext ctx) { }
@Override public void exitFieldVarAccess(DecafParser.FieldVarAccessContext ctx) { }
/**
* {@inheritDoc}
*

View File

@ -242,7 +242,7 @@ public class DecafBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitFieldId(DecafParser.FieldIdContext ctx) { return visitChildren(ctx); }
@Override public T visitFieldVarAccess(DecafParser.FieldVarAccessContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*

File diff suppressed because one or more lines are too long

View File

@ -123,7 +123,7 @@ public class DecafLexer extends Lexer {
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\u0004\u0000/\u0120\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
"\u0004\u0000/\u012a\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
"\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+
"\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+
"\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+
@ -161,14 +161,15 @@ public class DecafLexer extends Lexer {
"\'\u0001\'\u0001\'\u0001\'\u0001\'\u0001\'\u0001\'\u0001\'\u0001(\u0001"+
"(\u0001(\u0001(\u0001(\u0001)\u0001)\u0001)\u0001)\u0001)\u0001*\u0001"+
"*\u0001*\u0001*\u0001*\u0001*\u0001*\u0001*\u0001*\u0003*\u010d\b*\u0001"+
"+\u0001+\u0001+\u0001+\u0001,\u0004,\u0114\b,\u000b,\f,\u0115\u0001-\u0004"+
"-\u0119\b-\u000b-\f-\u011a\u0001.\u0001.\u0001.\u0001.\u0000\u0000/\u0001"+
"+\u0001+\u0001+\u0001+\u0001,\u0004,\u0114\b,\u000b,\f,\u0115\u0001,\u0005"+
",\u0119\b,\n,\f,\u011c\t,\u0004,\u011e\b,\u000b,\f,\u011f\u0001-\u0004"+
"-\u0123\b-\u000b-\f-\u0124\u0001.\u0001.\u0001.\u0001.\u0000\u0000/\u0001"+
"\u0001\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007"+
"\u000f\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e\u001d"+
"\u000f\u001f\u0010!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017/"+
"\u00181\u00193\u001a5\u001b7\u001c9\u001d;\u001e=\u001f? A!C\"E#G$I%K"+
"&M\'O(Q)S*U+W,Y-[.]/\u0001\u0000\u0004\u0001\u0000\'\'\u0002\u0000AZa"+
"z\u0001\u000009\u0003\u0000\t\n\r\r \u0122\u0000\u0001\u0001\u0000\u0000"+
"z\u0001\u000009\u0003\u0000\t\n\r\r \u012e\u0000\u0001\u0001\u0000\u0000"+
"\u0000\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000"+
"\u0000\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000"+
"\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000"+
@ -209,8 +210,8 @@ public class DecafLexer extends Lexer {
"\u0000K\u00eb\u0001\u0000\u0000\u0000M\u00ed\u0001\u0000\u0000\u0000O"+
"\u00f1\u0001\u0000\u0000\u0000Q\u00f9\u0001\u0000\u0000\u0000S\u00fe\u0001"+
"\u0000\u0000\u0000U\u010c\u0001\u0000\u0000\u0000W\u010e\u0001\u0000\u0000"+
"\u0000Y\u0113\u0001\u0000\u0000\u0000[\u0118\u0001\u0000\u0000\u0000]"+
"\u011c\u0001\u0000\u0000\u0000_`\u0005c\u0000\u0000`a\u0005l\u0000\u0000"+
"\u0000Y\u011d\u0001\u0000\u0000\u0000[\u0122\u0001\u0000\u0000\u0000]"+
"\u0126\u0001\u0000\u0000\u0000_`\u0005c\u0000\u0000`a\u0005l\u0000\u0000"+
"ab\u0005a\u0000\u0000bc\u0005s\u0000\u0000cd\u0005s\u0000\u0000d\u0002"+
"\u0001\u0000\u0000\u0000ef\u0005{\u0000\u0000f\u0004\u0001\u0000\u0000"+
"\u0000gh\u0005}\u0000\u0000h\u0006\u0001\u0000\u0000\u0000ij\u0005;\u0000"+
@ -287,13 +288,19 @@ public class DecafLexer extends Lexer {
"\u0000\u0000\u0110\u0111\u0007\u0000\u0000\u0000\u0111X\u0001\u0000\u0000"+
"\u0000\u0112\u0114\u0007\u0001\u0000\u0000\u0113\u0112\u0001\u0000\u0000"+
"\u0000\u0114\u0115\u0001\u0000\u0000\u0000\u0115\u0113\u0001\u0000\u0000"+
"\u0000\u0115\u0116\u0001\u0000\u0000\u0000\u0116Z\u0001\u0000\u0000\u0000"+
"\u0117\u0119\u0007\u0002\u0000\u0000\u0118\u0117\u0001\u0000\u0000\u0000"+
"\u0119\u011a\u0001\u0000\u0000\u0000\u011a\u0118\u0001\u0000\u0000\u0000"+
"\u011a\u011b\u0001\u0000\u0000\u0000\u011b\\\u0001\u0000\u0000\u0000\u011c"+
"\u011d\u0007\u0003\u0000\u0000\u011d\u011e\u0001\u0000\u0000\u0000\u011e"+
"\u011f\u0006.\u0000\u0000\u011f^\u0001\u0000\u0000\u0000\u0004\u0000\u010c"+
"\u0115\u011a\u0001\u0006\u0000\u0000";
"\u0000\u0115\u0116\u0001\u0000\u0000\u0000\u0116\u011a\u0001\u0000\u0000"+
"\u0000\u0117\u0119\u0007\u0002\u0000\u0000\u0118\u0117\u0001\u0000\u0000"+
"\u0000\u0119\u011c\u0001\u0000\u0000\u0000\u011a\u0118\u0001\u0000\u0000"+
"\u0000\u011a\u011b\u0001\u0000\u0000\u0000\u011b\u011e\u0001\u0000\u0000"+
"\u0000\u011c\u011a\u0001\u0000\u0000\u0000\u011d\u0113\u0001\u0000\u0000"+
"\u0000\u011e\u011f\u0001\u0000\u0000\u0000\u011f\u011d\u0001\u0000\u0000"+
"\u0000\u011f\u0120\u0001\u0000\u0000\u0000\u0120Z\u0001\u0000\u0000\u0000"+
"\u0121\u0123\u0007\u0002\u0000\u0000\u0122\u0121\u0001\u0000\u0000\u0000"+
"\u0123\u0124\u0001\u0000\u0000\u0000\u0124\u0122\u0001\u0000\u0000\u0000"+
"\u0124\u0125\u0001\u0000\u0000\u0000\u0125\\\u0001\u0000\u0000\u0000\u0126"+
"\u0127\u0007\u0003\u0000\u0000\u0127\u0128\u0001\u0000\u0000\u0000\u0128"+
"\u0129\u0006.\u0000\u0000\u0129^\u0001\u0000\u0000\u0000\u0006\u0000\u010c"+
"\u0115\u011a\u011f\u0124\u0001\u0006\u0000\u0000";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@ -364,15 +364,15 @@ public interface DecafListener extends ParseTreeListener {
*/
void exitUnaryOp(DecafParser.UnaryOpContext ctx);
/**
* Enter a parse tree produced by {@link DecafParser#fieldId}.
* Enter a parse tree produced by {@link DecafParser#fieldVarAccess}.
* @param ctx the parse tree
*/
void enterFieldId(DecafParser.FieldIdContext ctx);
void enterFieldVarAccess(DecafParser.FieldVarAccessContext ctx);
/**
* Exit a parse tree produced by {@link DecafParser#fieldId}.
* Exit a parse tree produced by {@link DecafParser#fieldVarAccess}.
* @param ctx the parse tree
*/
void exitFieldId(DecafParser.FieldIdContext ctx);
void exitFieldVarAccess(DecafParser.FieldVarAccessContext ctx);
/**
* Enter a parse tree produced by {@link DecafParser#assign}.
* @param ctx the parse tree

File diff suppressed because it is too large Load Diff

View File

@ -221,11 +221,11 @@ public interface DecafVisitor<T> extends ParseTreeVisitor<T> {
*/
T visitUnaryOp(DecafParser.UnaryOpContext ctx);
/**
* Visit a parse tree produced by {@link DecafParser#fieldId}.
* Visit a parse tree produced by {@link DecafParser#fieldVarAccess}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitFieldId(DecafParser.FieldIdContext ctx);
T visitFieldVarAccess(DecafParser.FieldVarAccessContext ctx);
/**
* Visit a parse tree produced by {@link DecafParser#assign}.
* @param ctx the parse tree