| | 1221 | if _eventType inherits MethodSig |
| | 1222 | _params = _eventType.params |
| | 1223 | else |
| | 1224 | member = _eventType.memberForName('invoke') |
| | 1225 | if member inherits Method |
| | 1226 | _params = member.params |
| | 1227 | else |
| | 1228 | .throwError('Cannot find a single "invoke" method for "_eventType.name".') |
| | 1229 | # TODO: check type compatibility of exprs with params |
| | 1230 | args = _exprs[1:] |
| | 1231 | params = _params |
| | 1232 | unThis = 'Unnecessary "this" which is already implied by raising an event. You can remove it.' |
| | 1233 | if args.count == params.count |
| | 1234 | if args.count > 0 and args[0] inherits ThisLit |
| | 1235 | .compiler.warning(this, unThis) |
| | 1236 | else if args.count == params.count - 1 |
| | 1237 | # off by one. |
| | 1238 | if args[0] inherits ThisLit |
| | 1239 | .compiler.warning(this, unThis) |
| | 1240 | # since we have 'this', try appending the args object |
| | 1241 | args.add(_postCallForType(params[params.count-1].type)) |
| | 1242 | else |
| | 1243 | # since we don't have 'this', try prepending 'this' |
| | 1244 | args.insert(0, ThisLit(.token, .compiler.boxStack.peek).bindImp) |
| | 1245 | else if args.count == 0 and params.count == 2 |
| | 1246 | # missing both 'this' and event args |
| | 1247 | args.add(ThisLit(.token, .compiler.boxStack.peek).bindImp) |
| | 1248 | args.add(_postCallForType(params[params.count-1].type)) |
| | 1249 | else |
| | 1250 | .throwError('Event expects [params.count] arguments, but the "raise" statement is providing [args.count].') |
| | 1251 | _args = args |
| | 1252 | |
| | 1253 | def _postCallForType(type as IType) as PostCallExpr |
| | 1254 | inits = type.memberForName('init') |
| | 1255 | if inits inherits Initializer |
| | 1256 | if inits.params.count <> 0 |
| | 1257 | .throwError('Missing argument for "raise" of type "[type.name]".') |
| | 1258 | else |
| | 1259 | token = .token.copy('ID', type.name) |
| | 1260 | return PostCallExpr(token, TypeExpr(token, type), List<of Expr>()).bindImp |
| | 1261 | else |
| | 1262 | .throwError('Missing argument for "raise" of type "[type.name]".') |
| | 1263 | throw FallThroughException() # suppress an error |