You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -164,14 +164,46 @@ If you are a team member of the project, please review the [Guidelines for Contr
164
164
- [] check try statement
165
165
- [x]`verify_constructors` that checks the type of constructors
166
166
- [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`
167
197
168
198
##### Errors that can be found during Type-checking
169
199
170
200
- ArgumentAlreadyExists
171
201
- when found duplicated argument in constructor argument list -> ArgumentAlreadyExists("[pident of argument]")
172
202
- when found duplicated argument in method argument list -> ArgumentAlreadyExists("[pident of argument]")
173
203
- ArgumentTypeNotExiste
204
+
- when found the arguments in a called function don't existe a declared method
174
205
- ArgumentTypeNotMatch
206
+
- when found the arguments in a called function don't match a declared method -> ArgumentTypeNotMatch("Arguments\' type in "^meth_name^" not match")
175
207
- AttributeAlreadyExists
176
208
- when found duplicated attribute in class definition environment -> AttributeAlreadyExists("[aname of attribute]")
177
209
- ClassAlreadyExists
@@ -200,13 +232,19 @@ If you are a team member of the project, please review the [Guidelines for Contr
200
232
- 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")
201
233
- 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")
202
234
- UnknownVariable
235
+
- when the variable does not existe in current environment or global environment -> UnknownVariable("[variable_name]")
203
236
- UnknownClass
204
237
- UnknownMethod
205
238
- WrongTypePrefixOperation
239
+
- when the prefix operation type is not match -> WrongTypePrefixOperation("[operation, expr]")
206
240
- WrongTypePostfixOperation
241
+
- when the postfix operation type is not match -> WrongTypePostfixOperation("[operation, expr]")
207
242
- WrongInvokedArgumentsLength
243
+
- when actual and formal argument lists differ in length -> WrongInvokedArgumentsLength()
208
244
- WrongTypesAssignOperation
245
+
- when an assignment operation type is not match -> WrongTypesAssignOperation("[expr1_type, op, expr2_type]")
209
246
- WrongTypesOperation
247
+
- when an operation type is not match -> WrongTypesAssignOperation("[expr1_type, op, expr2_type]")
210
248
211
249
##### Errors that can not yet be found during Type-checking
0 commit comments