Compare commits
35 Commits
3c0f7e857a
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
4c4c06f728 | ||
|
30bd5a0b5c | ||
f673612f54 | |||
|
9760e39a29 | ||
|
93e17e5415 | ||
|
b151edc2fd | ||
|
c0d8ab8399 | ||
|
f50bb7efd7 | ||
|
51a390752b | ||
|
3114064038 | ||
|
745db43b34 | ||
|
e0286e0840 | ||
|
ebef717141 | ||
|
3de54afa93 | ||
|
30d3cfa44a | ||
efa1a21655 | |||
3fb11e5d7e | |||
|
c6e61defce | ||
|
dbde4e8047 | ||
5a12d61623 | |||
f5bccab651 | |||
0de5c3e993 | |||
3628a0a4d8 | |||
36f0683240 | |||
|
97aadb9ba8 | ||
|
e5dcbb8f99 | ||
e96f30fe19 | |||
64b15af6ef | |||
4ff6854094 | |||
0a9cc7655a | |||
7e66b5b8e3 | |||
d835a98e6f | |||
240913d422 | |||
4bee432294 | |||
0cf4715782 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -78,7 +78,7 @@ fabric.properties
|
||||
|
||||
/target
|
||||
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.class
|
||||
src/test/resources/output/miniCompiler/CompilerInput.class
|
||||
|
@@ -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**
|
BIN
JavaCompiler-1.0-jar-with-dependencies.jar
Normal file
BIN
JavaCompiler-1.0-jar-with-dependencies.jar
Normal file
Binary file not shown.
BIN
Parser_Dokumentation.pdf
Normal file
BIN
Parser_Dokumentation.pdf
Normal file
Binary file not shown.
@@ -15,7 +15,6 @@ This project aims to provide a simplified version of the Java compiler, focusing
|
||||
- `while` ... ;
|
||||
- `do` ... `while`;
|
||||
- `for`;
|
||||
- `switch` ... `case` ... ;
|
||||
- **Comments**:
|
||||
- Single line: `// comment`
|
||||
- Multi-line: `/* comment */`
|
||||
@@ -56,6 +55,9 @@ test/
|
||||
## Distribution of the realisation
|
||||
|
||||
### i22030 & i22035
|
||||
Ausführliche Beschreibung der Parser Umsetzung:
|
||||
|
||||

