Fixed bugs in StatementGenerator regarding constructor generation and field accesses

This commit is contained in:
luca9913 2023-06-09 17:26:55 +02:00
parent f08744479a
commit 78ad7bc003
4 changed files with 22 additions and 10 deletions

View File

@ -573,12 +573,10 @@ public class StatementGenerator {
}
public Receiver getReceiver(ExpressionContext expr) {
Expression expression;
if (expr instanceof PrimaryexpressionContext pc) {
expression = convert(pc.primary());
} else {
expression = generateLocalOrFieldVarOrClassName(expr.getText(), expr.getStart());
}
Expression expression = generateLocalOrFieldVarOrClassName(expr.getText(), expr.getStart());
/*
* if (expr instanceof PrimaryexpressionContext pc) { expression = convert(pc.primary()); } else { expression = generateLocalOrFieldVarOrClassName(expr.getText(), expr.getStart()); }
*/
return getReceiver(expression);
}
@ -816,7 +814,7 @@ public class StatementGenerator {
case PrimaryLiteralContext primliteral:
return convert(primliteral.literal());
case PrimaryIdentifierContext primidentifier:
return new LocalVar(primidentifier.getText(), TypePlaceholder.fresh(primidentifier.getStart()), primidentifier.getStart());
return generateLocalOrFieldVarOrClassName(primidentifier.getText(), primidentifier.getStart());
case PrimaryClassrefContext primclassref:
throw new NotImplementedException();
default:

View File

@ -308,7 +308,12 @@ public class SyntaxTreeGenerator {
break;
}
case MembermethodContext membermethod: {
methods.add(convert(membermodifiers, membermethod.method(), name, superClass, generics));
Method convertedMethod = convert(membermodifiers, membermethod.method(), name, superClass, generics);
if (convertedMethod instanceof Constructor constructor) {
constructors.add(constructor);
} else {
methods.add(convertedMethod);
}
break;
}
case MemberconstructorContext memberconstructor: {
@ -516,7 +521,11 @@ public class SyntaxTreeGenerator {
MethodblockContext methodblock = (MethodblockContext) body;
block = stmtgen.convert(methodblock.block(), true);
}
return new Method(modifiers, name, retType, paramlist, block, gtvDeclarations, header.getStart());
if (name.equals(parentClass.getClassName())) {
return new Constructor(modifiers, name, retType, paramlist, block, gtvDeclarations, methoddeclaration.getStart());
} else {
return new Method(modifiers, name, retType, paramlist, block, gtvDeclarations, methoddeclaration.getStart());
}
}
public Constructor convert(int modifiers, Java17Parser.ConstructorContext constructorContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) {

View File

@ -0,0 +1,5 @@
package syntaxtreegenerator;
public class TestNewFeatures {
}

View File

@ -4,7 +4,7 @@ class Faculty {
Faculty(){
super(());
}
TPH DDBK getFact(java.lang.Integer x){
TPH DDBK getFact(TPH DDBL x){
return this.fact.apply Signature: [TPH DDBM, TPH DDBN](x);
}