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

View File

@@ -253,6 +253,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (toCheck.memberAccess != null) {
var result = toCheck.memberAccess.accept(this);
toCheck.identifier = toCheck.memberAccess.identifiers.getLast();
toCheck.setTypeNode(result.getType());
return result;
} else {
@@ -316,9 +317,13 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(IfElseNode toCheck) {
var resultIf = toCheck.ifStatement.accept(this);
var resultElse = toCheck.elseStatement.accept(this);
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(), new BaseType(TypeEnum.VOID));
return new TypeCheckResult(resultIf.isValid(), new BaseType(TypeEnum.VOID));
}
@Override
@@ -604,11 +609,15 @@ public class SemanticAnalyzer implements SemanticVisitor {
ITypeNode currentType = null;
int start = 0;
if(!memberAccessNode.identifiers.isEmpty()){
if(currentFields.get(memberAccessNode.identifiers.get(0)) != null){
memberAccessNode.identifiers.add(0, currentClass.identifier);
start = 1;
if(currentFields.get(memberAccessNode.identifiers.getFirst()) != null){
memberAccessNode.identifiers.addFirst(currentClass.identifier);
start++;
}
}
if(context.getClasses().get(memberAccessNode.identifiers.getFirst()) == null){
memberAccessNode.identifiers.addFirst(currentClass.identifier);
start++;
}
for (int i = start; i < memberAccessNode.identifiers.size(); i++) {
String s = memberAccessNode.identifiers.get(i);
@@ -626,7 +635,8 @@ public class SemanticAnalyzer implements SemanticVisitor {
} else {
if (currentType instanceof ReferenceType reference) {
var currentTypeClass = context.getClass(reference.getIdentifier());
memberAccessNode.identifiers.add(i, reference.getIdentifier());
i++;
var currentField = currentTypeClass.getField(s);
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) {
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'"
# 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:
# move the compiled class to the test/main folder
mv ../main/resources/output/CompilerInput.class .java/main/

View File

@@ -88,7 +88,7 @@ public class E2EReflectionsTest {
for (Field raupenpilerField : raupenpilerLoadedClassDeclaredFields) {
if (field.getName().equals(raupenpilerField.getName())) {
assertEquals(field.getType(), raupenpilerField.getType());
// assertEquals(field.getModifiers(), raupenpilerField.getModifiers());
// assertEquals(field.getModifiers(), raupenpilerField.getModifiers());
}
}
}

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 ------------------
/**

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 int test;
public int test1() {
test = 5;
return 1;
public class Compiler {
Node node;
public int add(int i, int j) {
node = new Node();
node.x = 1;
return i+j;
}
}
public void test2() {
int testInt;
testInt = this.test1();
public class Node {
public int x;
public void main() {
Compiler compiler = new Compiler();
int i = compiler.add(5, 8);
}
}