10 Commits

Author SHA1 Message Date
Purplumbi504
bd61a0e595 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:11:35 +02:00
Purplumbi504
24407a5c1c Revert test case directory: singleFeatureTests 2024-07-04 21:11:21 +02:00
195440e9d9 Added SemanticAnalyzer ElseIfStatement
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:49:54 +02:00
6fa57cf319 Type Error Change
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:36:36 +02:00
1de6add080 Fixe Type Error
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:23:43 +02:00
c315966219 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 19:45:09 +02:00
c2c4974c76 More Abgabe Tests working 2024-07-04 19:44:59 +02:00
Purplumbi504
85e0cf3807 Revert test case directory: singleFeatureTests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 19:10:21 +02:00
Purplumbi504
6f3fb02666 Fixing test case directory: singleFeatureTests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 19:03:44 +02:00
Purplumbi504
435697053a Fixing ReflectionTests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 18:57:36 +02:00
19 changed files with 150 additions and 1965 deletions

View File

@@ -95,14 +95,6 @@ Tests and execution:
- Typing and Type checking -> (src/test/java/semantic/EndToTypedAstTest)
## Used Tools
- [Maven 4.0](https://maven.apache.org/index.html)
- Used for automating the build process and managing dependencies.
- [ANTLR4 v.13.1](https://www.antlr.org/)
- Used to parse the input Java code into the Abstract Syntax Tree.
## Used Tools
- [Maven 4.0](https://maven.apache.org/index.html)
@@ -140,10 +132,3 @@ Example (jar needs to be in the target directory)
```
DgenClass=true
```
## How to run tests
```bash
mvn test
```
Or start them manually in your IDE

BIN
ast.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

@@ -14,7 +14,6 @@ public class ConstructorNode extends MethodNode implements Visitable {
public AccessModifierNode accessType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public ConstructorNode(String accessType, String identifier, BlockNode block) {
this.accessType = new AccessModifierNode(accessType);

View File

@@ -135,12 +135,12 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override
public void visit(CalculationNode calculationNode) {
if (calculationNode.dotExpression != null) {
calculationNode.dotExpression.accept(this);
}
if (calculationNode.calculationExpression != null) {
calculationNode.calculationExpression.accept(this);
}
if (calculationNode.dotExpression != null) {
calculationNode.dotExpression.accept(this);
}
if (calculationNode.operator != null) {
switch (calculationNode.operator) {
case PLUS:

View File

@@ -15,7 +15,6 @@ import java.io.IOException;
import java.nio.file.Paths;
import java.util.Optional;
/**
* Start miniCompiler using make:
* <p> <code> cd .\src\test\ </code>
@@ -40,6 +39,14 @@ public class Main {
System.err.println("Error reading the file: " + e.getMessage());
}
}
else {
try {
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/endabgabeTests/Person.java"));
compileFile(codeCharStream, "src/test/resources/input/endabgabeTests");
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
}
/**

View File

@@ -66,13 +66,13 @@ public class MiniCompilerLogger {
logger.addHandler(consoleHandler);
// Configure file handler
Handler fileHandler = new FileHandler("src/main/resources/logs/miniCompiler.log");
//Handler fileHandler = new FileHandler("src/main/resources/logs/miniCompiler.log");
// Toggle file logging on/off
fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new CustomFormatter());
logger.addHandler(fileHandler);
//fileHandler.setLevel(Level.ALL);
//fileHandler.setFormatter(new CustomFormatter());
//logger.addHandler(fileHandler);
} catch (SecurityException | IOException e) {
} catch (SecurityException e) {
e.printStackTrace();
}
}

View File

@@ -114,10 +114,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(MethodNode methodNode) {
if (methodNode instanceof ConstructorNode) {
return new TypeCheckResult(true, new BaseType(TypeEnum.VOID));
} else {
var valid = true;
for (var otherMethod : currentClass.getMethods()) {
@@ -159,8 +155,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
}
return new TypeCheckResult(valid, resultType);
}
}
@Override
@@ -177,8 +171,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
currentFields.put(toCheck.identifier, toCheck.type);
}
return new TypeCheckResult(true, null);
}
@Override
@@ -317,9 +309,18 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(IfElseNode toCheck) {
var resultIf = toCheck.ifStatement.accept(this);
var validElseIf = true;
if(toCheck.elseIfStatements.size() != 0) {
for(IfNode ifNode : toCheck.elseIfStatements) {
var resultIfFor = ifNode.accept(this);
validElseIf = validElseIf && resultIfFor.isValid();
}
}
if(toCheck.elseStatement != null){
var resultElse = toCheck.elseStatement.accept(this);
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID));
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid() && validElseIf, new BaseType(TypeEnum.VOID));
}
@@ -575,6 +576,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
var type = currentFields.get(unary.identifier);
unary.setType(type);
return new TypeCheckResult(valid,type );
} else if (unary.value != null) {
var result = unary.value.accept(this);
unary.setType(result.getType());
return new TypeCheckResult(result.isValid(), result.getType());
} else if (unary.statement != null) {
var result = unary.statement.accept(this);
unary.setType(result.getType());

View File

File diff suppressed because it is too large Load Diff

View File

@@ -438,9 +438,7 @@ class AstBuilderTest {
BlockNode testMethod3Block = new BlockNode();
testMethod3Block.addStatement(new LocalVariableDeclarationNode(new ReferenceType("SelfReference"),"selfReference1", "=", new UnaryNode(new NewDeclarationNode("SelfReference")))); // Assing einfach "=" ?
MemberAccessNode methodAccess = new MemberAccessNode(false);
methodAccess.addIdentifier("selfReference1");
methodAccess.addIdentifier("selfReference");
TargetNode methodTarget = new TargetNode(methodAccess);
TargetNode methodTarget = new TargetNode("selfReference1");
testMethod3Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(methodTarget,"testMethod1"))));
MethodNode testMethod3 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod3", testMethod3Block);

View File

@@ -4,13 +4,13 @@ public class ControlStructures {
return a + b;
}
public cahr checkNumber(int num) {
public char checkNumber(int num) {
if (num > 0) {
return "p";
return 'p';
} else if (num < 0) {
return "n";
return 'n';
} else {
return "z";
return 'z';
}
}
@@ -19,7 +19,7 @@ public class ControlStructures {
int uneven = 0;
int i = 0;
while (i < limit) {
if (i % 2 == 0) {
if ((i % 2) == 0) {
even++;
} else {
uneven = uneven + 1;

View File

@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
Person testPerson = new Person(5);
}
}

View File

@@ -0,0 +1,25 @@
public class Calculation {
public int add(int a, int b) {
return a + b;
}
public int sub(int a, int b) {
return a - b;
}
public int mul(int a, int b) {
return a * b;
}
public int div(int a, int b) {
return a / b;
}
public int mod(int a, int b) {
return a % b;
}
public int complexCalculation() {
return 3 - 2 * 2 + 5;
}
}

View File

@@ -0,0 +1 @@
public class EmptyClass {}

View File

@@ -0,0 +1,17 @@
public class Loops {
public boolean If(int a, int b) {
if(a == b) {
return true;
} else {
return false;
}
}
public int While(int a) {
int count = 0;
while(count < a) {
count++;
}
return count;
}
}

View File

@@ -1,8 +1,8 @@
class Null{
Null a;
int a;
public Null(){
this.a = null;
this.a = 1;
}
}

View File

@@ -1,4 +1,4 @@
class SelfReference{
class SelfReference {
SelfReference selfReference;
@@ -10,9 +10,9 @@ class SelfReference{
return 1;
}
int testMethod3(){
int testMethod3() {
SelfReference selfReference1 = new SelfReference();
return selfReference1.selfReference.testMethod1();
return selfReference1.testMethod1();
}
}
}

View File

@@ -1,16 +1,8 @@
public class Compiler {
Node node;
public int add(int i, int j) {
node = new Node();
node.x = 1;
return i+j;
}
}
public class Node {
public int x;
public void main() {
Compiler compiler = new Compiler();
int i = compiler.add(5, 8);
public class If {
public If() {
int intValue = 5;
if(intValue == 5) {
intValue--;
}
}
}

View File