forked from JavaTX/JavaCompilerCore
StatementGenerator fertiggestellt
This commit is contained in:
parent
d362858184
commit
09cc88062e
@ -328,13 +328,13 @@ qualifiedName
|
|||||||
;
|
;
|
||||||
|
|
||||||
literal
|
literal
|
||||||
: integerLiteral
|
: integerLiteral # intLiteral
|
||||||
| floatLiteral
|
| floatLiteral # fltLiteral
|
||||||
| CHAR_LITERAL
|
| CHAR_LITERAL # charLiteral
|
||||||
| STRING_LITERAL
|
| STRING_LITERAL # stringLiteral
|
||||||
| BOOL_LITERAL
|
| BOOL_LITERAL # boolLiteral
|
||||||
| NULL_LITERAL
|
| NULL_LITERAL # nullLiteral
|
||||||
| TEXT_BLOCK // Java17
|
| TEXT_BLOCK # textBlock // Java17
|
||||||
;
|
;
|
||||||
|
|
||||||
integerLiteral
|
integerLiteral
|
||||||
@ -675,13 +675,13 @@ lambdaBody
|
|||||||
;
|
;
|
||||||
|
|
||||||
primary
|
primary
|
||||||
: '(' expression ')'
|
: '(' expression ')' # primaryExpression
|
||||||
| THIS
|
| THIS # primaryThis
|
||||||
| SUPER
|
| SUPER # primarySuper
|
||||||
| literal
|
| literal # primaryLiteral
|
||||||
| identifier
|
| identifier # primaryIdentifier
|
||||||
| refType '.' CLASS
|
| refType '.' CLASS # primaryClassref
|
||||||
| nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments)
|
| nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments) # primaryInvocation
|
||||||
;
|
;
|
||||||
|
|
||||||
// Java17
|
// Java17
|
||||||
|
@ -1,65 +1,110 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.AndexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ArrayaccessexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ArrayaccessexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.AssertstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.AssertstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.AssignexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.AssignexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwiseandexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwiseandexpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwiseorexpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwisexorexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.BlockstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.BlockstmtContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.BoolLiteralContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.BreakstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.BreakstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.CastexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.CastexpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.CharLiteralContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ConditionalassignexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ConditionalstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ConditionalstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ContinuestmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ContinuestmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.DottedexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.DottedexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ForControlContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.DowhileloopContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.EqualityexpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ExpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.FltLiteralContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ForloopContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ForloopContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.IdentifierContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.IdentifierContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.IntLiteralContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.LabeledstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.LabeledstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.LambdaLVTIParameterContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.LambdaLVTIParameterContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.LambdaexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.LambdaexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.MathaddsubexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.MathaddsubexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.MathmuldivmodexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.MathmuldivmodexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodcallexpressionContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodCallContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodCallContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodcallexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.NewinstanceexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.NewinstanceexpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.NullLiteralContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.OrexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PostfixexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PostfixexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrefixexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrefixexpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryClassrefContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryExpressionContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryIdentifierContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryInvocationContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryLiteralContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimarySuperContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryThisContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.RelationalexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.RelationalexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ReturnstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ReturnstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SemistmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SemistmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ShiftexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ShiftexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.StmtexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.StmtexpressionContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchexpressionContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.StringLiteralContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchexpressionstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchexpressionstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SynchronizedstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SynchronizedstmtContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.TextBlockContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ThrowstmtContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ThrowstmtContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.WhileloopContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.YieldstmtContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.DowhileloopContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.EqualityexpressionContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ExpressionContext;
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchblockContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchblockContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchresourceContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchresourceContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TypeArgumentsContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.WhileloopContext;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.YieldstmtContext;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr.Operation;
|
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class StatementGenerator {
|
public class StatementGenerator {
|
||||||
|
|
||||||
@ -134,17 +179,25 @@ public class StatementGenerator {
|
|||||||
case StmtexpressionContext stmtexpression:
|
case StmtexpressionContext stmtexpression:
|
||||||
return convert(stmtexpression);
|
return convert(stmtexpression);
|
||||||
case AssertstmtContext assertstmt:
|
case AssertstmtContext assertstmt:
|
||||||
/*
|
return convert(assertstmt);
|
||||||
* case ForloopContext forloop:
|
case ForloopContext forloop:
|
||||||
* case TrycatchblockContext trycatchblock:
|
return convert(forloop);
|
||||||
* case TrycatchresourceContext trycatchresource:
|
case TrycatchblockContext trycatchblock:
|
||||||
* case SynchronizedstmtContext synchronizedstmt:
|
return convert(trycatchblock);
|
||||||
* case ThrowstmtContext throwstmt:
|
case TrycatchresourceContext trycatchresource:
|
||||||
* case BreakstmtContext breakstmt:
|
return convert(trycatchresource);
|
||||||
* case ContinuestmtContext continuestmt:
|
case SynchronizedstmtContext synchronizedstmt:
|
||||||
* case SemistmtContext semistmt:
|
return convert(synchronizedstmt);
|
||||||
* case LabeledstmtContext labeledstmt:
|
case ThrowstmtContext throwstmt:
|
||||||
*/
|
return convert(throwstmt);
|
||||||
|
case BreakstmtContext breakstmt:
|
||||||
|
return convert(breakstmt);
|
||||||
|
case ContinuestmtContext continuestmt:
|
||||||
|
return convert(continuestmt);
|
||||||
|
case SemistmtContext semistmt:
|
||||||
|
return convert(semistmt);
|
||||||
|
case LabeledstmtContext labeledstmt:
|
||||||
|
return convert(labeledstmt);
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -219,13 +272,21 @@ public class StatementGenerator {
|
|||||||
|
|
||||||
RefType newclass = convert(creator.createdName());
|
RefType newclass = convert(creator.createdName());
|
||||||
|
|
||||||
ArgumentList args = convertArguments(creator.classCreatorRest().arguments().expressionList());
|
if (!Objects.isNull(creator.classCreatorRest())) {
|
||||||
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
ArgumentList args = convertArguments(creator.classCreatorRest().arguments().expressionList());
|
||||||
.map(x -> TypePlaceholder.fresh(creator.getStart()))
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.map(x -> TypePlaceholder.fresh(creator.getStart()))
|
||||||
Statement ret = new NewClass(newclass, args, null, argTypes, creator.getStart());
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
ret.setStatement();
|
Statement ret = new NewClass(newclass, args, null, argTypes, creator.getStart());
|
||||||
return ret;
|
ret.setStatement();
|
||||||
|
return ret;
|
||||||
|
} else {
|
||||||
|
return convert(creator.arrayCreatorRest());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Statement convert(Java17Parser.ArrayCreatorRestContext expression) {
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RefType convert(Java17Parser.CreatedNameContext createdname) {
|
private RefType convert(Java17Parser.CreatedNameContext createdname) {
|
||||||
@ -260,6 +321,7 @@ public class StatementGenerator {
|
|||||||
Statement ret = new NewClass(newclass, args, null, argTypes, innercreator.getStart());
|
Statement ret = new NewClass(newclass, args, null, argTypes, innercreator.getStart());
|
||||||
ret.setStatement();
|
ret.setStatement();
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java17Parser.ConditionalstmtContext stmt) {
|
private Statement convert(Java17Parser.ConditionalstmtContext stmt) {
|
||||||
@ -312,11 +374,6 @@ public class StatementGenerator {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java17Parser.ExpressionListContext exprlist) {
|
|
||||||
// TODO
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArgumentList convertArguments(Java17Parser.ExpressionListContext arglist) {
|
private ArgumentList convertArguments(Java17Parser.ExpressionListContext arglist) {
|
||||||
if (arglist == null)
|
if (arglist == null)
|
||||||
return new ArgumentList(new ArrayList<>(), new NullToken());
|
return new ArgumentList(new ArrayList<>(), new NullToken());
|
||||||
@ -393,6 +450,11 @@ public class StatementGenerator {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Statement convert(Java17Parser.SemistmtContext stmt) {
|
||||||
|
// TODO
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
private Statement convert(Java17Parser.ReturnstmtContext stmt) {
|
private Statement convert(Java17Parser.ReturnstmtContext stmt) {
|
||||||
if (stmt.expression() != null) {
|
if (stmt.expression() != null) {
|
||||||
return new Return(convert(stmt.expression()), stmt.getStart());
|
return new Return(convert(stmt.expression()), stmt.getStart());
|
||||||
@ -416,7 +478,7 @@ public class StatementGenerator {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java17Parser.CatchClauseContext stmt) {
|
private Statement convert(Java17Parser.TrycatchresourceContext stmt) {
|
||||||
// TODO
|
// TODO
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -450,23 +512,30 @@ public class StatementGenerator {
|
|||||||
/*
|
/*
|
||||||
* TODO: syntaxtree for instanceof vorbereiten
|
* TODO: syntaxtree for instanceof vorbereiten
|
||||||
* case InstanceofexpressionContext instanceof:
|
* case InstanceofexpressionContext instanceof:
|
||||||
|
* case SwitchexpressionContext switchexpression:
|
||||||
*/
|
*/
|
||||||
case EqualityexpressionContext equal:
|
case EqualityexpressionContext equal:
|
||||||
return convert(equal);
|
return convert(equal);
|
||||||
case AssignexpressionContext assignment:
|
case AssignexpressionContext assignment:
|
||||||
return convert(assignment);
|
return convert(assignment);
|
||||||
case LambdaexpressionContext lambdaexpr:
|
case LambdaexpressionContext lambdaexpr:
|
||||||
return convert(lambdaexpr);
|
return convert(lambdaexpr.lambdaExpression());
|
||||||
/*
|
case ArrayaccessexpressionContext arrayaccess:
|
||||||
* case ArrayaccessexpressionContext arrayaccess:
|
return convert(arrayaccess);
|
||||||
* case ShiftexpressionContext shiftexpr:
|
case ShiftexpressionContext shiftexpr:
|
||||||
* case BitwiseandexpressionContext bitwiseand:
|
return convert(shiftexpr);
|
||||||
* case BitwisexorexpressionContext bitwisexor:
|
case BitwiseandexpressionContext bitwiseand:
|
||||||
* case BitwiseorexpressionContext bitwiseor:
|
return convert(bitwiseand);
|
||||||
* case AndexpressionContext andexpr:
|
case BitwisexorexpressionContext bitwisexor:
|
||||||
* case OrexpressionContext orexpr:
|
return convert(bitwisexor);
|
||||||
* case ConditionalassignexpressionContext condassign:
|
case BitwiseorexpressionContext bitwiseor:
|
||||||
*/
|
return convert(bitwiseor);
|
||||||
|
case AndexpressionContext andexpr:
|
||||||
|
return convert(andexpr);
|
||||||
|
case OrexpressionContext orexpr:
|
||||||
|
return convert(orexpr);
|
||||||
|
case ConditionalassignexpressionContext condassign:
|
||||||
|
return convert(condassign);
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -486,34 +555,6 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java17Parser.PrimaryNoNewArray_lfno_primaryContext expression) {
|
|
||||||
if (expression.literal() != null) {
|
|
||||||
return convert(expression.literal());
|
|
||||||
} else if (expression.parExpression() != null) {
|
|
||||||
return convert(expression.parExpression().expression());
|
|
||||||
} else if (expression.methodInvocation_lfno_primary() != null) {
|
|
||||||
return convert(expression.methodInvocation_lfno_primary());
|
|
||||||
} else if (expression.classInstanceCreationExpression_lfno_primary() != null) {
|
|
||||||
return convert(expression.classInstanceCreationExpression_lfno_primary());
|
|
||||||
} else if (expression.getText().equals("this")) {
|
|
||||||
return new This(expression.getStart());
|
|
||||||
} else if (expression.fieldAccess_lfno_primary() != null) {
|
|
||||||
return convert(expression.fieldAccess_lfno_primary());
|
|
||||||
} else if (expression.methodReference_lfno_primary() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (expression.typeName() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (expression.unannPrimitiveType() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (expression.arrayAccess_lfno_primary() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (expression.fieldAccess_lfno_primary() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private MethodCall convert(MethodCallContext expr, Token offset) {
|
private MethodCall convert(MethodCallContext expr, Token offset) {
|
||||||
String name = "this";
|
String name = "this";
|
||||||
Expression receiver = new This(offset);
|
Expression receiver = new This(offset);
|
||||||
@ -628,6 +669,10 @@ public class StatementGenerator {
|
|||||||
return new FieldVar(receiver, parts[parts.length - 1], TypePlaceholder.fresh(offset), offset);
|
return new FieldVar(receiver, parts[parts.length - 1], TypePlaceholder.fresh(offset), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Expression convert(Java17Parser.ArrayaccessexpressionContext arrayaccess) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
private Expression convert(Java17Parser.ConditionalassignexpressionContext expression) {
|
private Expression convert(Java17Parser.ConditionalassignexpressionContext expression) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -801,77 +846,49 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java17Parser.PrimaryContext primary) {
|
private Expression convert(Java17Parser.PrimaryContext primary) {
|
||||||
Expression expr;
|
switch (primary) {
|
||||||
if (primary.primaryNoNewArray_lfno_primary() != null) {
|
case PrimaryExpressionContext primexpression:
|
||||||
expr = convert(primary.primaryNoNewArray_lfno_primary());
|
return convert(primexpression.expression());
|
||||||
} else {
|
case PrimaryThisContext primthis:
|
||||||
expr = convert(primary.arrayCreationExpression());
|
return new This(primthis.getStart());
|
||||||
|
case PrimarySuperContext primsuper:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
case PrimaryLiteralContext primliteral:
|
||||||
|
return convert(primliteral.literal());
|
||||||
|
case PrimaryIdentifierContext primidentifier:
|
||||||
|
return new LocalVar(primidentifier.getText(), TypePlaceholder.fresh(primidentifier.getStart()),
|
||||||
|
primidentifier.getStart());
|
||||||
|
case PrimaryClassrefContext primclassref:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
case PrimaryInvocationContext priminvocation:
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (primary.primaryNoNewArray_lf_primary() != null && primary.primaryNoNewArray_lf_primary().size() > 0) {
|
|
||||||
for (Java17Parser.PrimaryNoNewArray_lf_primaryContext e : primary.primaryNoNewArray_lf_primary()) {
|
|
||||||
expr = convert(expr, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return expr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Expression convert(Expression expr, Java17Parser.PrimaryNoNewArray_lf_primaryContext e) {
|
|
||||||
if (e.classInstanceCreationExpression_lf_primary() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (e.fieldAccess_lf_primary() != null) {
|
|
||||||
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (e.arrayAccess_lf_primary() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else if (e.methodReference_lf_primary() != null) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
} else {
|
|
||||||
Java17Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
|
|
||||||
String methodName = ctxt.Identifier().toString();
|
|
||||||
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = ctxt.argumentList().expression().stream()
|
|
||||||
.map(x -> TypePlaceholder.fresh(e.getStart()))
|
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName,
|
|
||||||
convert(ctxt.argumentList()), TypePlaceholder.fresh(e.getStart()), argTypes, e.getStart());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Expression convert(Java17Parser.ArrayCreatorRestContext expression) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java17Parser.LiteralContext literal) {
|
private Expression convert(Java17Parser.LiteralContext literal) {
|
||||||
if (literal.IntegerLiteral() != null) {
|
switch (literal) {
|
||||||
Number value = Integer.parseInt(literal.IntegerLiteral().getText());
|
case IntLiteralContext intliteral:
|
||||||
return new Literal(TypePlaceholder.fresh(literal.getStart()),
|
Number value = Integer.parseInt(intliteral.getText());
|
||||||
value, literal.getStart());
|
return new Literal(TypePlaceholder.fresh(literal.getStart()), value, intliteral.getStart());
|
||||||
} else if (literal.FloatingPointLiteral() != null) {
|
case FltLiteralContext floatliteral:
|
||||||
Number value = Double.parseDouble(literal.FloatingPointLiteral().getText());
|
value = Double.parseDouble(floatliteral.getText());
|
||||||
return new Literal(TypePlaceholder.fresh(literal.getStart()),
|
return new Literal(TypePlaceholder.fresh(literal.getStart()), value, floatliteral.getStart());
|
||||||
value, literal.getStart());
|
case CharLiteralContext charliteral:
|
||||||
} else if (literal.BooleanLiteral() != null) {
|
RefType type = new RefType(reg.getName("java.lang.Character"), charliteral.getStart());
|
||||||
RefType type = new RefType(reg.getName("java.lang.Boolean"), literal.getStart());
|
return new Literal(type, charliteral.getText().charAt(1), charliteral.getStart());
|
||||||
return new Literal(type,
|
case StringLiteralContext stringliteral:
|
||||||
Boolean.parseBoolean(literal.BooleanLiteral().getText()),
|
type = new RefType(reg.getName("java.lang.String"), stringliteral.getStart());
|
||||||
literal.getStart());
|
return new Literal(type, stringliteral.getText().substring(1, stringliteral.getText().length() - 1),
|
||||||
} else if (literal.CharacterLiteral() != null) {
|
stringliteral.getStart());
|
||||||
RefType type = new RefType(reg.getName("java.lang.Character"), literal.getStart());
|
case BoolLiteralContext boolliteral:
|
||||||
return new Literal(type,
|
type = new RefType(reg.getName("java.lang.Boolean"), boolliteral.getStart());
|
||||||
// das gibt immer ' zurück, der Char befindet sich in Position 1
|
return new Literal(type, Boolean.parseBoolean(boolliteral.getText()), boolliteral.getStart());
|
||||||
// literal.CharacterLiteral().getText().charAt(0),
|
case NullLiteralContext nullliteral:
|
||||||
literal.CharacterLiteral().getText().charAt(1),
|
return new Literal(TypePlaceholder.fresh(nullliteral.getStart()), null, nullliteral.getStart());
|
||||||
literal.getStart());
|
case TextBlockContext textblock:
|
||||||
} else if (literal.StringLiteral() != null) {
|
default:
|
||||||
RefType type = new RefType(reg.getName("java.lang.String"), literal.getStart());
|
throw new NotImplementedException();
|
||||||
return new Literal(type,
|
|
||||||
literal.StringLiteral().getText().substring(1, literal.StringLiteral().getText().length() - 1),
|
|
||||||
literal.getStart());
|
|
||||||
} else if (literal.NullLiteral() != null) {
|
|
||||||
return new Literal(TypePlaceholder.fresh(literal.getStart()), null,
|
|
||||||
literal.getStart());
|
|
||||||
} else {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user