6 Commits

Author SHA1 Message Date
Bruder John
9b8155ebab added class identifier to member acces node
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 16:31:45 +02:00
Bruder John
2e3a7850a4 Fix Double Name 2024-07-04 16:29:42 +02:00
Bruder John
d925a3258c Add Class name to Memberaccesnode and identifier to assignable
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:58:46 +02:00
Lucas
fb5372bc8f make clean
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:22:37 +02:00
Lucas
f29be4fd8c E2E tests done
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:22:05 +02:00
Bruder John
34bb86c7f4 fixed if Check
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-04 10:40:13 +02:00
8 changed files with 55 additions and 36 deletions

View File

@@ -43,21 +43,10 @@ src/
└── resources/ └── resources/
test/ test/
└── java/ └── java/
│ ├── main/ │ ├── main/ -> MainTest, E2ETests, UtilityTests
│ ├── parser/ -> Performs tests on the parser │ ├── parser/ -> Performs tests on the parser
│ └── semantic/ │ └── semantic/ -> Performs tests on the semantic check
└── resources/ -> Ressources for running the Tests └── resources/ -> Ressources for running the Tests
├──input
│ ├── combinedFeatureTests
│ ├── endabgabeTests
│ ├── failureTests
│ ├── singleFeatureSemanticTests
│ ├── singleFeatureTests
│ ├── typedAstExceptionsTests
│ └── typedAstFeatureTests
└──output
├── javac
└── raupenpiler
``` ```
## Class-Diagramm AST ## Class-Diagramm AST
@@ -73,5 +62,7 @@ test/
## How to run the compiler ## How to run the compiler
## Download ## Download
```bash ```bash

View File

@@ -253,6 +253,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (toCheck.memberAccess != null) { if (toCheck.memberAccess != null) {
var result = toCheck.memberAccess.accept(this); var result = toCheck.memberAccess.accept(this);
toCheck.identifier = toCheck.memberAccess.identifiers.getLast();
toCheck.setTypeNode(result.getType()); toCheck.setTypeNode(result.getType());
return result; return result;
} else { } else {
@@ -316,11 +317,15 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override @Override
public TypeCheckResult analyze(IfElseNode toCheck) { public TypeCheckResult analyze(IfElseNode toCheck) {
var resultIf = toCheck.ifStatement.accept(this); var resultIf = toCheck.ifStatement.accept(this);
if(toCheck.elseStatement != null){
var resultElse = toCheck.elseStatement.accept(this); var resultElse = toCheck.elseStatement.accept(this);
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID)); return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID));
} }
return new TypeCheckResult(resultIf.isValid(), new BaseType(TypeEnum.VOID));
}
@Override @Override
public TypeCheckResult analyze(MethodCallNode toCheck) { public TypeCheckResult analyze(MethodCallNode toCheck) {
@@ -604,11 +609,15 @@ public class SemanticAnalyzer implements SemanticVisitor {
ITypeNode currentType = null; ITypeNode currentType = null;
int start = 0; int start = 0;
if(!memberAccessNode.identifiers.isEmpty()){ if(!memberAccessNode.identifiers.isEmpty()){
if(currentFields.get(memberAccessNode.identifiers.get(0)) != null){ if(currentFields.get(memberAccessNode.identifiers.getFirst()) != null){
memberAccessNode.identifiers.add(0, currentClass.identifier); memberAccessNode.identifiers.addFirst(currentClass.identifier);
start = 1; start++;
} }
} }
if(context.getClasses().get(memberAccessNode.identifiers.getFirst()) == null){
memberAccessNode.identifiers.addFirst(currentClass.identifier);
start++;
}
for (int i = start; i < memberAccessNode.identifiers.size(); i++) { for (int i = start; i < memberAccessNode.identifiers.size(); i++) {
String s = memberAccessNode.identifiers.get(i); String s = memberAccessNode.identifiers.get(i);
@@ -626,7 +635,8 @@ public class SemanticAnalyzer implements SemanticVisitor {
} else { } else {
if (currentType instanceof ReferenceType reference) { if (currentType instanceof ReferenceType reference) {
var currentTypeClass = context.getClass(reference.getIdentifier()); var currentTypeClass = context.getClass(reference.getIdentifier());
memberAccessNode.identifiers.add(i, reference.getIdentifier());
i++;
var currentField = currentTypeClass.getField(s); var currentField = currentTypeClass.getField(s);
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) { if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) {
currentType = currentField.getType(); currentType = currentField.getType();

View File

@@ -12,12 +12,6 @@ compile-raupenpiler:
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'" cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
# cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler # cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler
test: compile-javac compile-raupenpiler test-javac test-raupenpiler
test-javac:
# gleich wie bei raupenpiler, kann ich ohne funktionierenden Compiler nicht testen
test-raupenpiler: test-raupenpiler:
# move the compiled class to the test/main folder # move the compiled class to the test/main folder
mv ../main/resources/output/CompilerInput.class .java/main/ mv ../main/resources/output/CompilerInput.class .java/main/

View File

@@ -338,6 +338,17 @@ public class EndToTypedAstTest {
} }
@Test
public void Expression(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/Expression.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
// ------------------ Helpers ------------------ // ------------------ Helpers ------------------
/** /**

View File

@@ -0,0 +1,10 @@
class VariableCompare{
void trueMethod(boolean a, int c) {
if(a && c == 10){
}
}
}

View File

@@ -1,13 +1,16 @@
public class Klasse1 { public class Compiler {
public int test; Node node;
public int add(int i, int j) {
public int test1() { node = new Node();
test = 5; node.x = 1;
return 1; return i+j;
} }
}
public void test2() {
int testInt; public class Node {
testInt = this.test1(); public int x;
public void main() {
Compiler compiler = new Compiler();
int i = compiler.add(5, 8);
} }
} }