31 Commits

Author SHA1 Message Date
Lucas
30bd5a0b5c Oder Documentation and Delete unnecessary
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-08 13:20:41 +02:00
Maximilian Stahl
9760e39a29 Test updated
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-05 13:57:07 +02:00
Maximilian Stahl
93e17e5415 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:51:29 +02:00
Maximilian Stahl
b151edc2fd Updated README.md 2024-07-05 13:51:14 +02:00
Lucas
c0d8ab8399 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:50:11 +02:00
Lucas
f50bb7efd7 refactoring 2024-07-05 13:49:43 +02:00
Maximilian Stahl
51a390752b Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:46:31 +02:00
Maximilian Stahl
3114064038 Fixed Generation 2024-07-05 13:46:18 +02:00
Lucas
745db43b34 make and input
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:44:11 +02:00
Lucas
e0286e0840 Merge branch 'Endabgabe' of https://gitea.hb.dhbw-stuttgart.de/i22005/JavaCompiler into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:25:01 +02:00
Lucas
ebef717141 refactoring 2024-07-05 13:24:48 +02:00
Maximilian Stahl
3de54afa93 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
# Conflicts:
#	src/main/java/bytecode/MethodCodeGen.java
2024-07-05 13:23:57 +02:00
Maximilian Stahl
30d3cfa44a Fix and Final Test File 2024-07-05 13:23:09 +02:00
efa1a21655 Fix for MethodCallNode
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 06:30:55 -04:00
3fb11e5d7e Fixed methotcall with params
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 06:20:49 -04:00
Bruder John
c6e61defce Revert "Some small changes for SemanticAnalyzer"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit dbde4e8047.
2024-07-05 09:34:06 +02:00
Bruder John
dbde4e8047 Some small changes for SemanticAnalyzer
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 09:13:27 +02:00
5a12d61623 Changed testfiles
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:59:37 -04:00
f5bccab651 Small change
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:40:21 -04:00
0de5c3e993 Fixed MethodCall
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:03:52 -04:00
3628a0a4d8 Merge branch 'Endabgabe' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:04:23 -04:00
36f0683240 Fixed crement assign 2024-07-04 20:04:10 -04:00
Purplumbi504
97aadb9ba8 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 23:41:17 +02:00
Purplumbi504
e5dcbb8f99 Fixing AstBuilder For
pp script
2024-07-04 23:41:04 +02:00
e96f30fe19 Updated Loop Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:39:54 +02:00
64b15af6ef Null Test Deleted
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:15:22 +02:00
4ff6854094 NonCalculation Type added
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:14:00 +02:00
0a9cc7655a Changed For Structure
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:07:54 +02:00
7e66b5b8e3 Fixed Target = null
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 22:53:33 +02:00
d835a98e6f Some fixes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 16:41:44 -04:00
240913d422 Fixed MemberAccess Type
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 22:38:39 +02:00
41 changed files with 1180 additions and 851 deletions

2
.gitignore vendored
View File

@@ -78,7 +78,7 @@ fabric.properties
/target /target
src/main/resources/logs/miniCompilerLog.log src/main/resources/logs/miniCompilerLog.log
src/main/resources/output/CompilerInput.class src/test/java/main/CompilerInput.class
src/test/resources/output/javac/CompilerInput$Test.class src/test/resources/output/javac/CompilerInput$Test.class
src/test/resources/output/javac/CompilerInput.class src/test/resources/output/javac/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput.class src/test/resources/output/miniCompiler/CompilerInput.class

View File

@@ -1,58 +0,0 @@
# Kurzdokumentation
## Aufgabenverteilung
### Maximilian Stahl und Jannik Rombach:
- **Scanner**
- **Parser**
- **AST**
- **AstBuilder**
- **Modul: ast**
- Alle
- **Modul: parser**
- Alle
- **Modul: visitor**
- Alle
- **Testmodul: parser**
- AstBuildertest.java
- Helper.java
- **Testfiles: singleFeatureTests**
- Alle
### Johannes Ehlert:
- **Semantische Analyse**
- **Modul: semantic**
- **Modul: typecheck**
- **Testmodul: parser**
- AstBuildertest.java
- **Testfiles: typedAstFeatureTests**
- Großteil
- **Testfiles: typedAstExceptionsTests**
- Großteil
### David Große:
- **Bytecodegenerator**
- **Modul: bytecode**
- Alle
### Lucas Janker:
- **Tests**
- **Modul: main**
- Alle
- **Testmodul: main**
- Alle
- **Testmodul: parser**
- ScannerTest.java
- ParserTest.java
- **Testmodul: semantic**
- **Testfiles: combinedFeatureTests**
- Alle
- **Testfiles: failureTests**
- Alle
- **Testfiles: Alle**
- Refactoring
- **Ordnerstrukturen**
- Großteil
- **Build**
- **Makefile**
- **Dokumentation**

Binary file not shown.

BIN
Parser_Dokumentation.pdf Normal file

Binary file not shown.

View File

@@ -15,7 +15,6 @@ This project aims to provide a simplified version of the Java compiler, focusing
- `while` ... ; - `while` ... ;
- `do` ... `while`; - `do` ... `while`;
- `for`; - `for`;
- `switch` ... `case` ... ;
- **Comments**: - **Comments**:
- Single line: `// comment` - Single line: `// comment`
- Multi-line: `/* comment */` - Multi-line: `/* comment */`
@@ -56,6 +55,9 @@ test/
## Distribution of the realisation ## Distribution of the realisation
### i22030 & i22035 ### i22030 & i22035
Ausführliche Beschreibung der Parser Umsetzung:
![Parserumsetzung](Parser_Dokumentation.pdf)
Parser: Parser:
- Grammar -> (src/main/java/parser/grammar) - Grammar -> (src/main/java/parser/grammar)
@@ -111,7 +113,7 @@ cd .\src\test\ ; make clean compile-miniCompiler
``` ```
### 2. Start miniCompiler using jar: ### 2. Start miniCompiler using jar:
If you do not have the .jar, download it [here](https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0/src/branch/Endabgabe/src) or compile it using mvn package or make first If you do not have the .jar, download it [here](https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0/src/branch/main/JavaCompiler-1.0-jar-with-dependencies.jar) or compile it using mvn package or make first
``` ```
java.exe -DgenJar=bool -DgenClass=bool -jar path_to_jar\jarName.jar 'path_to_input_file.java' 'path_to_output_directory' java.exe -DgenJar=bool -DgenClass=bool -jar path_to_jar\jarName.jar 'path_to_input_file.java' 'path_to_output_directory'
``` ```

View File

@@ -4,5 +4,6 @@ public enum TypeEnum {
VOID, VOID,
INT, INT,
CHAR, CHAR,
BOOL BOOL,
NULL
} }

View File

