10000 Typing: Update Readme for type-checking part · compiler-experts/miniJava@ec51e45 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec51e45

Browse files
committed
Typing: Update Readme for type-checking part
1 parent a15c330 commit ec51e45

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,46 @@ If you are a team member of the project, please review the [Guidelines for Contr
164164
- [ ] check try statement
165165
- [x] `verify_constructors` that checks the type of constructors
166166
- [x] `verify_attributes` that checks the type of attributes
167+
- [x] create a local definition environment type called `current_env` it contains 3 fields as following
168+
- returntype: since attributes have no return value, so it sets to be `Type.Void`
169+
- variables: a `Hashtbl` that maps from local variable name to local variable declared type
170+
- this_class: the id of the current class
171+
- env_type: which is `attribute` here
172+
- [x] write a verification expression (`verify_expression`) that checks the declared type of an expression
173+
In `verify_expression`:
174+
- [x] check `New` expression type which instantiates a class
175+
- [x] check `NewArray` expression type which declares an array like: new int[5]
176+
- [x] check `Call` expression type which calls a method, here, we didn't check `this` keyword when calling a method. For the moment, it only supports the case when the class name has already existes in `class_en` hashtable.
177+
- [x] check `Attr` expression type which calls an attribute
178+
- [x] check `If` expression type
179+
- [x] check `Val` expression type which is the primitive type like int, string... in an expression
180+
- [x] check `Name` expression type which represents a variable
181+
- [x] check `ArrayInit` expression type which initializes an array like {1,2,3}
182+
- [ ] check `Array` expression type (TODO). This part has not been done for the moment
183+
- [x] check `AssignExp` expression type which compares an assignment operation type
184+
- [x] check `Post` expression type which is some post operations type, like: a++, b--...
185+
- [x] check `Pre` expression type which is some pre operations type, like: !a, ~b...
186+
- [x] cehck `Op` expression type which is some operation optype, like: ||, &&, +, -...
187+
- [x] check `CondOp` expression type which is conditional operation, like a ? b : c
188+
- [x] check `Cast` expression type
189+
- [x] check `Type` expression type
190+
- [x] check `ClassOf` expression type
191+
- [x] check `Instanceof` expression type
192+
- [x] check `VoidClass` expression
193+
- [x] write an verification method (`verify_assignop_type`) that checks the declared type of an attribute match the type of the expression. It has three inputs:
194+
- t1: the type of an attribute
195+
- t2: the type of the corresponding expression of an attribute
196+
- op: the type of operation, here is `Type.Assign`
167197

168198
##### Errors that can be found during Type-checking
169199

170200
- ArgumentAlreadyExists
171201
- when found duplicated argument in constructor argument list -> ArgumentAlreadyExists("[pident of argument]")
172202
- when found duplicated argument in method argument list -> ArgumentAlreadyExists("[pident of argument]")
173203
- ArgumentTypeNotExiste
204+
- when found the arguments in a called function don't existe a declared method
174205
- ArgumentTypeNotMatch
206+
- when found the arguments in a called function don't match a declared method -> ArgumentTypeNotMatch("Arguments\' type in "^meth_name^" not match")
175207
- AttributeAlreadyExists
176208
- when found duplicated attribute in class definition environment -> AttributeAlreadyExists("[aname of attribute]")
177209
- ClassAlreadyExists
@@ -200,13 +232,19 @@ If you are a team member of the project, please review the [Guidelines for Contr
200232
- when actual type of variable cannot be determined in the condition part of if statement (If(e,s,None)) -> UnknownActualType("[edesc]: unknow type in if condition")
201233
- when actual type of variable cannot be determined in the condition part of if else statement (If(e,s,Some s2)) -> UnknownActualType("[edesc]: unknow type in if else condition")
202234
- UnknownVariable
235+
- when the variable does not existe in current environment or global environment -> UnknownVariable("[variable_name]")
203236
- UnknownClass
204237
- UnknownMethod
205238
- WrongTypePrefixOperation
239+
- when the prefix operation type is not match -> WrongTypePrefixOperation("[operation, expr]")
206240
- WrongTypePostfixOperation
241+
- when the postfix operation type is not match -> WrongTypePostfixOperation("[operation, expr]")
207242
- WrongInvokedArgumentsLength
243+
- when actual and formal argument lists differ in length -> WrongInvokedArgumentsLength()
208244
- WrongTypesAssignOperation
245+
- when an assignment operation type is not match -> WrongTypesAssignOperation("[expr1_type, op, expr2_type]")
209246
- WrongTypesOperation
247+
- when an operation type is not match -> WrongTypesAssignOperation("[expr1_type, op, expr2_type]")
210248

211249
##### Errors that can not yet be found during Type-checking
212250

0 commit comments

Comments
 (0)
0