mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:18: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
|
||||
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 typeRight = value.typeCheck(typedProgram);
|
||||
|
||||
|
@ -28,10 +28,12 @@ public class TypedClass implements TypedNode {
|
||||
private TypedMethod currentMethod;
|
||||
private TypedConstructor currentConstructor;
|
||||
private Type type;
|
||||
private boolean isMainCurrentMethod;
|
||||
|
||||
public TypedClass(Class c) {
|
||||
className = c.classname();
|
||||
type = Type.REFERENCE(className);
|
||||
isMainCurrentMethod = false;
|
||||
}
|
||||
|
||||
public boolean isParameterNameInCurrentConstructor(String parameterName) {
|
||||
@ -86,7 +88,9 @@ public class TypedClass implements TypedNode {
|
||||
|
||||
if (c.mainmeth() != null) {
|
||||
enterCurrentMethod(typedMain.getTypedMethod());
|
||||
isMainCurrentMethod = true;
|
||||
typedMain.convertToTypedMethod(typedProgram, c);
|
||||
isMainCurrentMethod = false;
|
||||
exitCurrentMethod();
|
||||
} else {
|
||||
typedMain = null;
|
||||
@ -173,7 +177,9 @@ public class TypedClass implements TypedNode {
|
||||
public boolean isCurrentConstructorPresent() {
|
||||
return currentConstructor != null;
|
||||
}
|
||||
|
||||
public boolean isCurrentMainMethodPresent() {
|
||||
return isMainCurrentMethod;
|
||||
}
|
||||
|
||||
public byte[] codeGen() {
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
|
@ -42,6 +42,10 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
|
||||
@Override
|
||||
public Type typeCheck(TypedProgram typedProgram) {
|
||||
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) {
|
||||
ownerChainName = recipient.getRecursiveOwnerChain().getType().getReference();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user