@@ -10,6 +10,7 @@ import ast.members.MainMethodNode;
import ast.members.MethodNode; import ast.members.MethodNode;
import ast.parameters.ParameterNode; import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode; import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.NewDeclarationNode; import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.CrementType; import ast.statementexpressions.crementexpressions.CrementType;
import ast.statementexpressions.crementexpressions.DecrementNode; import ast.statementexpressions.crementexpressions.DecrementNode;
@@ -304,9 +305,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
public void visit(UnaryNode unaryNode) { public void visit(UnaryNode unaryNode) {
if (unaryNode.thisExp != null) { if (unaryNode.thisExp != null) {
methodVisitor.visitVarInsn(ALOAD, 0); // this methodVisitor.visitVarInsn(ALOAD, 0); // this
} else if (unaryNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(unaryNode.identifier));
} else if (unaryNode.memberAccess != null) { } else if (unaryNode.memberAccess != null) {
unaryNode.memberAccess.setTypeNode(unaryNode.getType());
unaryNode.memberAccess.accept(this); unaryNode.memberAccess.accept(this);
} else if (unaryNode.value != null) { } else if (unaryNode.value != null) {
unaryNode.value.accept(this); unaryNode.value.accept(this);
@@ -316,6 +316,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
unaryNode.statement.accept(this); unaryNode.statement.accept(this);
} else if (unaryNode.expression != null) { } else if (unaryNode.expression != null) {
unaryNode.expression.accept(this); unaryNode.expression.accept(this);
} else if (unaryNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(unaryNode.identifier));
} }
} }
@@ -324,7 +326,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(BlockNode blockNode) { public void visit(BlockNode blockNode) {
for(IStatementNode statementNode : blockNode.statements) { for (IStatementNode statementNode : blockNode.statements) {
statementNode.accept(this); statementNode.accept(this);
} }
} }
@@ -380,6 +382,20 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
if (localVariableDeclarationNode.expression != null) { if (localVariableDeclarationNode.expression != null) {
// Process expression // Process expression
localVariableDeclarationNode.expression.accept(this); localVariableDeclarationNode.expression.accept(this);
if (localVariableDeclarationNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) localVariableDeclarationNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.type;
loadIncrement(incrementNode);
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.type;
loadDecrement(decrementNode);
}
}
// add local var to list if not in list // add local var to list if not in list
if (!localVariables.contains(localVariableDeclarationNode.identifier)) { if (!localVariables.contains(localVariableDeclarationNode.identifier)) {
localVariables.add(localVariableDeclarationNode.identifier); localVariables.add(localVariableDeclarationNode.identifier);
@@ -400,24 +416,37 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(AssignNode assignNode) { public void visit(AssignNode assignNode) {
if (assignNode.assignable.memberAccess != null) { // this / object if (assignNode.assignable.memberAccess != null) { // this / object
if (assignNode.expression instanceof IncrementNode) { assignNode.assignable.memberAccess.setTypeNode(assignNode.assignable.typeNode);
if (((IncrementNode) assignNode.expression).crementType.equals(CrementType.PREFIX)) { // ++i if (assignNode.expression instanceof UnaryNode) {
fieldOrObjectVarPrefixCrementAssign(assignNode); UnaryNode unaryNode = (UnaryNode) assignNode.expression;
} else { // i++ if (unaryNode.statement instanceof IncrementNode) {
fieldOrObjectVarSuffixCrementAssign(assignNode); IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
} if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
} else if (assignNode.expression instanceof DecrementNode) { incrementNode.accept(this); // crement
if (((DecrementNode) assignNode.expression).crementType.equals(CrementType.PREFIX)) { fieldOrObjectVarCrementAssign(assignNode); // assign
fieldOrObjectVarPrefixCrementAssign(assignNode); } else { // i++
} else { fieldOrObjectVarCrementAssign(assignNode); // assign
fieldOrObjectVarSuffixCrementAssign(assignNode); incrementNode.accept(this); // crement
}
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.accept(this); // crement
fieldOrObjectVarCrementAssign(assignNode); // assign
} else {
fieldOrObjectVarCrementAssign(assignNode); // assign
decrementNode.accept(this); // crement
}
} }
} else { } else {
assignFieldOrObjectVar(assignNode); assignFieldOrObjectVar(assignNode);
} }
} else { // local var } else { // local var
if (assignNode.expression instanceof IncrementNode || assignNode.expression instanceof DecrementNode) { if (assignNode.expression instanceof UnaryNode) {
localVarCrementAssign(assignNode); UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode || unaryNode.statement instanceof DecrementNode) {
localVarCrementAssign(assignNode);
}
} else { } else {
assignNode.expression.accept(this); assignNode.expression.accept(this);
assignLocalVar(assignNode); assignLocalVar(assignNode);
@@ -425,82 +454,40 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
} }
} }
private void localVarCrementAssign(AssignNode assignNode) { private void loadIncrement(IncrementNode incrementNode) {
if (assignNode.expression instanceof IncrementNode) { AssignableNode assignableNode = incrementNode.assignableExpression;
IncrementNode incrementNode = (IncrementNode) assignNode.expression; if (assignableNode.memberAccess != null) {
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i assignableNode.memberAccess.accept(this);
incrementNode.accept(this); } else {
assignLocalVar(assignNode); if (assignableNode.typeNode instanceof BaseType) {
} else { // i++ methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
loadBeforeCrement(assignNode); } else if (assignableNode.typeNode instanceof ReferenceType) {
assignLocalVar(assignNode); methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
incrementNode.accept(this);
}
} else if (assignNode.expression instanceof DecrementNode decrementNode) {
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.accept(this);
assignLocalVar(assignNode);
} else {
loadBeforeCrement(assignNode);
assignLocalVar(assignNode);
decrementNode.accept(this);
} }
} }
} }
private void fieldOrObjectVarPrefixCrementAssign(AssignNode assignNode) { private void loadDecrement(DecrementNode decrementNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier); AssignableNode assignableNode = decrementNode.assignableExpression;
if(localVarIndex >= 0) { // object if (assignableNode.memberAccess != null) {
methodVisitor.visitVarInsn(ALOAD, localVarIndex); assignableNode.memberAccess.accept(this);
} else if(assignNode.assignable.memberAccess.thisExpr) { // field
methodVisitor.visitVarInsn(ALOAD, 0);
} else { } else {
localVariables.add(assignNode.assignable.identifier); if (assignableNode.typeNode instanceof BaseType) {
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier)); methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
} else if (assignableNode.typeNode instanceof ReferenceType) {
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
}
} }
assignNode.expression.accept(this);
methodVisitor.visitInsn(DUP_X1);
if (assignNode.expression instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
}
private void fieldOrObjectVarSuffixCrementAssign(AssignNode assignNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier);
if(localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else if(assignNode.assignable.memberAccess.thisExpr) { // field
methodVisitor.visitVarInsn(ALOAD, 0);
} else {
localVariables.add(assignNode.assignable.identifier);
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier));
}
loadBeforeCrement(assignNode);
if (assignNode.expression instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
assignNode.expression.accept(this);
} }
private void assignLocalVar(AssignNode assignNode) { private void assignLocalVar(AssignNode assignNode) {
methodVisitor.visitInsn(DUP);
if (!localVariables.contains(assignNode.assignable.identifier)) { if (!localVariables.contains(assignNode.assignable.identifier)) {
localVariables.add(assignNode.assignable.identifier); localVariables.add(assignNode.assignable.identifier);
} }
if (assignNode.expression instanceof BaseType) {
if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(assignNode.assignable.identifier)); methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(assignNode.assignable.identifier));
} else if (assignNode.expression instanceof ReferenceType) { } else if (assignNode.expression.getType() instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(assignNode.assignable.identifier)); methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(assignNode.assignable.identifier));
} }
} }
@@ -513,46 +500,78 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitVarInsn(ALOAD, 0);
} else { } else {
localVariables.add(assignNode.assignable.identifier); localVariables.add(assignNode.assignable.identifier);
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier));
} }
assignNode.expression.accept(this); assignNode.expression.accept(this);
methodVisitor.visitInsn(DUP_X1);
if (assignNode.expression instanceof BaseType) { if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType())); methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression instanceof ReferenceType) { } else if (assignNode.expression.getType() instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType(); ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";"); methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
} }
} }
private void loadBeforeCrement(AssignNode assignNode) { private void localVarCrementAssign(AssignNode assignNode) {
if(assignNode.expression instanceof IncrementNode) { UnaryNode unaryNode = (UnaryNode) assignNode.expression;
IncrementNode incrementNode = (IncrementNode) assignNode.expression; if (unaryNode.statement instanceof IncrementNode) {
if(incrementNode.assignableExpression.memberAccess != null) { IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.memberAccess.accept(this); if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
} else { incrementNode.accept(this);
if(assignNode.assignable.typeNode instanceof BaseType) { incrementNode.assignableExpression.typeNode = unaryNode.getType();
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignNode.assignable.identifier)); loadIncrement(incrementNode);
} else if(assignNode.assignable.typeNode instanceof ReferenceType) { assignLocalVar(assignNode);
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier)); } else { // i++
} incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
assignLocalVar(assignNode);
incrementNode.accept(this);
} }
} else if(assignNode.expression instanceof DecrementNode) { } else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) assignNode.expression; DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
if(decrementNode.assignableExpression.memberAccess != null) { if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.assignableExpression.memberAccess.accept(this); decrementNode.accept(this);
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
assignLocalVar(assignNode);
} else { } else {
if(assignNode.assignable.typeNode instanceof BaseType) { decrementNode.assignableExpression.typeNode = unaryNode.getType();
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignNode.assignable.identifier)); loadDecrement(decrementNode);
} else if(assignNode.assignable.typeNode instanceof ReferenceType) { assignLocalVar(assignNode);
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier)); decrementNode.accept(this);
}
} }
} }
} }
private void fieldOrObjectVarCrementAssign(AssignNode assignNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else if (assignNode.assignable.memberAccess.thisExpr) { // field
methodVisitor.visitVarInsn(ALOAD, 0);
} else {
localVariables.add(assignNode.assignable.identifier);
}
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement((incrementNode));
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
}
if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
}
@Override @Override
public void visit(IncrementNode incrementNode) { public void visit(IncrementNode incrementNode) {
if (incrementNode.assignableExpression.memberAccess != null) { // Object var / field if (incrementNode.assignableExpression.memberAccess != null) { // Object var / field
@@ -567,7 +586,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
} else if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) { } else if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) incrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";")); methodVisitor.visitFieldInsn(GETFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) incrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
} }
methodVisitor.visitInsn(DUP);
methodVisitor.visitInsn(ICONST_1); methodVisitor.visitInsn(ICONST_1);
methodVisitor.visitInsn(IADD); methodVisitor.visitInsn(IADD);
if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) { if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
@@ -589,7 +607,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
} else { // this } else { // this
methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitVarInsn(ALOAD, 0);
} }
methodVisitor.visitInsn(DUP);
if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) { if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) decrementNode.assignableExpression.memberAccess.getTypeNode())); methodVisitor.visitFieldInsn(GETFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) decrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) { } else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
@@ -662,6 +679,21 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
} else { // Return something } else { // Return something
// Process expression // Process expression
returnNode.expression.accept(this); returnNode.expression.accept(this);
if (returnNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) returnNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
}
if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
}
}
// Return result of expression // Return result of expression
if (returnNode.expression.getType() instanceof BaseType) { if (returnNode.expression.getType() instanceof BaseType) {
methodVisitor.visitInsn(IRETURN); methodVisitor.visitInsn(IRETURN);
@@ -691,10 +723,22 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(MethodCallNode methodCallNode) { public void visit(MethodCallNode methodCallNode) {
List<ParameterNode> parameterNodes = new ArrayList<>(); List<ParameterNode> parameterNodes = new ArrayList<>();
int localVarIndex = -1;
if (methodCallNode.target.memberAccess.identifiers.size() > 1) {
localVarIndex = localVariables.indexOf(methodCallNode.target.memberAccess.identifiers.get(1));
}
if (localVarIndex >= 0) { // local var object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this field
methodVisitor.visitVarInsn(ALOAD, 0);
}
for (IExpressionNode expressionNode : methodCallNode.parameters) { for (IExpressionNode expressionNode : methodCallNode.parameters) {
expressionNode.accept(this); expressionNode.accept(this);
parameterNodes.add(new ParameterNode(expressionNode.getType(), "")); parameterNodes.add(new ParameterNode(expressionNode.getType(), ""));
} }
if(methodCallNode.type == null) {
methodCallNode.type = new BaseType(TypeEnum.INT);
}
methodVisitor.visitMethodInsn(INVOKEVIRTUAL, methodCallNode.target.memberAccess.identifiers.get(0), methodCallNode.identifier, mapper.generateMethodDescriptor(methodCallNode.type, parameterNodes), false); methodVisitor.visitMethodInsn(INVOKEVIRTUAL, methodCallNode.target.memberAccess.identifiers.get(0), methodCallNode.identifier, mapper.generateMethodDescriptor(methodCallNode.type, parameterNodes), false);
} }
} }

