added check if there is a main method
This commit is contained in:
parent
30334dc393
commit
77a6dae94f
@ -20,7 +20,7 @@ public class RefType extends AbstractType implements Node {
|
|||||||
public String name; // Class Name
|
public String name; // Class Name
|
||||||
public List<FieldDecl> fieldDecls;
|
public List<FieldDecl> fieldDecls;
|
||||||
public List<MethodDecl> methodDecls;
|
public List<MethodDecl> methodDecls;
|
||||||
boolean hasMain;
|
public boolean hasMain;
|
||||||
|
|
||||||
public RefType(String name,
|
public RefType(String name,
|
||||||
List<FieldDecl> fieldDecls,
|
List<FieldDecl> fieldDecls,
|
||||||
|
@ -53,6 +53,16 @@ public class Program implements Node {
|
|||||||
methodContext.put(oneClass.name, identifierAndMethod);
|
methodContext.put(oneClass.name, identifierAndMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mainCounter = 0;
|
||||||
|
// check if main exists
|
||||||
|
for(RefType oneClass : classes){
|
||||||
|
if(oneClass.hasMain)
|
||||||
|
mainCounter++;
|
||||||
|
}
|
||||||
|
if(mainCounter != 1)
|
||||||
|
throw new TypeCheckException("There is not 1 Main method.");
|
||||||
|
|
||||||
// typecheck each class
|
// typecheck each class
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
for(RefType oneClass : classes){
|
for(RefType oneClass : classes){
|
||||||
|
@ -58,7 +58,6 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
|||||||
//if classToSearchMethodIn does not conatin method, throw exception. go through list and check each
|
//if classToSearchMethodIn does not conatin method, throw exception. go through list and check each
|
||||||
|
|
||||||
for(int i = 0; i < receivingMethods.size(); i++){
|
for(int i = 0; i < receivingMethods.size(); i++){
|
||||||
//todo throw exception
|
|
||||||
currentType = (String) methodContext.get(currentType).get(receivingMethods.get(i).methodName).keySet().toArray()[0];
|
currentType = (String) methodContext.get(currentType).get(receivingMethods.get(i).methodName).keySet().toArray()[0];
|
||||||
if(currentType == null)
|
if(currentType == null)
|
||||||
throw new TypeCheckException("The method " + methodName + " was not found in "+ classToSearchMethodIn + ".");
|
throw new TypeCheckException("The method " + methodName + " was not found in "+ classToSearchMethodIn + ".");
|
||||||
@ -67,12 +66,6 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
|||||||
|
|
||||||
}
|
}
|
||||||
currentType = (String) methodContext.get(currentType).get(methodName).keySet().toArray()[0];
|
currentType = (String) methodContext.get(currentType).get(methodName).keySet().toArray()[0];
|
||||||
// todo checkparameter
|
|
||||||
// if(method == null)
|
|
||||||
// throw new TypeCheckException("The method " + methodName + " was not found in "+ classToSearchMethodIn + ".");
|
|
||||||
|
|
||||||
// typecheck arguments
|
|
||||||
|
|
||||||
|
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
result.type = currentType;
|
result.type = currentType;
|
||||||
|
Loading…
Reference in New Issue
Block a user