Compare commits
6 Commits
9b8155ebab
...
Tests
Author | SHA1 | Date | |
---|---|---|---|
|
729f4f23d6 | ||
|
a1a9cce511 | ||
|
f7a4e65093 | ||
|
2934872457 | ||
|
1c327705d8 | ||
|
49195c754c |
19
readme.md
19
readme.md
@@ -43,10 +43,21 @@ src/
|
||||
└── resources/
|
||||
test/
|
||||
└── java/
|
||||
│ ├── main/ -> MainTest, E2ETests, UtilityTests
|
||||
│ ├── main/
|
||||
│ ├── parser/ -> Performs tests on the parser
|
||||
│ └── semantic/ -> Performs tests on the semantic check
|
||||
└── resources/ -> Ressources for running the Tests
|
||||
│ └── semantic/
|
||||
└── resources/ -> Ressources for running the Tests
|
||||
├──input
|
||||
│ ├── combinedFeatureTests
|
||||
│ ├── endabgabeTests
|
||||
│ ├── failureTests
|
||||
│ ├── singleFeatureSemanticTests
|
||||
│ ├── singleFeatureTests
|
||||
│ ├── typedAstExceptionsTests
|
||||
│ └── typedAstFeatureTests
|
||||
└──output
|
||||
├── javac
|
||||
└── raupenpiler
|
||||
```
|
||||
|
||||
## Class-Diagramm AST
|
||||
@@ -62,7 +73,5 @@ test/
|
||||
|
||||
|
||||
## How to run the compiler
|
||||
|
||||
## Download
|
||||
|
||||
```bash
|
@@ -253,7 +253,6 @@ 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 {
|
||||
@@ -317,13 +316,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
@Override
|
||||
public TypeCheckResult analyze(IfElseNode toCheck) {
|
||||
var resultIf = toCheck.ifStatement.accept(this);
|
||||
if(toCheck.elseStatement != null){
|
||||
var resultElse = toCheck.elseStatement.accept(this);
|
||||
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID));
|
||||
}
|
||||
var resultElse = toCheck.elseStatement.accept(this);
|
||||
|
||||
|
||||
return new TypeCheckResult(resultIf.isValid(), new BaseType(TypeEnum.VOID));
|
||||
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -609,15 +604,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
ITypeNode currentType = null;
|
||||
int start = 0;
|
||||
if(!memberAccessNode.identifiers.isEmpty()){
|
||||
if(currentFields.get(memberAccessNode.identifiers.getFirst()) != null){
|
||||
memberAccessNode.identifiers.addFirst(currentClass.identifier);
|
||||
start++;
|
||||
if(currentFields.get(memberAccessNode.identifiers.get(0)) != null){
|
||||
memberAccessNode.identifiers.add(0, currentClass.identifier);
|
||||
start = 1;
|
||||
}
|
||||
}
|
||||
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);
|
||||
@@ -635,8 +626,7 @@ 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();
|
||||
|
@@ -12,6 +12,12 @@ 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/
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -338,17 +338,6 @@ 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 ------------------
|
||||
|
||||
/**
|
||||
|
@@ -1,10 +0,0 @@
|
||||
class VariableCompare{
|
||||
|
||||
void trueMethod(boolean a, int c) {
|
||||
if(a && c == 10){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,16 +1,13 @@
|
||||
public class Compiler {
|
||||
Node node;
|
||||
public int add(int i, int j) {
|
||||
node = new Node();
|
||||
node.x = 1;
|
||||
return i+j;
|
||||
}
|
||||
}
|
||||
public class Klasse1 {
|
||||
public int test;
|
||||
|
||||
public class Node {
|
||||
public int x;
|
||||
public void main() {
|
||||
Compiler compiler = new Compiler();
|
||||
int i = compiler.add(5, 8);
|
||||
public int test1() {
|
||||
test = 5;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void test2() {
|
||||
int testInt;
|
||||
testInt = this.test1();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user