View File

@@ -41,8 +41,8 @@ public class Main {
} }
else { else {
try { try {
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/endabgabeTests/Person.java")); CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/finalTest/Car.java"));
compileFile(codeCharStream, "src/test/resources/input/endabgabeTests"); compileFile(codeCharStream, "src/test/resources/input/finalTest");
} catch (IOException e) { } catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage()); System.err.println("Error reading the file: " + e.getMessage());
} }

View File

@@ -29,6 +29,10 @@ import java.util.logging.*;
* <code>consoleHandler.setLevel(Level.OFF);</code> * <code>consoleHandler.setLevel(Level.OFF);</code>
* <code>fileHandler.setLevel(Level.ALL);</code> * <code>fileHandler.setLevel(Level.ALL);</code>
*/ */
public class MiniCompilerLogger { public class MiniCompilerLogger {
static Logger logger = Logger.getLogger("miniCompilerLogs"); static Logger logger = Logger.getLogger("miniCompilerLogs");
@@ -66,14 +70,16 @@ public class MiniCompilerLogger {
logger.addHandler(consoleHandler); logger.addHandler(consoleHandler);
// Configure file handler // 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 // Toggle file logging on/off
//fileHandler.setLevel(Level.ALL); fileHandler.setLevel(Level.ALL);
//fileHandler.setFormatter(new CustomFormatter()); fileHandler.setFormatter(new CustomFormatter());
//logger.addHandler(fileHandler); logger.addHandler(fileHandler);
} catch (SecurityException e) { } catch (SecurityException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
} }
} }
@@ -102,7 +108,7 @@ public class MiniCompilerLogger {
public static void logAST(ASTNode abstractSyntaxTree) { public static void logAST(ASTNode abstractSyntaxTree) {
// Printing the AST // Printing the AST
logger.info("-------------------- AST builder -> AST --------------------"); logger.info("-------------------- AST builder -> AST --------------------");
// logger.info("AST: " + ast.toString()); logger.info("Abstract Syntax Tree generated, Startnode:");
logAST(abstractSyntaxTree, 0); logAST(abstractSyntaxTree, 0);
logger.info("\n"); logger.info("\n");
} }
@@ -110,14 +116,15 @@ public class MiniCompilerLogger {
public static void logSemanticAnalyzer(ASTNode typedAst) { public static void logSemanticAnalyzer(ASTNode typedAst) {
// Printing the typed AST // Printing the typed AST
logger.info("-------------------- Semantic Analyzer -> typed AST --------------------"); logger.info("-------------------- Semantic Analyzer -> typed AST --------------------");
logAST(typedAst, 0); // logAST(typedAst, 0);
logger.info("Typed Abstract Syntax Tree generated without errors");
logger.info("\n"); logger.info("\n");
} }
public static void logBytecodeGenerator() { public static void logBytecodeGenerator() {
// Printing the bytecode // Printing the bytecode
logger.info("-------------------- Bytecode Generator -> Bytecode --------------------"); logger.info("-------------------- Bytecode Generator -> Bytecode --------------------");
logger.info("Bytecode generated without errors."); logger.info("Bytecode generated without errors");
logger.info("\n"); logger.info("\n");
} }
@@ -164,7 +171,6 @@ public class MiniCompilerLogger {
} }
} }
// TODO: Fix this method
public static void logAST(ASTNode abstractSyntaxTree, int indent) { public static void logAST(ASTNode abstractSyntaxTree, int indent) {
if (abstractSyntaxTree == null) { if (abstractSyntaxTree == null) {
logger.severe("AST is null !!!"); logger.severe("AST is null !!!");
@@ -172,9 +178,9 @@ public class MiniCompilerLogger {
} }
String indentString = " ".repeat(indent * 2); String indentString = " ".repeat(indent * 2);
logger.info(indentString + abstractSyntaxTree.getClass()); logger.info(indentString + abstractSyntaxTree.getClass());
//for (ASTNode child : abstractSyntaxTree.getChildren()) { // for (ASTNode child : abstractSyntaxTree.getChildren()) {
// logAST(child, indent + 1); // logAST(child, indent + 1);
// } // }
} }
} }

