mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 03:08:04 +00:00
Added stuff for präsi
This commit is contained in:
parent
f63df782bc
commit
dfe24f4a4b
@ -215,6 +215,697 @@ While -[#008200,dashed]u-^ Statement
|
||||
|
||||
</Transform>
|
||||
|
||||
## TypedAST
|
||||
|
||||
|
||||
<Transform :scale="1">
|
||||
|
||||
```plantuml
|
||||
@startuml
|
||||
|
||||
!theme plain
|
||||
top to bottom direction
|
||||
skinparam linetype ortho
|
||||
|
||||
class TypedAssignment {
|
||||
+ TypedAssignment(TypedExpression, TypedFieldVarAccess, Type):
|
||||
+ TypedAssignment(TypedProgram, Assignment):
|
||||
- location: TypedFieldVarAccess
|
||||
- type: Type
|
||||
- value: TypedExpression
|
||||
+ toString(): String
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
- convertToTypedAssignment(TypedProgram, Assignment): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- getTypeFromConstructorOrField(TypedConstructor, String, TypedClass): Type
|
||||
- getOwnerChain(MethodContext): void
|
||||
- getTypeLeft(TypedProgram): Type
|
||||
- getTypeFromMethodOrField(TypedMethod, String, TypedClass): Type
|
||||
+ codeGen(MethodContext): void
|
||||
location: TypedFieldVarAccess
|
||||
value: TypedExpression
|
||||
type: Type
|
||||
}
|
||||
class TypedBinary {
|
||||
+ TypedBinary(TypedExpression, Operator, TypedExpression, Type):
|
||||
+ TypedBinary():
|
||||
+ TypedBinary(TypedProgram, Binary):
|
||||
- left: TypedExpression
|
||||
- right: TypedExpression
|
||||
- type: Type
|
||||
- op: Operator
|
||||
+ equals(Object): boolean
|
||||
+ hashCode(): int
|
||||
# canEqual(Object): boolean
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ codeGen(MethodContext): void
|
||||
- convertToTypedBinary(TypedProgram, Binary): void
|
||||
left: TypedExpression
|
||||
type: Type
|
||||
op: Operator
|
||||
right: TypedExpression
|
||||
}
|
||||
class TypedBlock {
|
||||
+ TypedBlock(List<TypedLocalVariable>, List<TypedStatement>, Type):
|
||||
+ TypedBlock():
|
||||
+ TypedBlock(List<TypedLocalVariable>, List<TypedStatement>):
|
||||
+ TypedBlock(TypedProgram, Block):
|
||||
- type: Type
|
||||
- vars: List<TypedLocalVariable>
|
||||
- stmts: List<TypedStatement>
|
||||
+ toString(): String
|
||||
+ equals(Object): boolean
|
||||
+ hashCode(): int
|
||||
# canEqual(Object): boolean
|
||||
- clearLocalVariable(TypedProgram): void
|
||||
- convertToTypedBlock(TypedProgram, Block): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ codeGen(MethodContext): void
|
||||
stmts: List<TypedStatement>
|
||||
vars: List<TypedLocalVariable>
|
||||
type: Type
|
||||
}
|
||||
class TypedBoolLiteral {
|
||||
+ TypedBoolLiteral(Boolean, Type):
|
||||
+ TypedBoolLiteral():
|
||||
+ TypedBoolLiteral(BoolLiteral):
|
||||
- type: Type
|
||||
- value: Boolean
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(MethodContext): void
|
||||
- convertToTypedBoolLiteral(BoolLiteral): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
value: Boolean
|
||||
type: Type
|
||||
}
|
||||
class TypedBreak {
|
||||
+ TypedBreak():
|
||||
- type: Type
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ codeGen(MethodContext): void
|
||||
type: Type
|
||||
}
|
||||
class TypedCharLiteral {
|
||||
+ TypedCharLiteral(char, Type):
|
||||
+ TypedCharLiteral(CharLiteral):
|
||||
- value: char
|
||||
- type: Type
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- convertToCharLiteral(CharLiteral): void
|
||||
+ codeGen(MethodContext): void
|
||||
value: char
|
||||
type: Type
|
||||
}
|
||||
class TypedClass {
|
||||
+ TypedClass(String, List<TypedDeclaration>, List<TypedMethod>, List<TypedConstructor>, TypedMain, TypedMethod, TypedConstructor, Type, boolean):
|
||||
+ TypedClass():
|
||||
+ TypedClass(String, List<TypedDeclaration>, List<TypedMethod>, List<TypedConstructor>, TypedMain, TypedMethod, TypedConstructor, Type):
|
||||
+ TypedClass(Class):
|
||||
- typedMethods: List<TypedMethod>
|
||||
- typedConstructors: List<TypedConstructor>
|
||||
- currentMethod: TypedMethod
|
||||
- isMainCurrentMethod: boolean
|
||||
- className: String
|
||||
- typedMain: TypedMain
|
||||
- type: Type
|
||||
- currentConstructor: TypedConstructor
|
||||
- typedDeclarations: List<TypedDeclaration>
|
||||
+ isParameterNameInCurrentConstructor(String): boolean
|
||||
+ codeGenClassWriter(): ClassWriter
|
||||
+ toString(): String
|
||||
+ hashCode(): int
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ isParameterWitNameInCurrentMethod(String): boolean
|
||||
+ exitCurrentConstructor(): void
|
||||
+ isMethodOfCurrentClass(String): boolean
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ getFieldType(String): Type
|
||||
+ getMethodType(String): Type
|
||||
+ getParameterTypeInCurrentConstructor(String): Type
|
||||
+ enterCurrentMethod(TypedMethod): void
|
||||
+ getParameterTypeInCurrentMethod(String): Type
|
||||
+ enterCurrentConstructor(TypedConstructor): void
|
||||
+ codeGen(): byte[]
|
||||
+ covertBlocksOfConstructorsAndMethods(TypedProgram, Class): void
|
||||
+ convertMethodsAndConstructorsAndFields(TypedProgram, Class): void
|
||||
+ isThereField(String): boolean
|
||||
+ isParameterWitNameInCurrentConstructor(String): boolean
|
||||
+ exitCurrentMethod(): void
|
||||
+ checkMethodExists(TypedMethod): void
|
||||
currentConstructorPresent: boolean
|
||||
typedConstructors: List<TypedConstructor>
|
||||
currentMethod: TypedMethod
|
||||
typedMain: TypedMain
|
||||
type: Type
|
||||
typedDeclarations: List<TypedDeclaration>
|
||||
currentConstructor: TypedConstructor
|
||||
className: String
|
||||
typedMethods: List<TypedMethod>
|
||||
currentMainMethodPresent: boolean
|
||||
isMainCurrentMethod: boolean
|
||||
currentMethodPresent: boolean
|
||||
}
|
||||
class TypedConstructor {
|
||||
+ TypedConstructor(String, List<TypedParameter>, TypedBlock, Type, List<TypedLocalVariable>):
|
||||
+ TypedConstructor():
|
||||
+ TypedConstructor(String, List<TypedParameter>, TypedBlock):
|
||||
+ TypedConstructor(Constructor, String):
|
||||
- localVariables: List<TypedLocalVariable>
|
||||
- name: String
|
||||
- typedBlock: TypedBlock
|
||||
- type: Type
|
||||
- typedParameters: List<TypedParameter>
|
||||
+ toString(): String
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ equals(Object): boolean
|
||||
- checkIfParameterExists(String): void
|
||||
+ deleteLocalVariableInConstructor(String): void
|
||||
+ isLocalVariablePresent(String): boolean
|
||||
- convertToTypedConstructor(Constructor, String): void
|
||||
+ getLocalVariableType(String): Type
|
||||
- convertToTypedParameter(List<Parameter>): void
|
||||
+ isParameterPresent(String): boolean
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ convertToBlock(TypedProgram, Constructor): void
|
||||
+ codeGen(ClassContext): void
|
||||
+ isLocalVariableInConstructor(String): boolean
|
||||
localVariables: List<TypedLocalVariable>
|
||||
name: String
|
||||
typedParameters: List<TypedParameter>
|
||||
type: Type
|
||||
typedBlock: TypedBlock
|
||||
}
|
||||
class TypedContinue {
|
||||
+ TypedContinue():
|
||||
- type: Type
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ codeGen(MethodContext): void
|
||||
type: Type
|
||||
}
|
||||
class TypedDeclaration {
|
||||
+ TypedDeclaration(TypedProgram, Declaration):
|
||||
+ TypedDeclaration(String, Type):
|
||||
+ TypedDeclaration():
|
||||
- name: String
|
||||
- type: Type
|
||||
+ equals(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- convertToTypedDeclaration(TypedProgram, Declaration): void
|
||||
+ codeGen(ClassWriter): void
|
||||
name: String
|
||||
type: Type
|
||||
}
|
||||
class TypedDoWhile {
|
||||
+ TypedDoWhile(TypedBlock, TypedExpression, Type):
|
||||
+ TypedDoWhile(TypedProgram, DoWhile):
|
||||
- cond: TypedExpression
|
||||
- type: Type
|
||||
- typedBlock: TypedBlock
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
- convertToTypedDoWhile(TypedProgram, DoWhile): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ codeGen(MethodContext): void
|
||||
cond: TypedExpression
|
||||
typedBlock: TypedBlock
|
||||
type: Type
|
||||
}
|
||||
interface TypedExpression << interface >> {
|
||||
+ codeGen(MethodContext): void
|
||||
type: Type
|
||||
}
|
||||
class TypedExpressionUtil {
|
||||
+ TypedExpressionUtil():
|
||||
+ convertExpression(TypedProgram, Expression): TypedExpression
|
||||
}
|
||||
class TypedFieldVarAccess {
|
||||
+ TypedFieldVarAccess(Boolean, TypedExpression, String, Type):
|
||||
+ TypedFieldVarAccess():
|
||||
+ TypedFieldVarAccess(TypedProgram, FieldVarAccess):
|
||||
- field: Boolean
|
||||
- type: Type
|
||||
- name: String
|
||||
- recursiveOwnerChain: TypedExpression
|
||||
# canEqual(Object): boolean
|
||||
+ toString(): String
|
||||
+ equals(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ codeGen(MethodContext): void
|
||||
- checkFieldOrMethodOrRecursiveType(TypedProgram): Type
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- checkMethodVariableType(TypedProgram): Type
|
||||
- convertToTypedFieldVarAccess(TypedProgram, FieldVarAccess): void
|
||||
- checkVariableType(TypedProgram): Type
|
||||
- checkConstructorVariableType(TypedProgram): Type
|
||||
- checkFieldOrMethodType(TypedProgram): Type
|
||||
- checkTypeField(TypedProgram): Type
|
||||
name: String
|
||||
type: Type
|
||||
recursiveOwnerChain: TypedExpression
|
||||
field: Boolean
|
||||
}
|
||||
class TypedFor {
|
||||
+ TypedFor():
|
||||
+ TypedFor(TypedAssignment, TypedExpression, TypedAssignment, TypedBlock, Type):
|
||||
+ TypedFor(TypedProgram, For):
|
||||
- assign: TypedAssignment
|
||||
- typedBlock: TypedBlock
|
||||
- type: Type
|
||||
- cond: TypedExpression
|
||||
- inc: TypedAssignment
|
||||
+ hashCode(): int
|
||||
# canEqual(Object): boolean
|
||||
+ toString(): String
|
||||
+ equals(Object): boolean
|
||||
+ codeGen(MethodContext): void
|
||||
- convertToTypedFor(TypedProgram, For): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
inc: TypedAssignment
|
||||
type: Type
|
||||
cond: TypedExpression
|
||||
typedBlock: TypedBlock
|
||||
assign: TypedAssignment
|
||||
}
|
||||
class TypedIfElse {
|
||||
+ TypedIfElse(TypedExpression, TypedBlock, TypedBlock, Type):
|
||||
+ TypedIfElse():
|
||||
+ TypedIfElse(TypedProgram, IfElse):
|
||||
- typedCon: TypedExpression
|
||||
- elseTypedBlock: TypedBlock
|
||||
- ifTypedBlock: TypedBlock
|
||||
- type: Type
|
||||
+ toString(): String
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ codeGen(MethodContext): void
|
||||
- convertToTypedIfElse(TypedProgram, IfElse): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
elseTypedBlock: TypedBlock
|
||||
type: Type
|
||||
ifTypedBlock: TypedBlock
|
||||
typedCon: TypedExpression
|
||||
}
|
||||
class TypedIntLiteral {
|
||||
+ TypedIntLiteral(Integer, Type):
|
||||
+ TypedIntLiteral():
|
||||
+ TypedIntLiteral(Integer):
|
||||
+ TypedIntLiteral(IntLiteral):
|
||||
- value: Integer
|
||||
- type: Type
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(MethodContext): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- convertToTypedIntLiteral(IntLiteral): void
|
||||
value: Integer
|
||||
type: Type
|
||||
}
|
||||
class TypedLocalVariable {
|
||||
+ TypedLocalVariable(TypedProgram, Declaration):
|
||||
+ TypedLocalVariable(String, Type):
|
||||
+ TypedLocalVariable():
|
||||
- type: Type
|
||||
- name: String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ equals(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(MethodVisitor, MethodContext): void
|
||||
- convertToTypedLocalVariable(Declaration): void
|
||||
name: String
|
||||
type: Type
|
||||
}
|
||||
class TypedMain {
|
||||
+ TypedMain(Type, TypedMethod):
|
||||
+ TypedMain():
|
||||
- type: Type
|
||||
- typedMethod: TypedMethod
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(ClassContext): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ convertToTypedMethod(TypedProgram, Class): void
|
||||
typedMethod: TypedMethod
|
||||
type: Type
|
||||
}
|
||||
class TypedMethod {
|
||||
+ TypedMethod(String, Type, List<TypedParameter>, List<TypedLocalVariable>, TypedBlock):
|
||||
+ TypedMethod():
|
||||
+ TypedMethod(TypedProgram, Method):
|
||||
- returnType: Type
|
||||
- typedBlock: TypedBlock
|
||||
- localVariables: List<TypedLocalVariable>
|
||||
- name: String
|
||||
- typedParameters: List<TypedParameter>
|
||||
+ toString(): String
|
||||
- convertToTypedMethod(TypedProgram, Method): void
|
||||
+ equals(Object): boolean
|
||||
+ codeGen(ClassContext): void
|
||||
+ codeGenMain(ClassContext): void
|
||||
- convertToTypedParameter(List<Parameter>): void
|
||||
- checkReturn(List<TypedStatement>): boolean
|
||||
+ isLocalVariablePresent(String): boolean
|
||||
+ isParameterPresent(String): boolean
|
||||
+ deleteLocalVariableInMethod(String): void
|
||||
+ convertToTypedBlock(TypedProgram, Method): void
|
||||
+ isLocalVariableInMethod(String): boolean
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ getLocalVariableType(String): Type
|
||||
+ checkIfParameterExists(String): void
|
||||
localVariables: List<TypedLocalVariable>
|
||||
name: String
|
||||
typedParameters: List<TypedParameter>
|
||||
returnType: Type
|
||||
typedBlock: TypedBlock
|
||||
}
|
||||
class TypedMethodCall {
|
||||
+ TypedMethodCall():
|
||||
+ TypedMethodCall(TypedFieldVarAccess, List<TypedExpression>, Type):
|
||||
+ TypedMethodCall(TypedProgram, MethodCall):
|
||||
- recipient: TypedFieldVarAccess
|
||||
- args: List<TypedExpression>
|
||||
- type: Type
|
||||
+ hashCode(): int
|
||||
+ equals(Object): boolean
|
||||
+ toString(): String
|
||||
# canEqual(Object): boolean
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ codeGen(MethodContext): void
|
||||
- getOwnerChain(MethodContext): void
|
||||
+ findMatchingMethod(TypedClass, String): Optional<Type>
|
||||
- convertToTypedMethodCall(TypedProgram, MethodCall): void
|
||||
recipient: TypedFieldVarAccess
|
||||
args: List<TypedExpression>
|
||||
type: Type
|
||||
}
|
||||
class TypedNew {
|
||||
+ TypedNew(Type, List<TypedExpression>):
|
||||
+ TypedNew(TypedProgram, New):
|
||||
- type: Type
|
||||
- args: List<TypedExpression>
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(MethodContext): void
|
||||
- convertToTypedNew(TypedProgram, New): void
|
||||
- findMatchingConstructorType(TypedProgram, List<TypedExpression>): Type
|
||||
+ typeCheck(TypedProgram): Type
|
||||
args: List<TypedExpression>
|
||||
type: Type
|
||||
}
|
||||
interface TypedNode << interface >> {
|
||||
+ typeCheck(TypedProgram): Type
|
||||
}
|
||||
class TypedParameter {
|
||||
+ TypedParameter(String, Type):
|
||||
+ TypedParameter(Parameter):
|
||||
- paraName: String
|
||||
- type: Type
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
+ equals(Object): boolean
|
||||
- convertToTypedParameter(Parameter): void
|
||||
paraName: String
|
||||
type: Type
|
||||
}
|
||||
class TypedPrint {
|
||||
+ TypedPrint(TypedProgram, Print):
|
||||
+ TypedPrint(TypedExpression, Type):
|
||||
+ codeGen(MethodContext): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
}
|
||||
class TypedProgram {
|
||||
+ TypedProgram(List<TypedClass>, TypedClass):
|
||||
+ TypedProgram(Program):
|
||||
- typedClasses: List<TypedClass>
|
||||
- currentClass: TypedClass
|
||||
+ isTypedClassPresent(String): boolean
|
||||
+ toString(): String
|
||||
+ getTypeOfFieldNameInClass(String, String): Type
|
||||
+ getTypedClass(String): TypedClass
|
||||
+ startConversion(Program): void
|
||||
- exitCurrentClass(): void
|
||||
+ equals(Object): boolean
|
||||
+ isClassWithNamePresent(String): boolean
|
||||
+ getTypeOfFieldOrMethodNameInClass(String, String): Type
|
||||
- enterCurrentClass(TypedClass): void
|
||||
currentClass: TypedClass
|
||||
typedClasses: List<TypedClass>
|
||||
}
|
||||
class TypedReturn {
|
||||
+ TypedReturn():
|
||||
+ TypedReturn(TypedExpression, Type):
|
||||
+ TypedReturn(TypedProgram, Return):
|
||||
- ret: TypedExpression
|
||||
- type: Type
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(MethodContext): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- convertToTypedReturn(TypedProgram, Return): void
|
||||
ret: TypedExpression
|
||||
type: Type
|
||||
}
|
||||
interface TypedStatement << interface >> {
|
||||
+ codeGen(MethodContext): void
|
||||
}
|
||||
class TypedUnary {
|
||||
+ TypedUnary(UnaryOperator, TypedExpression, Type):
|
||||
+ TypedUnary(TypedProgram, Unary):
|
||||
- type: Type
|
||||
- op: UnaryOperator
|
||||
- right: TypedExpression
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- convertToTypedUnary(TypedProgram, Unary): void
|
||||
+ codeGen(MethodContext): void
|
||||
right: TypedExpression
|
||||
op: UnaryOperator
|
||||
type: Type
|
||||
}
|
||||
class TypedWhile {
|
||||
+ TypedWhile(TypedExpression, TypedBlock, Type):
|
||||
+ TypedWhile(TypedProgram, While):
|
||||
- type: Type
|
||||
- cond: TypedExpression
|
||||
- typedBlock: TypedBlock
|
||||
+ equals(Object): boolean
|
||||
# canEqual(Object): boolean
|
||||
+ hashCode(): int
|
||||
+ toString(): String
|
||||
+ codeGen(MethodContext): void
|
||||
+ typeCheck(TypedProgram): Type
|
||||
- convertToTypedWhile(TypedProgram, While): void
|
||||
cond: TypedExpression
|
||||
typedBlock: TypedBlock
|
||||
type: Type
|
||||
}
|
||||
|
||||
TypedAssignment -[#008200,dashed]u-^ TypedStatement
|
||||
TypedBinary -[#008200,dashed]u-^ TypedExpression
|
||||
TypedBlock -[#008200,dashed]u-^ TypedNode
|
||||
TypedBoolLiteral -[#008200,dashed]u-^ TypedExpression
|
||||
TypedBreak -[#008200,dashed]u-^ TypedStatement
|
||||
TypedCharLiteral -[#008200,dashed]u-^ TypedExpression
|
||||
TypedClass -[#008200,dashed]u-^ TypedNode
|
||||
TypedConstructor -[#008200,dashed]u-^ TypedNode
|
||||
TypedContinue -[#008200,dashed]u-^ TypedStatement
|
||||
TypedDeclaration -[#008200,dashed]u-^ TypedNode
|
||||
TypedDoWhile -[#008200,dashed]u-^ TypedStatement
|
||||
TypedExpression -[#008200,plain]u-^ TypedNode
|
||||
TypedFieldVarAccess -[#008200,dashed]u-^ TypedExpression
|
||||
TypedFor -[#008200,dashed]u-^ TypedStatement
|
||||
TypedIfElse -[#008200,dashed]u-^ TypedStatement
|
||||
TypedIntLiteral -[#008200,dashed]u-^ TypedExpression
|
||||
TypedLocalVariable -[#008200,dashed]u-^ TypedNode
|
||||
TypedMain -[#008200,dashed]u-^ TypedNode
|
||||
TypedMethod -[#008200,dashed]u-^ TypedNode
|
||||
TypedMethodCall -[#008200,dashed]u-^ TypedExpression
|
||||
TypedMethodCall -[#008200,dashed]u-^ TypedStatement
|
||||
TypedNew -[#008200,dashed]u-^ TypedExpression
|
||||
TypedNew -[#008200,dashed]u-^ TypedStatement
|
||||
TypedParameter -[#008200,dashed]u-^ TypedNode
|
||||
TypedPrint -[#008200,dashed]u-^ TypedStatement
|
||||
TypedReturn -[#008200,dashed]u-^ TypedStatement
|
||||
TypedStatement -[#008200,plain]u-^ TypedNode
|
||||
TypedUnary -[#008200,dashed]u-^ TypedExpression
|
||||
TypedWhile -[#008200,dashed]u-^ TypedStatement
|
||||
@enduml
|
||||
|
||||
```
|
||||
</Transform>
|
||||
|
||||
---
|
||||
|
||||
# Grobe TypedAST Struktur
|
||||
|
||||
<Transform :scale="0.8">
|
||||
```plantuml
|
||||
@startuml
|
||||
|
||||
!theme plain
|
||||
left to right direction
|
||||
skinparam linetype ortho
|
||||
|
||||
interface TypedExpression << interface >> {
|
||||
+ codeGen(MethodContext): void
|
||||
type: Type
|
||||
}
|
||||
interface TypedNode << interface >> {
|
||||
+ typeCheck(TypedProgram): Type
|
||||
}
|
||||
interface TypedStatement << interface >> {
|
||||
+ codeGen(MethodContext): void
|
||||
}
|
||||
|
||||
class TypedClass{
|
||||
+ typeCheck(TypedProgram): Type
|
||||
}
|
||||
|
||||
class TypedWhile{
|
||||
+ typeCheck(TypedProgram): Type
|
||||
}
|
||||
|
||||
class TypedBinary{
|
||||
+ typeCheck(TypedProgram): Type
|
||||
}
|
||||
|
||||
TypedExpression -[#008200,plain]r-^ TypedNode
|
||||
TypedStatement -[#008200,plain]l-^ TypedNode
|
||||
TypedWhile -[#008200,dashed]-^ TypedStatement
|
||||
TypedClass -[#008200,dashed]-^ TypedNode
|
||||
TypedBinary -[#008200,dashed]-^ TypedExpression
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
</Transform>
|
||||
|
||||
---
|
||||
|
||||
# Phasen der Typisierung
|
||||
|
||||
- Initisialisierungsphase
|
||||
- Programm -> Klassen (Name, Feld-Variablen, Methoden, Konstruktoren)
|
||||
- Konvertierungsphase
|
||||
- Überführung von untypisierten AST zu typisierten AST
|
||||
- TypeCheck-Phase
|
||||
- Semantische Überprüfung
|
||||
- Ausführung von Blöcken
|
||||
---
|
||||
|
||||
## Konvertierung von untypisierten AST zu typisierten AST
|
||||
|
||||
<Transform :scale="0.8">
|
||||
|
||||
```java
|
||||
public class TypedDeclaration implements TypedNode {
|
||||
private String name;
|
||||
private Type type;
|
||||
|
||||
...
|
||||
|
||||
private void convertToTypedDeclaration(Declaration declaration) {
|
||||
name = declaration.name();
|
||||
type = declaration.type();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</Transform>
|
||||
|
||||
|
||||
---
|
||||
|
||||
# TypeCheck von While-Statement
|
||||
|
||||
<Transform :scale="0.9">
|
||||
|
||||
```java
|
||||
public class TypedWhile implements TypedStatement {
|
||||
private TypedExpression cond;
|
||||
private TypedBlock typedBlock;
|
||||
private Type type;
|
||||
|
||||
...
|
||||
|
||||
@Override
|
||||
public Type typeCheck(TypedProgram typedProgram) {
|
||||
if (cond.typeCheck(typedProgram) != Type.BOOL) {
|
||||
throw new InvalidWhileConditionException();
|
||||
}
|
||||
type = typedBlock.typeCheck(typedProgram);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</Transform>
|
||||
|
||||
---
|
||||
|
||||
# Speichern von lokalen Variablen
|
||||
|
||||
- Methoden und Konstruktoren haben jeweils eine Liste von lokalen Variablen
|
||||
|
||||
<Transform :scale="0.8">
|
||||
|
||||
```java
|
||||
public int calculateResult(boolean isMultiple, int x, int y) {
|
||||
int resultat = 0;// add resultat to list
|
||||
|
||||
if(isMultiple) {
|
||||
int a = x * y;// add a to list
|
||||
|
||||
resultat = a;
|
||||
}// remove a from list
|
||||
else {
|
||||
int b = x + y;// add b to list
|
||||
|
||||
resultat = b;
|
||||
} // remove b from list
|
||||
|
||||
return resultat;
|
||||
} // clear list
|
||||
```
|
||||
|
||||
</Transform>
|
||||
|
||||
---
|
||||
|
||||
# Code Generierung
|
||||
|
Loading…
Reference in New Issue
Block a user