mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 09:08:05 +00:00
Fixed error of constructor which is not named like class name
This commit is contained in:
parent
de9365d5c9
commit
ad770213d3
@ -56,7 +56,7 @@ public class TypedClass implements TypedNode {
|
|||||||
typedDeclarations.add(new TypedDeclaration(typedProgram, declaration));
|
typedDeclarations.add(new TypedDeclaration(typedProgram, declaration));
|
||||||
}
|
}
|
||||||
for (Constructor constructor : c.constructors()) {
|
for (Constructor constructor : c.constructors()) {
|
||||||
typedConstructors.add(new TypedConstructor(typedProgram, constructor));
|
typedConstructors.add(new TypedConstructor(typedProgram, constructor, this.className));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Method method : c.methods()) {
|
for (Method method : c.methods()) {
|
||||||
|
@ -32,9 +32,14 @@ public class TypedConstructor implements TypedNode {
|
|||||||
this.typedParameters = typedParameters;
|
this.typedParameters = typedParameters;
|
||||||
this.typedBlock = typedBlock;
|
this.typedBlock = typedBlock;
|
||||||
}
|
}
|
||||||
|
public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) {
|
||||||
|
convertToTypedConstructor(typedProgram, unTypedConstructor, className);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) {
|
||||||
public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
if(!unTypedConstructor.className().equals(className)) {
|
||||||
|
throw new RuntimeException("Constructor name "+ unTypedConstructor.className() +" must be the same as class name" + className);
|
||||||
|
}
|
||||||
name = unTypedConstructor.className();
|
name = unTypedConstructor.className();
|
||||||
convertToTypedParameter(typedProgram, unTypedConstructor.params());
|
convertToTypedParameter(typedProgram, unTypedConstructor.params());
|
||||||
type = Type.VOID;
|
type = Type.VOID;
|
||||||
@ -59,9 +64,7 @@ public class TypedConstructor implements TypedNode {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
|
||||||
convertToTypedConstructor(typedProgram, unTypedConstructor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLocalVariablePresent(String localVarName) {
|
public boolean isLocalVariablePresent(String localVarName) {
|
||||||
return localVariables.stream().anyMatch(localVariable -> localVariable.getName().equals(localVarName));
|
return localVariables.stream().anyMatch(localVariable -> localVariable.getName().equals(localVarName));
|
||||||
|
Loading…
Reference in New Issue
Block a user