mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 15:38:03 +00:00
Removed direct usage of fields and methods in Main
This commit is contained in:
parent
18125531cf
commit
3a3ac49054
@ -37,6 +37,10 @@ public class TypedAssignment implements TypedStatement {
|
|||||||
@Override
|
@Override
|
||||||
public Type typeCheck(TypedProgram typedProgram) {
|
public Type typeCheck(TypedProgram typedProgram) {
|
||||||
|
|
||||||
|
if(typedProgram.getCurrentClass().isCurrentMainMethodPresent() && location.getField() && location.getRecursiveOwnerChain() == null){
|
||||||
|
throw new RuntimeException("Main Method, is not allowed to have fields, they are not static");
|
||||||
|
}
|
||||||
|
|
||||||
Type typeLeft = getTypeLeft(typedProgram);
|
Type typeLeft = getTypeLeft(typedProgram);
|
||||||
Type typeRight = value.typeCheck(typedProgram);
|
Type typeRight = value.typeCheck(typedProgram);
|
||||||
|
|
||||||
|
@ -28,10 +28,12 @@ public class TypedClass implements TypedNode {
|
|||||||
private TypedMethod currentMethod;
|
private TypedMethod currentMethod;
|
||||||
private TypedConstructor currentConstructor;
|
private TypedConstructor currentConstructor;
|
||||||
private Type type;
|
private Type type;
|
||||||
|
private boolean isMainCurrentMethod;
|
||||||
|
|
||||||
public TypedClass(Class c) {
|
public TypedClass(Class c) {
|
||||||
className = c.classname();
|
className = c.classname();
|
||||||
type = Type.REFERENCE(className);
|
type = Type.REFERENCE(className);
|
||||||
|
isMainCurrentMethod = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isParameterNameInCurrentConstructor(String parameterName) {
|
public boolean isParameterNameInCurrentConstructor(String parameterName) {
|
||||||
@ -86,7 +88,9 @@ public class TypedClass implements TypedNode {
|
|||||||
|
|
||||||
if (c.mainmeth() != null) {
|
if (c.mainmeth() != null) {
|
||||||
enterCurrentMethod(typedMain.getTypedMethod());
|
enterCurrentMethod(typedMain.getTypedMethod());
|
||||||
|
isMainCurrentMethod = true;
|
||||||
typedMain.convertToTypedMethod(typedProgram, c);
|
typedMain.convertToTypedMethod(typedProgram, c);
|
||||||
|
isMainCurrentMethod = false;
|
||||||
exitCurrentMethod();
|
exitCurrentMethod();
|
||||||
} else {
|
} else {
|
||||||
typedMain = null;
|
typedMain = null;
|
||||||
@ -173,7 +177,9 @@ public class TypedClass implements TypedNode {
|
|||||||
public boolean isCurrentConstructorPresent() {
|
public boolean isCurrentConstructorPresent() {
|
||||||
return currentConstructor != null;
|
return currentConstructor != null;
|
||||||
}
|
}
|
||||||
|
public boolean isCurrentMainMethodPresent() {
|
||||||
|
return isMainCurrentMethod;
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] codeGen() {
|
public byte[] codeGen() {
|
||||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
@ -42,6 +42,10 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
|
|||||||
@Override
|
@Override
|
||||||
public Type typeCheck(TypedProgram typedProgram) {
|
public Type typeCheck(TypedProgram typedProgram) {
|
||||||
String ownerChainName = null;
|
String ownerChainName = null;
|
||||||
|
if (typedProgram.getCurrentClass().isCurrentMainMethodPresent() && recipient.getRecursiveOwnerChain() == null) {
|
||||||
|
throw new RuntimeException("Main Method, is not allowed to have methods, they are not static");
|
||||||
|
}
|
||||||
|
|
||||||
if (recipient.getRecursiveOwnerChain() != null) {
|
if (recipient.getRecursiveOwnerChain() != null) {
|
||||||
ownerChainName = recipient.getRecursiveOwnerChain().getType().getReference();
|
ownerChainName = recipient.getRecursiveOwnerChain().getType().getReference();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user