View File

@@ -332,15 +332,8 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
// Inkrement // Inkrement
IStatementExpressionNode crement = null; IStatementExpressionNode crement = null;
boolean isPrefix = false;
if (ctx.statementExpression(i) != null) { if (ctx.statementExpression(i) != null) {
crement = (IStatementExpressionNode) visit(ctx.statementExpression(i)); crement = (IStatementExpressionNode) visit(ctx.statementExpression(i));
if (crement instanceof IncrementNode) {
isPrefix = ((IncrementNode) crement).crementType == CrementType.PREFIX;
} else if (crement instanceof DecrementNode) {
isPrefix = ((DecrementNode) crement).crementType == CrementType.PREFIX;
}
} }
BlockNode forBlock = (BlockNode) visit(ctx.blockStatement()); BlockNode forBlock = (BlockNode) visit(ctx.blockStatement());
@@ -348,18 +341,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
// While-Schleife // While-Schleife
BlockNode whileBody = new BlockNode(); BlockNode whileBody = new BlockNode();
// Prä-Inkrement: Das Inkrement kommt vor dem Block
if (crement != null && isPrefix) {
whileBody.addStatement(crement);
}
// Block Statements der For-Schleife in den While-Block kopieren // Block Statements der For-Schleife in den While-Block kopieren
for (IStatementNode statement : forBlock.statements) { for (IStatementNode statement : forBlock.statements) {
whileBody.addStatement(statement); whileBody.addStatement(statement);
} }
// Post-Inkrement: Das Inkrement kommt nach dem Block // Post-Inkrement: Das Inkrement kommt nach dem Block
if (crement != null && !isPrefix) { if (crement != null) {
whileBody.addStatement(crement); whileBody.addStatement(crement);
} }
@@ -846,6 +834,12 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
* *
* @param ctx the dot subtraction expression context * @param ctx the dot subtraction expression context
* @return the AST node for the dot subtraction expression * @return the AST node for the dot subtraction expression
*//**
* Creates an ITypeNode based on the type identifier.
* It handles basic types and reference types.
*
* @param identifier the type identifier
* @return the type node
*/ */
@Override @Override
public ASTNode visitDotSubtractionExpression(SimpleJavaParser.DotSubtractionExpressionContext ctx) { public ASTNode visitDotSubtractionExpression(SimpleJavaParser.DotSubtractionExpressionContext ctx) {

View File

@@ -254,12 +254,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
return new TypeCheckResult(true, type); return new TypeCheckResult(true, type);
} else if (currentScope.getLocalVar(toCheck.identifier) != null) { } else if (currentScope.getLocalVar(toCheck.identifier) != null) {
var type = currentScope.getLocalVar(toCheck.identifier); var type = currentScope.getLocalVar(toCheck.identifier);
toCheck.setTypeNode(type);
return new TypeCheckResult(true, type); return new TypeCheckResult(true, type);
} }
} }
return new TypeCheckResult(true, null); return new TypeCheckResult(true, null);
} }
@Override @Override
@@ -372,6 +371,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
} }
} }
} else { } else {
if(toCheck.identifier != null) {
toCheck.target = new TargetNode(new MemberAccessNode(false));
toCheck.target.memberAccess.identifiers.add(currentClass.identifier);
}
ReferenceType reference = new ReferenceType(currentClass.identifier); ReferenceType reference = new ReferenceType(currentClass.identifier);
if (!toCheck.chainedMethods.isEmpty()) { if (!toCheck.chainedMethods.isEmpty()) {
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) { for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
@@ -388,7 +392,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
} else { } else {
return new TypeCheckResult(false, null); return new TypeCheckResult(false, null);
} }
} }
return new TypeCheckResult(false, null); return new TypeCheckResult(false, null);
@@ -426,8 +429,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override @Override
public TypeCheckResult analyze(NewDeclarationNode toCheck) { public TypeCheckResult analyze(NewDeclarationNode toCheck) {
if (context.containsClass(toCheck.identifier)) { if (context.containsClass(toCheck.identifier)) {
for(var t : toCheck.expressions) {
t.accept(this);
}
return new TypeCheckResult(true, new ReferenceType(toCheck.identifier)); return new TypeCheckResult(true, new ReferenceType(toCheck.identifier));
} else { } else {
throw new RuntimeException("Cannot find class " + toCheck.identifier); throw new RuntimeException("Cannot find class " + toCheck.identifier);
@@ -529,7 +534,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
case LESS, LESS_EQUAL, GREATER, GREATER_EQUAL: case LESS, LESS_EQUAL, GREATER, GREATER_EQUAL:
if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.INT) && if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.INT) &&
unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.INT)) { unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.INT)) {
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL)); ITypeNode type = new BaseType(TypeEnum.BOOL);
nonCalculationNode.setType(type);
return new TypeCheckResult(true, type);
} else { } else {
errors.add(new TypeMismatchException("Both types must be Integer")); errors.add(new TypeMismatchException("Both types must be Integer"));
} }
@@ -537,7 +544,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
case OR, AND: case OR, AND:
if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.BOOL) && if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.BOOL) &&
unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.BOOL)) { unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.BOOL)) {
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL)); ITypeNode type = new BaseType(TypeEnum.BOOL);
nonCalculationNode.setType(type);
return new TypeCheckResult(true, type);
} else { } else {
errors.add(new TypeMismatchException("Both types must be Boolean")); errors.add(new TypeMismatchException("Both types must be Boolean"));
} }
@@ -545,7 +554,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
case EQUAL, NOT_EQUAL: case EQUAL, NOT_EQUAL:
if (expResult.getType() instanceof BaseType expResultType && unaryResult.getType() instanceof BaseType unaryResultType if (expResult.getType() instanceof BaseType expResultType && unaryResult.getType() instanceof BaseType unaryResultType
&& Objects.equals(expResultType, unaryResultType)) { && Objects.equals(expResultType, unaryResultType)) {
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL)); ITypeNode type = new BaseType(TypeEnum.BOOL);
nonCalculationNode.setType(type);
return new TypeCheckResult(true, type);
} else { } else {
errors.add(new TypeMismatchException("Both types must be the same")); errors.add(new TypeMismatchException("Both types must be the same"));
} }
@@ -624,7 +635,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (currentType == null) { if (currentType == null) {
if (currentScope.getLocalVar(s) != null) { if (currentScope.getLocalVar(s) != null) {
currentType = currentScope.getLocalVar(s); currentType = currentScope.getLocalVar(s);
} else if (currentFields.get(s) != null) { } else if (currentFields.get(s) != null) {
currentType = currentFields.get(s); currentType = currentFields.get(s);
} else { } else {
@@ -648,7 +658,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
} }
} }
memberAccessNode.setTypeNode(currentType);
return new TypeCheckResult(true, currentType); return new TypeCheckResult(true, currentType);
} }
@@ -674,6 +684,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
return new TypeCheckResult(true, new BaseType(TypeEnum.INT)); return new TypeCheckResult(true, new BaseType(TypeEnum.INT));
} }
case CHAR_VALUE -> { case CHAR_VALUE -> {
valueNode.value = valueNode.value.replace("'", "");
return new TypeCheckResult(true, new BaseType(TypeEnum.CHAR)); return new TypeCheckResult(true, new BaseType(TypeEnum.CHAR));
} }
case BOOLEAN_VALUE -> { case BOOLEAN_VALUE -> {

View File

@@ -1,13 +1,63 @@
public class Compiler { public class CompilerInput {
public int add(int i, int j) { public int ps;
return i+j; public char brand;
public int tires;
public int drivenKilometers;
public CompilerInput(int horsePower) {
this.ps = horsePower;
this.tires = 4;
}
public int getTires() {
return this.tires;
}
public boolean isSuperCar() {
if(this.ps > 300) {
return true;
} else {
return false;
}
}
public void tune(int horsePower) {
this.ps = this.ps + horsePower;
}
public void tune() {
this.ps = this.ps + 50;
}
public void driveCircels(int circels) {
for(int i = 0; i < circels; i++) {
this.drivenKilometers = this.drivenKilometers + 5;
}
}
public void isTunable(boolean hasEngine, boolean hasTires) {
if(hasEngine && hasTires) {
this.tune(5);
}
}
public char race() {
int enemyHorsePower = 200;
char win = 'W';
char lose = 'L';
CompilerInput enemy = new CompilerInput(ps);
if(this.ps > enemyHorsePower) {
return win;
} else {
return lose;
}
}
public int refuel(int currentTank, int maxTank){
int tank = currentTank;
do{
tank++;
}while(tank<maxTank);
return tank;
} }
} }
public class Node {
public void main() {
Compiler compiler = new Compiler();
int i = compiler.add(5, 8);
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View File

@@ -5,22 +5,12 @@
all: compile-javac compile-miniCompiler all: compile-javac compile-miniCompiler
compile-javac: compile-javac:
javac -d .\resources\output\javac .\resources\input\CompilerInput.java javac -d .\resources\output\javac ..\main\resources\input\CompilerInput.java
compile-miniCompiler: compile-miniCompiler:
cd ../.. ; mvn -DskipTests install cd ../.. ; mvn -DskipTests install
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/miniCompiler cp ..\main\resources\output\CompilerInput.class .\resources\output\miniCompiler
test-miniCompiler:
# move the compiled class to the test/main folder
mv ../main/resources/output/CompilerInput.class .java/main/
# compile the test class
javac .java/main.EndToEndTester.java
# run the test class
java .java/main.EndToEndTester
clean: clean:
# clean main output folders # clean main output folders

View File

@@ -1,93 +0,0 @@
# Scanner
## Scanner Input
### Beispiel 1: Empty Class
String empty class = "public class Name {}";
### Beispiel 2: Filled Class
String filled class =
"class javaFileInput.Example {" +
"if (x < 5) {" +
"for (int i = 0; i < 10; i++) {" +
"while (true) {" +
"x = 5;" +
"}"
## Scanner Output
CommonTokenStream
### Beispiel 1: Empty Class
Token Type; Token Text
Type gibts nur bei Terminalen, Text bei allen
[null "public", null "class", IDENTIFIER "Name", null "{", null "}", EOF "<EOF>"]
Bsp von Ihm mal:
[TokPublic,TokClass,TokIdentifier "Name",TokLeftBrace,TokRightBrace]
# Parser
## Parser Input
CommonTokenStream
(Scanner Output)
## Parser Output (AST)
(program (classDeclaration (accessType public) class Name { }))
ParseTree
### Beispiel 1: Empty Class
# Semantische Analyse / Typcheck
## Typcheck Input
(Parser Output = AST)
## Typcheck Output
### Beispiel 1: Empty Class
# Bytecodegenerierung
## Bytecodegenerierung Input
(Typcheck Output = vom Typcheck eventuell manipulierter AST)
## Bytecodegenerierung Output
### Beispiel 1: Empty Class
Compiled Classfile
public class javaFileInput.Example {
}
## E2E Tests:
- Testdatei mit Main ausführen/kompilieren
- Testdatei mit "javac -d output .\CompilerInput.java" kompilieren
- -> Dateien mit javap vergleichen
wenn beides erfolgreich
- Ergebnis vom eigenen Compiler mithilfe von main.EndToEndTester ausführen
- (Ergebnis von javac mithilfe von main.EndToEndTester ausführen)
### Andis Tipps:
- cp mitgeben
- makefile
- java -jar pfadtocompiler.jar EmptyClass.java
- mvn package
- javac tester // tester compilen
- java tester // tester ausführen
- -> tester ist in unserem Fall main.EndToEndTester.java
- -> Hab ich alles umgesetzt

View File

@@ -10,6 +10,8 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@@ -105,16 +107,6 @@ public class E2EReflectionsTest {
runTest("MultipleClasses"); runTest("MultipleClasses");
} }
@Test
public void NullTest() {
runTest("Null");
}
@Test
public void SelfReferenceTest() {
runTest("SelfReference");
}
@Test @Test
public void ThisDotTest() { public void ThisDotTest() {
runTest("ThisDot"); runTest("ThisDot");

View File

@@ -1,43 +0,0 @@
package main;
/**
* This class is used to test the output of the compiler.
*
* <p>Im gleichen Ordner wie diese Datei (EndToEndTester.java) muss die selbst kompilierte CompilerInput.class Datei sein.
* <br><strong>Hinweis:</strong> Diese muss man also vom Ordner <code> main/resources/output </code> in diesen Ordner hier (test/java/main) rein kopieren. (bis es eine bessere Lösung gibt -> bin grad in der Make dran das alles hier automatisch zu machen)</p>
*
* <p>Die selbst kompilierte .class Datei wird dann hier drin geladen und eine Instanz von ihr erstellt, es können auch Methoden aufgerufen werden.
* <p>Diese EndToEndTester.java Datei wird dann in <code> \src\test\java> </code> mit <code>javac .\main.EndToEndTester.java</code> kompiliert und mit <code>java main.EndToEndTester</code> ausgeführt.
* Wenn unser Compiler funktioniert, sollten keine Errors kommen (sondern nur die Ausgaben, die wir in der CompilerInput.java Datei gemacht haben,
* oder Methoden, die wir hier aufrufen).</p>
*
*/
public class EndToEndTester {
public static void main(String[] args) {
try {
// Try to load the class named "CompilerInput"
Class<?> cls = Class.forName("CompilerInput");
// Print a success message if the class is loaded successfully
System.out.println("Class loaded successfully: " + cls.getName());
// Try to create an instance of the loaded class
Object instance = cls.getDeclaredConstructor().newInstance();
// Print a success message if the instance is created successfully
System.out.println("Instance created: " + instance);
// If the class has a main method, you can invoke it
// cls.getMethod("main", String[].class).invoke(null, (Object) new String[]{});
// If the class has other methods, you can invoke them as well
// Example: cls.getMethod("someMethod").invoke(instance);
} catch (ClassNotFoundException e) {
// Print an error message if the class is not found
System.err.println("Class not found: " + e.getMessage());
} catch (Exception e) {
// Print an error message if any other exception occurs during class loading or instance creation
System.err.println("Error during class loading or execution: " + e.getMessage());
}
}
}

View File

@@ -1,6 +1,5 @@
package main; package main;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
@@ -32,12 +31,14 @@ public class InputFilesTest {
File singleFeatureSemanticTests = new File("src/test/resources/input/singleFeatureSemanticTests"); File singleFeatureSemanticTests = new File("src/test/resources/input/singleFeatureSemanticTests");
File singleFeatureTests = new File("src/test/resources/input/singleFeatureTests"); File singleFeatureTests = new File("src/test/resources/input/singleFeatureTests");
File typedAstFeatureTests = new File("src/test/resources/input/typedAstFeatureTests"); File typedAstFeatureTests = new File("src/test/resources/input/typedAstFeatureTests");
File finalTest = new File("src/test/resources/input/finalTest");
List<File> files = getJavaFilesFromDirectory(combinedFeatureTests); List<File> files = getJavaFilesFromDirectory(combinedFeatureTests);
// files.addAll(getJavaFilesFromDirectory(endabgabeTests)); // files.addAll(getJavaFilesFromDirectory(endabgabeTests));
// files.addAll(getJavaFilesFromDirectory(singleFeatureSemanticTests)); // files.addAll(getJavaFilesFromDirectory(singleFeatureSemanticTests));
files.addAll(getJavaFilesFromDirectory(singleFeatureTests)); files.addAll(getJavaFilesFromDirectory(singleFeatureTests));
// files.addAll(getJavaFilesFromDirectory(typedAstFeatureTests)); // files.addAll(getJavaFilesFromDirectory(typedAstFeatureTests));
//files.addAll(getJavaFilesFromDirectory(finalTest));
if (!files.isEmpty()) { if (!files.isEmpty()) {
for (File file : files) { for (File file : files) {
@@ -76,55 +77,6 @@ public class InputFilesTest {
} }
} }
@Test
@Disabled
public void areEndabgabeTestsActuallyValid() throws IOException {
// Get the system Java compiler
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
File endabgabeTests = new File("src/test/resources/input/endabgabeTests");
List<File> files = getJavaFilesFromDirectory(endabgabeTests);
if (!files.isEmpty()) {
for (File file : files) {
// Try to compile the file and get the result
int result = javac.run(null, null, null, file.getPath());
// Assert that the compilation succeeded (i.e., the result is zero)
assertEquals(0, result, "Expected compilation success for " + file.getName());
}
} else {
System.out.println("No files found in the directories.");
}
}
@Test
@Disabled
public void areSingleFeatureSemanticTestsActuallyValid() throws IOException {
// Get the system Java compiler
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
File singleFeatureSemanticTests = new File("src/test/resources/input/singleFeatureSemanticTests");
List<File> files = getJavaFilesFromDirectory(singleFeatureSemanticTests);
if (!files.isEmpty()) {
for (File file : files) {
// Try to compile the file and get the result
int result = javac.run(null, null, null, file.getPath());
// Assert that the compilation succeeded (i.e., the result is zero)
assertEquals(0, result, "Expected compilation success for " + file.getName());
}
} else {
System.out.println("No files found in the directories.");
}
}
@Test @Test
@@ -152,34 +104,6 @@ public class InputFilesTest {
} }
@Test
@Disabled
public void areTypedAstFeatureTestsActuallyValid() throws IOException {
// Get the system Java compiler
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
File typedAstFeatureTests = new File("src/test/resources/input/typedAstFeatureTests");
List<File> files = getJavaFilesFromDirectory(typedAstFeatureTests);
if (!files.isEmpty()) {
for (File file : files) {
// Try to compile the file and get the result
int result = javac.run(null, null, null, file.getPath());
// Assert that the compilation succeeded (i.e., the result is zero)
assertEquals(0, result, "Expected compilation success for " + file.getName());
}
} else {
System.out.println("No files found in the directories.");
}
}
/** /**
* This test method checks if invalid Java files fail to compile as expected. * This test method checks if invalid Java files fail to compile as expected.
* It uses the JavaCompiler from the ToolProvider to compile the files. * It uses the JavaCompiler from the ToolProvider to compile the files.

View File

@@ -12,9 +12,6 @@ import semantic.SemanticTest;
*/ */
@RunWith(Suite.class) @RunWith(Suite.class)
@Suite.SuiteClasses({ @Suite.SuiteClasses({
InputFilesTest.class,
SemanticTest.class,
EndToTypedAstTest.class
}) })
public class MainTest { public class MainTest {
// This class remains empty, it is used only as a holder for the above annotations // This class remains empty, it is used only as a holder for the above annotations

View File

@@ -308,31 +308,6 @@ class AstBuilderTest {
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
} }
@Test
@DisplayName("Null Test")
public void nullTest() {
BlockNode blockCon = new BlockNode();
MemberAccessNode memberAccess = new MemberAccessNode(true);
memberAccess.addIdentifier("a");
AssignableNode assignable = new AssignableNode(memberAccess);
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "Null", blockCon);
ClassNode class1 = new ClassNode("public", "Null");
class1.addMember(new FieldNode(new AccessModifierNode("public"), new ReferenceType("Null"), "a"));
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "Null.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test @Test
@DisplayName("If Test") @DisplayName("If Test")
public void ifTest() { public void ifTest() {
@@ -428,7 +403,7 @@ class AstBuilderTest {
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("SelfReference"),"selfReference"); MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("SelfReference"),"selfReference");
BlockNode testMethod1Block = new BlockNode(); BlockNode testMethod1Block = new BlockNode();
testMethod1Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(new TargetNode(true), "testMethod2")))); testMethod1Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(null, "testMethod2"))));
MethodNode testMethod1 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod1", testMethod1Block); MethodNode testMethod1 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod1", testMethod1Block);
BlockNode testMethod2Block = new BlockNode(); BlockNode testMethod2Block = new BlockNode();
@@ -608,7 +583,7 @@ class AstBuilderTest {
blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10")))); blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10"))));
blockCon.addStatement(whileStatement); blockCon.addStatement(whileStatement);
blockCon.addStatement(new ReturnNode(null)); blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); ConstructorNode constructor = new ConstructorNode("public", "While", blockCon);
ClassNode class1 = new ClassNode("public", "While"); ClassNode class1 = new ClassNode("public", "While");
class1.addMember(constructor); class1.addMember(constructor);
@@ -639,7 +614,7 @@ class AstBuilderTest {
blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0")))); blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0"))));
blockCon.addStatement(blockDoWhile); blockCon.addStatement(blockDoWhile);
blockCon.addStatement(new ReturnNode(null)); blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); ConstructorNode constructor = new ConstructorNode("public", "DoWhile", blockCon);
ClassNode class1 = new ClassNode("public", "DoWhile"); ClassNode class1 = new ClassNode("public", "DoWhile");
class1.addMember(constructor); class1.addMember(constructor);
@@ -658,7 +633,7 @@ class AstBuilderTest {
LocalVariableDeclarationNode forDeclaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0"))); LocalVariableDeclarationNode forDeclaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0")));
AssignableNode assignable = new AssignableNode("i"); AssignableNode assignable = new AssignableNode("i");
IncrementNode increment = new IncrementNode(CrementType.SUFFIX, assignable); IncrementNode increment = new IncrementNode(CrementType.PREFIX, assignable);
LocalVariableDeclarationNode declaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "a", null, null); LocalVariableDeclarationNode declaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "a", null, null);
@@ -675,7 +650,7 @@ class AstBuilderTest {
BlockNode blockCon = new BlockNode(); BlockNode blockCon = new BlockNode();
blockCon.addStatement(forStatement); blockCon.addStatement(forStatement);
blockCon.addStatement(new ReturnNode(null)); blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); ConstructorNode constructor = new ConstructorNode("public", "For", blockCon);
ClassNode class1 = new ClassNode("public", "For"); ClassNode class1 = new ClassNode("public", "For");
class1.addMember(constructor); class1.addMember(constructor);