|
||||
|
||||
Parser:
|
||||
- Grammar -> (src/main/java/parser/grammar)
|
||||
@@ -111,7 +113,7 @@ cd .\src\test\ ; make clean compile-miniCompiler
|
||||
```
|
||||
|
||||
### 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'
|
||||
```
|
||||
|
@@ -11,12 +11,8 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConstructorNode extends MethodNode implements Visitable {
|
||||
public AccessModifierNode accessType;
|
||||
public String identifier;
|
||||
public List<ParameterNode> parameters = new ArrayList<>();
|
||||
|
||||
public ConstructorNode(String accessType, String identifier, BlockNode block) {
|
||||
this.accessType = new AccessModifierNode(accessType);
|
||||
this.accesModifier = new AccessModifierNode(accessType);
|
||||
this.identifier = identifier;
|
||||
this.block = block;
|
||||
}
|
||||
|
@@ -4,5 +4,6 @@ public enum TypeEnum {
|
||||
VOID,
|
||||
INT,
|
||||
CHAR,
|
||||
BOOL
|
||||
BOOL,
|
||||
NULL
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import ast.members.MainMethodNode;
|
||||
import ast.members.MethodNode;
|
||||
import ast.parameters.ParameterNode;
|
||||
import ast.statementexpressions.AssignNode;
|
||||
import ast.statementexpressions.AssignableNode;
|
||||
import ast.statementexpressions.NewDeclarationNode;
|
||||
import ast.statementexpressions.crementexpressions.CrementType;
|
||||
import ast.statementexpressions.crementexpressions.DecrementNode;
|
||||
@@ -53,7 +54,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
@Override
|
||||
public void visit(ConstructorNode constructorNode) {
|
||||
methodVisitor =
|
||||
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accessType),
|
||||
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accesModifier),
|
||||
"<init>",
|
||||
mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters),
|
||||
null,
|
||||
@@ -304,9 +305,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
public void visit(UnaryNode unaryNode) {
|
||||
if (unaryNode.thisExp != null) {
|
||||
methodVisitor.visitVarInsn(ALOAD, 0); // this
|
||||
} else if (unaryNode.identifier != null) {
|
||||
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(unaryNode.identifier));
|
||||
} else if (unaryNode.memberAccess != null) {
|
||||
unaryNode.memberAccess.setTypeNode(unaryNode.getType());
|
||||
unaryNode.memberAccess.accept(this);
|
||||
} else if (unaryNode.value != null) {
|
||||
unaryNode.value.accept(this);
|
||||
@@ -316,6 +316,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
unaryNode.statement.accept(this);
|
||||
} else if (unaryNode.expression != null) {
|
||||
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
|
||||
public void visit(BlockNode blockNode) {
|
||||
for(IStatementNode statementNode : blockNode.statements) {
|
||||
for (IStatementNode statementNode : blockNode.statements) {
|
||||
statementNode.accept(this);
|
||||
}
|
||||
}
|
||||
@@ -380,6 +382,20 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
if (localVariableDeclarationNode.expression != null) {
|
||||
// Process expression
|
||||
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
|
||||
if (!localVariables.contains(localVariableDeclarationNode.identifier)) {
|
||||
localVariables.add(localVariableDeclarationNode.identifier);
|
||||
@@ -400,24 +416,37 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
@Override
|
||||
public void visit(AssignNode assignNode) {
|
||||
if (assignNode.assignable.memberAccess != null) { // this / object
|
||||
if (assignNode.expression instanceof IncrementNode) {
|
||||
if (((IncrementNode) assignNode.expression).crementType.equals(CrementType.PREFIX)) { // ++i
|
||||
fieldOrObjectVarPrefixCrementAssign(assignNode);
|
||||
} else { // i++
|
||||
fieldOrObjectVarSuffixCrementAssign(assignNode);
|
||||
}
|
||||
} else if (assignNode.expression instanceof DecrementNode) {
|
||||
if (((DecrementNode) assignNode.expression).crementType.equals(CrementType.PREFIX)) {
|
||||
fieldOrObjectVarPrefixCrementAssign(assignNode);
|
||||
} else {
|
||||
fieldOrObjectVarSuffixCrementAssign(assignNode);
|
||||
assignNode.assignable.memberAccess.setTypeNode(assignNode.assignable.typeNode);
|
||||
if (assignNode.expression instanceof UnaryNode) {
|
||||
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
|
||||
if (unaryNode.statement instanceof IncrementNode) {
|
||||
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
|
||||
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
|
||||
incrementNode.accept(this); // crement
|
||||
fieldOrObjectVarCrementAssign(assignNode); // assign
|
||||
} else { // i++
|
||||
fieldOrObjectVarCrementAssign(assignNode); // assign
|
||||
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 {
|
||||
assignFieldOrObjectVar(assignNode);
|
||||
}
|
||||
} else { // local var
|
||||
if (assignNode.expression instanceof IncrementNode || assignNode.expression instanceof DecrementNode) {
|
||||
localVarCrementAssign(assignNode);
|
||||
if (assignNode.expression instanceof UnaryNode) {
|
||||
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
|
||||
if (unaryNode.statement instanceof IncrementNode || unaryNode.statement instanceof DecrementNode) {
|
||||
localVarCrementAssign(assignNode);
|
||||
}
|
||||
} else {
|
||||
assignNode.expression.accept(this);
|
||||
assignLocalVar(assignNode);
|
||||
@@ -425,82 +454,40 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void localVarCrementAssign(AssignNode assignNode) {
|
||||
if (assignNode.expression instanceof IncrementNode) {
|
||||
IncrementNode incrementNode = (IncrementNode) assignNode.expression;
|
||||
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
|
||||
incrementNode.accept(this);
|
||||
assignLocalVar(assignNode);
|
||||
} else { // i++
|
||||
loadBeforeCrement(assignNode);
|
||||
assignLocalVar(assignNode);
|
||||
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 loadIncrement(IncrementNode incrementNode) {
|
||||
AssignableNode assignableNode = incrementNode.assignableExpression;
|
||||
if (assignableNode.memberAccess != null) {
|
||||
assignableNode.memberAccess.accept(this);
|
||||
} else {
|
||||
if (assignableNode.typeNode instanceof BaseType) {
|
||||
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
|
||||
} else if (assignableNode.typeNode instanceof ReferenceType) {
|
||||
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fieldOrObjectVarPrefixCrementAssign(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);
|
||||
private void loadDecrement(DecrementNode decrementNode) {
|
||||
AssignableNode assignableNode = decrementNode.assignableExpression;
|
||||
if (assignableNode.memberAccess != null) {
|
||||
assignableNode.memberAccess.accept(this);
|
||||
} else {
|
||||
localVariables.add(assignNode.assignable.identifier);
|
||||
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
if (assignableNode.typeNode instanceof BaseType) {
|
||||
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) {
|
||||
methodVisitor.visitInsn(DUP);
|
||||
if (!localVariables.contains(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));
|
||||
} else if (assignNode.expression instanceof ReferenceType) {
|
||||
} else if (assignNode.expression.getType() instanceof ReferenceType) {
|
||||
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
}
|
||||
}
|
||||
@@ -513,46 +500,78 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
methodVisitor.visitVarInsn(ALOAD, 0);
|
||||
} else {
|
||||
localVariables.add(assignNode.assignable.identifier);
|
||||
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
}
|
||||
|
||||
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()));
|
||||
} else if (assignNode.expression instanceof ReferenceType) {
|
||||
} 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() + ";");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBeforeCrement(AssignNode assignNode) {
|
||||
if(assignNode.expression instanceof IncrementNode) {
|
||||
IncrementNode incrementNode = (IncrementNode) assignNode.expression;
|
||||
if(incrementNode.assignableExpression.memberAccess != null) {
|
||||
incrementNode.assignableExpression.memberAccess.accept(this);
|
||||
} else {
|
||||
if(assignNode.assignable.typeNode instanceof BaseType) {
|
||||
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
} else if(assignNode.assignable.typeNode instanceof ReferenceType) {
|
||||
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
}
|
||||
private void localVarCrementAssign(AssignNode assignNode) {
|
||||
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
|
||||
if (unaryNode.statement instanceof IncrementNode) {
|
||||
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
|
||||
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
|
||||
incrementNode.accept(this);
|
||||
incrementNode.assignableExpression.typeNode = unaryNode.getType();
|
||||
loadIncrement(incrementNode);
|
||||
assignLocalVar(assignNode);
|
||||
} else { // i++
|
||||
incrementNode.assignableExpression.typeNode = unaryNode.getType();
|
||||
loadIncrement(incrementNode);
|
||||
assignLocalVar(assignNode);
|
||||
incrementNode.accept(this);
|
||||
}
|
||||
} else if(assignNode.expression instanceof DecrementNode) {
|
||||
DecrementNode decrementNode = (DecrementNode) assignNode.expression;
|
||||
if(decrementNode.assignableExpression.memberAccess != null) {
|
||||
decrementNode.assignableExpression.memberAccess.accept(this);
|
||||
} else if (unaryNode.statement instanceof DecrementNode) {
|
||||
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
|
||||
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
|
||||
decrementNode.accept(this);
|
||||
decrementNode.assignableExpression.typeNode = unaryNode.getType();
|
||||
loadDecrement(decrementNode);
|
||||
assignLocalVar(assignNode);
|
||||
} else {
|
||||
if(assignNode.assignable.typeNode instanceof BaseType) {
|
||||
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
} else if(assignNode.assignable.typeNode instanceof ReferenceType) {
|
||||
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignNode.assignable.identifier));
|
||||
}
|
||||
decrementNode.assignableExpression.typeNode = unaryNode.getType();
|
||||
loadDecrement(decrementNode);
|
||||
assignLocalVar(assignNode);
|
||||
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
|
||||
public void visit(IncrementNode incrementNode) {
|
||||
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) {
|
||||
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(IADD);
|
||||
if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
|
||||
@@ -589,7 +607,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
} else { // this
|
||||
methodVisitor.visitVarInsn(ALOAD, 0);
|
||||
}
|
||||
methodVisitor.visitInsn(DUP);
|
||||
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()));
|
||||
} else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
|
||||
@@ -662,6 +679,21 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
} else { // Return something
|
||||
// Process expression
|
||||
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
|
||||
if (returnNode.expression.getType() instanceof BaseType) {
|
||||
methodVisitor.visitInsn(IRETURN);
|
||||
@@ -691,10 +723,22 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
@Override
|
||||
public void visit(MethodCallNode methodCallNode) {
|
||||
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) {
|
||||
expressionNode.accept(this);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -41,8 +41,8 @@ public class Main {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/endabgabeTests/Person.java"));
|
||||
compileFile(codeCharStream, "src/test/resources/input/endabgabeTests");
|
||||
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/finalTest/Car.java"));
|
||||
compileFile(codeCharStream, "src/test/resources/input/finalTest");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error reading the file: " + e.getMessage());
|
||||
}
|
||||
|
@@ -29,6 +29,10 @@ import java.util.logging.*;
|
||||
* <code>consoleHandler.setLevel(Level.OFF);</code>
|
||||
* <code>fileHandler.setLevel(Level.ALL);</code>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
public class MiniCompilerLogger {
|
||||
|
||||
static Logger logger = Logger.getLogger("miniCompilerLogs");
|
||||
@@ -66,14 +70,16 @@ 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 e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +108,7 @@ public class MiniCompilerLogger {
|
||||
public static void logAST(ASTNode abstractSyntaxTree) {
|
||||
// Printing the AST
|
||||
logger.info("-------------------- AST builder -> AST --------------------");
|
||||
// logger.info("AST: " + ast.toString());
|
||||
logger.info("Abstract Syntax Tree generated, Startnode:");
|
||||
logAST(abstractSyntaxTree, 0);
|
||||
logger.info("\n");
|
||||
}
|
||||
@@ -110,14 +116,15 @@ public class MiniCompilerLogger {
|
||||
public static void logSemanticAnalyzer(ASTNode typedAst) {
|
||||
// Printing the 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");
|
||||
}
|
||||
|
||||
public static void logBytecodeGenerator() {
|
||||
// Printing the bytecode
|
||||
logger.info("-------------------- Bytecode Generator -> Bytecode --------------------");
|
||||
logger.info("Bytecode generated without errors.");
|
||||
logger.info("Bytecode generated without errors");
|
||||
logger.info("\n");
|
||||
}
|
||||
|
||||
@@ -164,7 +171,6 @@ public class MiniCompilerLogger {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Fix this method
|
||||
public static void logAST(ASTNode abstractSyntaxTree, int indent) {
|
||||
if (abstractSyntaxTree == null) {
|
||||
logger.severe("AST is null !!!");
|
||||
@@ -172,9 +178,9 @@ public class MiniCompilerLogger {
|
||||
}
|
||||
String indentString = " ".repeat(indent * 2);
|
||||
logger.info(indentString + abstractSyntaxTree.getClass());
|
||||
//for (ASTNode child : abstractSyntaxTree.getChildren()) {
|
||||
// for (ASTNode child : abstractSyntaxTree.getChildren()) {
|
||||
// logAST(child, indent + 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -332,15 +332,8 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
|
||||
// Inkrement
|
||||
IStatementExpressionNode crement = null;
|
||||
boolean isPrefix = false;
|
||||
if (ctx.statementExpression(i) != null) {
|
||||
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());
|
||||
@@ -348,18 +341,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
// While-Schleife
|
||||
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
|
||||
for (IStatementNode statement : forBlock.statements) {
|
||||
whileBody.addStatement(statement);
|
||||
}
|
||||
|
||||
// Post-Inkrement: Das Inkrement kommt nach dem Block
|
||||
if (crement != null && !isPrefix) {
|
||||
if (crement != null) {
|
||||
whileBody.addStatement(crement);
|
||||
}
|
||||
|
||||
@@ -846,6 +834,12 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
||||
*
|
||||
* @param ctx the dot subtraction expression context
|
||||
* @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
|
||||
public ASTNode visitDotSubtractionExpression(SimpleJavaParser.DotSubtractionExpressionContext ctx) {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package semantic;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -25,15 +24,11 @@ import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNod
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||
import ast.statements.*;
|
||||
import ast.type.AccessModifierNode;
|
||||
import ast.type.EnumAccessModifierNode;
|
||||
import ast.type.ValueNode;
|
||||
import ast.type.type.*;
|
||||
import com.sun.jdi.IntegerType;
|
||||
import semantic.context.ClassContext;
|
||||
import semantic.context.Context;
|
||||
import semantic.exceptions.*;
|
||||
import semantic.TypeCheckResult;
|
||||
|
||||
public class SemanticAnalyzer implements SemanticVisitor {
|
||||
|
||||
@@ -259,12 +254,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else if (currentScope.getLocalVar(toCheck.identifier) != null) {
|
||||
var type = currentScope.getLocalVar(toCheck.identifier);
|
||||
toCheck.setTypeNode(type);
|
||||
return new TypeCheckResult(true, type);
|
||||
}
|
||||
}
|
||||
|
||||
return new TypeCheckResult(true, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -311,7 +305,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
var resultIf = toCheck.ifStatement.accept(this);
|
||||
var validElseIf = true;
|
||||
|
||||
if(toCheck.elseIfStatements.size() != 0) {
|
||||
if(!toCheck.elseIfStatements.isEmpty()) {
|
||||
for(IfNode ifNode : toCheck.elseIfStatements) {
|
||||
var resultIfFor = ifNode.accept(this);
|
||||
validElseIf = validElseIf && resultIfFor.isValid();
|
||||
@@ -365,6 +359,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
if (toCheck.target.thisTar) {
|
||||
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
|
||||
if (type != null) {
|
||||
toCheck.type = type;
|
||||
return new TypeCheckResult(true, type);
|
||||
}
|
||||
}
|
||||
@@ -376,6 +371,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
if (!toCheck.chainedMethods.isEmpty()) {
|
||||
@@ -393,7 +392,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
} else {
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new TypeCheckResult(false, null);
|
||||
@@ -431,8 +429,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
|
||||
@Override
|
||||
public TypeCheckResult analyze(NewDeclarationNode toCheck) {
|
||||
|
||||
if (context.containsClass(toCheck.identifier)) {
|
||||
for(var t : toCheck.expressions) {
|
||||
t.accept(this);
|
||||
}
|
||||
return new TypeCheckResult(true, new ReferenceType(toCheck.identifier));
|
||||
} else {
|
||||
throw new RuntimeException("Cannot find class " + toCheck.identifier);
|
||||
@@ -534,7 +534,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
case LESS, LESS_EQUAL, GREATER, GREATER_EQUAL:
|
||||
if (expResult.getType() instanceof BaseType expResultType && expResultType.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 {
|
||||
errors.add(new TypeMismatchException("Both types must be Integer"));
|
||||
}
|
||||
@@ -542,7 +544,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
case OR, AND:
|
||||
if (expResult.getType() instanceof BaseType expResultType && expResultType.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 {
|
||||
errors.add(new TypeMismatchException("Both types must be Boolean"));
|
||||
}
|
||||
@@ -550,7 +554,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
case EQUAL, NOT_EQUAL:
|
||||
if (expResult.getType() instanceof BaseType expResultType && unaryResult.getType() instanceof BaseType 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 {
|
||||
errors.add(new TypeMismatchException("Both types must be the same"));
|
||||
}
|
||||
@@ -629,7 +635,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
if (currentType == null) {
|
||||
if (currentScope.getLocalVar(s) != null) {
|
||||
currentType = currentScope.getLocalVar(s);
|
||||
|
||||
} else if (currentFields.get(s) != null) {
|
||||
currentType = currentFields.get(s);
|
||||
} else {
|
||||
@@ -653,7 +658,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
memberAccessNode.setTypeNode(currentType);
|
||||
return new TypeCheckResult(true, currentType);
|
||||
}
|
||||
|
||||
@@ -679,6 +684,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
return new TypeCheckResult(true, new BaseType(TypeEnum.INT));
|
||||
}
|
||||
case CHAR_VALUE -> {
|
||||
valueNode.value = valueNode.value.replace("'", "");
|
||||
return new TypeCheckResult(true, new BaseType(TypeEnum.CHAR));
|
||||
}
|
||||
case BOOLEAN_VALUE -> {
|
||||
|
@@ -1,13 +1,63 @@
|
||||
public class Compiler {
|
||||
public int add(int i, int j) {
|
||||
return i+j;
|
||||
public class CompilerInput {
|
||||
public int ps;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
809
src/main/resources/logs/miniCompiler.log
Normal file
809
src/main/resources/logs/miniCompiler.log
Normal file
File diff suppressed because one or more lines are too long
BIN
src/main/resources/output/CompilerInput.class
Normal file
BIN
src/main/resources/output/CompilerInput.class
Normal file
Binary file not shown.
BIN
src/main/resources/output/output.jar
Normal file
BIN
src/main/resources/output/output.jar
Normal file
Binary file not shown.
@@ -5,22 +5,12 @@
|
||||
all: compile-javac compile-miniCompiler
|
||||
|
||||
compile-javac:
|
||||
javac -d .\resources\output\javac .\resources\input\CompilerInput.java
|
||||
javac -d .\resources\output\javac ..\main\resources\input\CompilerInput.java
|
||||
|
||||
compile-miniCompiler:
|
||||
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'"
|
||||
# cp ../main/resources/output/CompilerInput.class .java/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
|
||||
|
||||
|
||||
cp ..\main\resources\output\CompilerInput.class .\resources\output\miniCompiler
|
||||
|
||||
clean:
|
||||
# clean main output folders
|
||||
|
@@ -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
|
@@ -10,6 +10,8 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -105,16 +107,6 @@ public class E2EReflectionsTest {
|
||||
runTest("MultipleClasses");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void NullTest() {
|
||||
runTest("Null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SelfReferenceTest() {
|
||||
runTest("SelfReference");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ThisDotTest() {
|
||||
runTest("ThisDot");
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package main;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
@@ -32,12 +31,14 @@ public class InputFilesTest {
|
||||
File singleFeatureSemanticTests = new File("src/test/resources/input/singleFeatureSemanticTests");
|
||||
File singleFeatureTests = new File("src/test/resources/input/singleFeatureTests");
|
||||
File typedAstFeatureTests = new File("src/test/resources/input/typedAstFeatureTests");
|
||||
File finalTest = new File("src/test/resources/input/finalTest");
|
||||
|
||||
List<File> files = getJavaFilesFromDirectory(combinedFeatureTests);
|
||||
// files.addAll(getJavaFilesFromDirectory(endabgabeTests));
|
||||
// files.addAll(getJavaFilesFromDirectory(singleFeatureSemanticTests));
|
||||
files.addAll(getJavaFilesFromDirectory(singleFeatureTests));
|
||||
// files.addAll(getJavaFilesFromDirectory(typedAstFeatureTests));
|
||||
//files.addAll(getJavaFilesFromDirectory(finalTest));
|
||||
|
||||
if (!files.isEmpty()) {
|
||||
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
|
||||
@@ -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.
|
||||
* It uses the JavaCompiler from the ToolProvider to compile the files.
|
||||
|
@@ -12,9 +12,6 @@ import semantic.SemanticTest;
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
InputFilesTest.class,
|
||||
SemanticTest.class,
|
||||
EndToTypedAstTest.class
|
||||
})
|
||||
public class MainTest {
|
||||
// This class remains empty, it is used only as a holder for the above annotations
|
||||
|
@@ -308,31 +308,6 @@ class AstBuilderTest {
|
||||
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
|
||||
@DisplayName("If Test")
|
||||
public void ifTest() {
|
||||
@@ -428,7 +403,7 @@ class AstBuilderTest {
|
||||
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("SelfReference"),"selfReference");
|
||||
|
||||
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);
|
||||
|
||||
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(whileStatement);
|
||||
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");
|
||||
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(blockDoWhile);
|
||||
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");
|
||||
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")));
|
||||
|
||||
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);
|
||||
|
||||
@@ -675,7 +650,7 @@ class AstBuilderTest {
|
||||
BlockNode blockCon = new BlockNode();
|
||||
blockCon.addStatement(forStatement);
|
||||
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");
|
||||
class1.addMember(constructor);
|
||||
|
@@ -352,34 +352,6 @@ public class SemanticTest {
|
||||
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
|
||||
@DisplayName("Self Reference Test")
|
||||
public void selfReferenceTest() {
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Person testPerson = new Person(5);
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
public class Person {
|
||||
private int age;
|
||||
|
||||
public Person(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return this.age;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -1 +0,0 @@
|
||||
public class EmptyClass {}
|
@@ -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;
|
||||
}
|
||||
}
|
63
src/test/resources/input/finalTest/Car.java
Normal file
63
src/test/resources/input/finalTest/Car.java
Normal 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;
|
||||
}
|
||||
}
|
32
src/test/resources/input/finalTest/Main.java
Normal file
32
src/test/resources/input/finalTest/Main.java
Normal 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));
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
class For{
|
||||
|
||||
public For(){
|
||||
for(int i = 0; i < 10; i++){
|
||||
for(int i = 0; i < 10; ++i){
|
||||
int a;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ public class Increment {
|
||||
public int test;
|
||||
|
||||
public void increment(int p) {
|
||||
test = p++;
|
||||
this.test = p++;
|
||||
|
||||
for(int i = 1; i<=10; i++) {
|
||||
int a = 5;
|
||||
|
@@ -1,8 +0,0 @@
|
||||
class Null{
|
||||
|
||||
int a;
|
||||
|
||||
public Null(){
|
||||
this.a = 1;
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ class SelfReference {
|
||||
SelfReference selfReference;
|
||||
|
||||
int testMethod1() {
|
||||
return this.testMethod2();
|
||||
return testMethod2();
|
||||
}
|
||||
|
||||
int testMethod2() {
|
||||
|
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -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"}}}]}]}]}
|
Reference in New Issue
Block a user