+void check_code_for_break(code_t*c)
+{
+ while(c) {
+ if(c->opcode == OPCODE___BREAK__) {
+ char*name = string_cstr(c->data[0]);
+ syntaxerror("Unresolved \"break %s\"", name);
+ }
+ if(c->opcode == OPCODE___CONTINUE__) {
+ char*name = string_cstr(c->data[0]);
+ syntaxerror("Unresolved \"continue %s\"", name);
+ }
+ c=c->prev;
+ }
+}
+
+
+static void check_constant_against_type(classinfo_t*t, constant_t*c)
+{
+#define xassert(b) if(!(b)) syntaxerror("Invalid default value %s for type '%s'", constant_tostring(c), t->name)
+ if(TYPE_IS_NUMBER(t)) {
+ xassert(c->type == CONSTANT_FLOAT
+ || c->type == CONSTANT_INT
+ || c->type == CONSTANT_UINT);
+ } else if(TYPE_IS_UINT(t)) {
+ xassert(c->type == CONSTANT_UINT ||
+ (c->type == CONSTANT_INT && c->i>0));
+ } else if(TYPE_IS_INT(t)) {
+ xassert(c->type == CONSTANT_INT);
+ } else if(TYPE_IS_BOOLEAN(t)) {
+ xassert(c->type == CONSTANT_TRUE
+ || c->type == CONSTANT_FALSE);
+ }
+}
+
+static int flags2access(int flags)
+{
+ int access = 0;
+ if(flags&FLAG_PUBLIC) {
+ if(access&(FLAG_PRIVATE|FLAG_PROTECTED|FLAG_INTERNAL)) syntaxerror("invalid combination of access levels");
+ access = ACCESS_PACKAGE;
+ } else if(flags&FLAG_PRIVATE) {
+ if(access&(FLAG_PUBLIC|FLAG_PROTECTED|FLAG_INTERNAL)) syntaxerror("invalid combination of access levels");
+ access = ACCESS_PRIVATE;
+ } else if(flags&FLAG_PROTECTED) {
+ if(access&(FLAG_PUBLIC|FLAG_PRIVATE|FLAG_INTERNAL)) syntaxerror("invalid combination of access levels");
+ access = ACCESS_PROTECTED;
+ } else {
+ access = ACCESS_PACKAGEINTERNAL;
+ }
+ return access;
+}
+
+static memberinfo_t*registerfunction(enum yytokentype getset, int flags, char*name, params_t*params, classinfo_t*return_type, int slot)
+{
+ memberinfo_t*minfo = 0;
+ if(!state->cls) {
+ //package method
+ minfo = memberinfo_register_global(flags2access(flags), state->package, name, MEMBER_METHOD);
+ minfo->return_type = return_type;
+ } else if(getset != KW_GET && getset != KW_SET) {
+ //class method
+ if((minfo = registry_findmember(state->cls->info, name, 0))) {
+ if(minfo->parent == state->cls->info) {
+ syntaxerror("class already contains a member/method called '%s'", name);
+ } else if(!minfo->parent) {
+ syntaxerror("internal error: overriding method %s, which doesn't have parent", name);
+ } else {
+ if(!(minfo->flags&(FLAG_STATIC|FLAG_PRIVATE)))
+ syntaxerror("function %s already exists in superclass. Did you forget the 'override' keyword?");
+ }
+ }
+ minfo = memberinfo_register(state->cls->info, name, MEMBER_METHOD);
+ minfo->return_type = return_type;
+ // getslot on a member slot only returns "undefined", so no need
+ // to actually store these
+ //state->minfo->slot = state->method->abc->method->trait->slot_id;
+ } else {
+ //class getter/setter
+ int gs = getset==KW_GET?MEMBER_GET:MEMBER_SET;
+ classinfo_t*type=0;
+ if(getset == KW_GET)
+ type = return_type;
+ else if(params->list)
+ type = params->list->param->type;
+ // not sure wether to look into superclasses here, too
+ if((minfo=registry_findmember(state->cls->info, name, 0))) {
+ if(minfo->kind & ~(MEMBER_GET|MEMBER_SET))
+ syntaxerror("class already contains a member or method called '%s'", name);
+ if(minfo->kind & gs)
+ syntaxerror("getter/setter for '%s' already defined", name);
+ /* make a setter or getter into a getset */
+ minfo->kind |= gs;
+ if(!minfo->type)
+ minfo->type = type;
+ else
+ if(type && minfo->type != type)
+ syntaxerror("different type in getter and setter");
+ } else {
+ minfo = memberinfo_register(state->cls->info, name, gs);
+ minfo->type = type;
+ }
+ /* can't assign a slot as getter and setter might have different slots */
+ //minfo->slot = slot;
+ }
+ if(flags&FLAG_STATIC) minfo->flags |= FLAG_STATIC;
+ if(flags&FLAG_PUBLIC) minfo->flags |= FLAG_PUBLIC;
+ if(flags&FLAG_PRIVATE) minfo->flags |= FLAG_PRIVATE;
+ if(flags&FLAG_PROTECTED) minfo->flags |= FLAG_PROTECTED;
+ if(flags&FLAG_INTERNAL) minfo->flags |= FLAG_INTERNAL;
+ if(flags&FLAG_OVERRIDE) minfo->flags |= FLAG_OVERRIDE;
+ return minfo;
+}
+
+static void startfunction(token_t*ns, int flags, enum yytokentype getset, char*name,
+ params_t*params, classinfo_t*return_type)
+{
+ if(state->method) {
+ syntaxerror("not able to start another method scope");
+ }
+ new_state();
+ global->variable_count = 0;
+ state->method = rfx_calloc(sizeof(methodstate_t));
+ state->method->initcode = 0;
+ state->method->has_super = 0;
+ if(state->cls) {
+ state->method->is_constructor = !strcmp(state->cls->info->name,name);
+ state->cls->has_constructor |= state->method->is_constructor;
+
+ new_variable((flags&FLAG_STATIC)?"class":"this", state->cls->info, 0);
+ } else {
+ state->method->is_global = 1;
+ state->method->late_binding = 1; // for global methods, always push local_0 on the scope stack
+
+ new_variable("globalscope", 0, 0);
+ }
+
+ /* state->vars is initialized by state_new */
+
+ param_list_t*p=0;
+ for(p=params->list;p;p=p->next) {
+ new_variable(p->param->name, p->param->type, 0);
+ }
+ if(state->method->is_constructor)
+ name = "__as3_constructor__";
+ state->method->info = registerfunction(getset, flags, name, params, return_type, 0);
+}
+
+static void endfunction(token_t*ns, int flags, enum yytokentype getset, char*name,
+ params_t*params, classinfo_t*return_type, code_t*body)