View File

@@ -352,34 +352,6 @@ public class SemanticTest {
assertNotNull(typedAst); assertNotNull(typedAst);
} }
@Test
@DisplayName("Null Test")
public void nullTest() {
BlockNode blockCon = new BlockNode();
MemberAccessNode memberAccess = new MemberAccessNode(true);
memberAccess.addIdentifier("a");
AssignableNode assignable = new AssignableNode(memberAccess);
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "Null", blockCon);
ClassNode class1 = new ClassNode("public", "Null");
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
class1.addMember(constructor);
ProgramNode abstractSyntaxTree = new ProgramNode();
abstractSyntaxTree.addClass(class1);
ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree);
for (Exception runtimeException : SemanticAnalyzer.errors) {
runtimeException.printStackTrace();
}
assertTrue(SemanticAnalyzer.errors.isEmpty());
assertNotNull(typedAst);
}
@Test @Test
@DisplayName("Self Reference Test") @DisplayName("Self Reference Test")
public void selfReferenceTest() { public void selfReferenceTest() {

View File

@@ -1,25 +0,0 @@
public class Main {
public static void main(String[] args) {
Car myCar = new Car(2020);
int tires = 0;
int year = myCar.getYear();
if (year == 2020) {
tires = 4;
} else {
tires = 2;
}
}
}
class Car {
private int year;
public Car(int year) {
this.year = year;
}
public int getYear() {
return this.year;
}
}

View File

@@ -1,36 +0,0 @@
public class ControlStructures {
public int sum(int a, int b) {
return a + b;
}
public char checkNumber(int num) {
if (num > 0) {
return 'p';
} else if (num < 0) {
return 'n';
} else {
return 'z';
}
}
public void printNumbersUpTo(int limit) {
int even = 0;
int uneven = 0;
int i = 0;
while (i < limit) {
if ((i % 2) == 0) {
even++;
} else {
uneven = uneven + 1;
}
i++;
}
}
public static void main(String[] args) {
ControlStructures cs = new ControlStructures();
cs.printNumbersUpTo(5);
int result = cs.sum(5, 5);
}
}

View File

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

View File

@@ -1,18 +0,0 @@
public class Person {
private int age;
public Person(int age) {
this.age = age;
}
public int getAge() {
return this.age;
}
}
public class Person2 {
public void greet() {
Person person = new Person(10);
person.getAge();
}
}

View File

@@ -1,25 +0,0 @@
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

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

View File

@@ -1,17 +0,0 @@
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

@@ -0,0 +1,63 @@
public class Car {
public int ps;
public char brand;
public int tires;
public int drivenKilometers;
public Car(int horsePower) {
this.ps = horsePower;
this.tires = 4;
}
public int getTires() {
return this.tires;
}
public boolean isSuperCar() {
if(this.ps > 300) {
return true;
} else {
return false;
}
}
public void tune(int horsePower) {
this.ps = this.ps + horsePower;
}
public void tune() {
this.ps = this.ps + 50;
}
public void driveCircels(int circels) {
for(int i = 0; i < circels; i++) {
this.drivenKilometers = this.drivenKilometers + 5;
}
}
public void isTunable(boolean hasEngine, boolean hasTires) {
if(hasEngine && hasTires) {
this.tune(5);
}
}
public char race() {
int enemyHorsePower = 200;
char win = 'W';
char lose = 'L';
Car enemy = new Car(ps);
if(this.ps > enemyHorsePower) {
return win;
} else {
return lose;
}
}
public int refuel(int currentTank, int maxTank){
int tank = currentTank;
do{
tank++;
}while(tank<maxTank);
return tank;
}
}

View File

@@ -0,0 +1,32 @@
public class Main {
public static void main(String[] args) {
Car vw = new Car(50);
System.out.println(vw.getTires());
System.out.println(vw.isSuperCar());
System.out.println("--------------------------------------");
vw.tune(300);
System.out.println(vw.ps);
System.out.println(vw.isSuperCar());
System.out.println("--------------------------------------");
System.out.println(vw.drivenKilometers);
vw.driveCircels(25);
System.out.println(vw.drivenKilometers);
System.out.println("--------------------------------------");
vw.isTunable(true, true);
System.out.println(vw.ps);
System.out.println("--------------------------------------");
System.out.println(vw.race());
System.out.println("--------------------------------------");
System.out.println(vw.refuel(10, 20));
}
}

View File

@@ -1,7 +1,7 @@
class For{ class For{
public For(){ public For(){
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; ++i){
int a; int a;
} }
} }

View File

@@ -3,7 +3,7 @@ public class Increment {
public int test; public int test;
public void increment(int p) { public void increment(int p) {
test = p++; this.test = p++;
for(int i = 1; i<=10; i++) { for(int i = 1; i<=10; i++) {
int a = 5; int a = 5;

View File

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

View File

@@ -3,7 +3,7 @@ class SelfReference {
SelfReference selfReference; SelfReference selfReference;
int testMethod1() { int testMethod1() {
return this.testMethod2(); return testMethod2();
} }
int testMethod2() { int testMethod2() {

View File

@@ -1,70 +0,0 @@
{
"classes": [
{
"identifier": "testClass1",
"accessType": {
"enumAccessTypeNode": "PUBLIC"
},
"members": [
{
"@type": "Field",
"accessTypeNode": {
"enumAccessTypeNode": "PUBLIC"
},
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "testVar1"
},
{
"@type": "Method",
"visibility": {
"enumAccessTypeNode": "PUBLIC"
},
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "testMethod",
"parameters": {
"parameters": [
{
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "param1"
}
]
},
"statements": [
{
"@type": "Assignment",
"expressionLeft": {
"@type": "InstVar",
"identifier": "testVar1",
"expression": {
"@type": "This",
"type": {
"@type": "Reference",
"identifier": "testClass1"
}
},
"type": null
},
"expressionRight": {
"@type": "Literal",
"type": {
"@type": "Base",
"enumType": "INT"
}
}
}
]
}
],
"hasConstructor": false
}
]
}

View File

@@ -1,133 +0,0 @@
{
"classes": [
{
"identifier": "testClass1",
"accessType": {
"enumAccessTypeNode": "PUBLIC"
},
"members": [
{
"@type": "Field",
"accessTypeNode": {
"enumAccessTypeNode": "PUBLIC"
},
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "testVar1"
},
{
"@type": "Method",
"visibility": {
"enumAccessTypeNode": "PUBLIC"
},
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "testMethod",
"parameters": {
"parameters": [
{
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "param1"
}
]
},
"statements": [
{
"@type": "Assignment",
"expressionLeft": {
"@type": "InstVar",
"identifier": "testVar1",
"expression": {
"@type": "This",
"type": {
"@type": "Reference",
"identifier": "testClass1"
}
},
"type": null
},
"expressionRight": {
"@type": "Literal",
"type": {
"@type": "Base",
"enumType": "BOOLEAN"
}
}
}
]
}
],
"hasConstructor": false,
"methods": [
{
"@type": "Method",
"visibility": {
"enumAccessTypeNode": "PUBLIC"
},
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "testMethod",
"parameters": {
"parameters": [
{
"type": {
"@type": "Base",
"enumType": "INT"
},
"identifier": "param1"
}
]
},
"statements": [
{
"@type": "Assignment",
"expressionLeft": {
"@type": "InstVar",
"identifier": "testVar",
"expression": {
"@type": "InstVar",
"identifier": "testVar",
"expression": {
"@type": "This",
"type": {
"@type": "Reference",
"identifier": "testClass2"
}
},
"type": null
},
"type": null
},
"expressionRight": {
"@type": "Literal",
"type": null
},
"type": null
},
{
"@type": "VariableDeclaration",
"type": {
"@type": "Base",
"enumType": "CHAR"
},
"identifier": "objectVar",
"expression": {
"@type": "Literal",
"type": null
}
}
]
}
]
}
]
}

View File

@@ -1 +0,0 @@
{"classes":[{"identifier":"testClass","accessType":{"enumAccessTypeNode":"PUBLIC"},"members":[{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar1"},{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"objectVar"},{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}],"hasConstructor":false,"methods":[{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}]}]}