boolean instead of bool
This commit is contained in:
parent
7daece9b8f
commit
ae260f6feb
@ -28,12 +28,12 @@ public class Compiler {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args) throws Exception{
|
||||||
|
|
||||||
Path filePath = Paths.get("src/main/java/InputTest.java");
|
Path filePath = Paths.get("src/main/java/Input.java");
|
||||||
|
|
||||||
|
|
||||||
// todo remove this debug info
|
// todo remove this debug info
|
||||||
Path absolutePath = filePath.toAbsolutePath();
|
Path absolutePath = filePath.toAbsolutePath();
|
||||||
System.out.println("Full path: " + absolutePath);
|
System.out.println("Processing input: " + absolutePath);
|
||||||
|
|
||||||
String content;
|
String content;
|
||||||
try {
|
try {
|
||||||
|
@ -2,7 +2,9 @@ class Example1 {
|
|||||||
int i;
|
int i;
|
||||||
int a = 12345;
|
int a = 12345;
|
||||||
Example e;
|
Example e;
|
||||||
|
public Example1(){i = 3456;}
|
||||||
int m(int n){
|
int m(int n){
|
||||||
|
boolean b123;
|
||||||
int x;
|
int x;
|
||||||
x = -3;
|
x = -3;
|
||||||
int i = 5;
|
int i = 5;
|
||||||
|
@ -13,10 +13,10 @@ public class TypeCheckHelper {
|
|||||||
if(Objects.equals(type1, type2)){
|
if(Objects.equals(type1, type2)){
|
||||||
result = type1;
|
result = type1;
|
||||||
}else{
|
}else{
|
||||||
throw new TypeCheckException("There is no upper bound.");
|
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||||
}
|
}
|
||||||
}else if(type1Primitiv || type2Primitiv){
|
}else if(type1Primitiv || type2Primitiv){
|
||||||
throw new TypeCheckException("There is no upper bound.");
|
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||||
}else{
|
}else{
|
||||||
result = "class";
|
result = "class";
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
|||||||
|
|
||||||
case "&&":
|
case "&&":
|
||||||
case "||" :{
|
case "||" :{
|
||||||
if (Objects.equals(TypeCheckHelper.upperBound(leftType.type, rightType.type), "bool")){
|
if (Objects.equals(TypeCheckHelper.upperBound(leftType.type, rightType.type), "boolean")){
|
||||||
result.type = "bool";
|
result.type = "boolean";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ public class UnaryExpression extends AbstractType implements IExpression{
|
|||||||
switch (operator) {
|
switch (operator) {
|
||||||
|
|
||||||
case "!" :{
|
case "!" :{
|
||||||
if (Objects.equals(operandType, "bool")){
|
if (Objects.equals(operandType, "boolean")){
|
||||||
result.type = "bool";
|
result.type = "boolean";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ public class Program implements Node {
|
|||||||
// build type context
|
// build type context
|
||||||
HashMap<String, String> classVars = new HashMap<>();
|
HashMap<String, String> classVars = new HashMap<>();
|
||||||
for (FieldDecl fieldDecl: oneClass.fieldDecls){
|
for (FieldDecl fieldDecl: oneClass.fieldDecls){
|
||||||
if(fieldDecl.type == "boolean")
|
|
||||||
fieldDecl.type = "bool";
|
|
||||||
classVars.put(fieldDecl.identifier, fieldDecl.type);
|
classVars.put(fieldDecl.identifier, fieldDecl.type);
|
||||||
}
|
}
|
||||||
typeContext.put(oneClass.name, classVars);
|
typeContext.put(oneClass.name, classVars);
|
||||||
|
@ -39,6 +39,11 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
LocalVarIdentifier localVarIdentifier = (LocalVarIdentifier) left;
|
LocalVarIdentifier localVarIdentifier = (LocalVarIdentifier) left;
|
||||||
String identifier = localVarIdentifier.getIdentifier();
|
String identifier = localVarIdentifier.getIdentifier();
|
||||||
leftType.type = localVars.get(identifier);
|
leftType.type = localVars.get(identifier);
|
||||||
|
|
||||||
|
// actually instavar of this
|
||||||
|
// if(leftType == null){
|
||||||
|
// localVarIdentifier.
|
||||||
|
// }
|
||||||
}else{
|
}else{
|
||||||
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user