+static methodinfo_t*registerfunction(enum yytokentype getset, modifiers_t*mod, char*name, params_t*params, classinfo_t*return_type, int slot)
+{
+ methodinfo_t*minfo = 0;
+ namespace_t ns = modifiers2access(mod);
+ if(!state->cls) {
+ //package method
+ minfo = methodinfo_register_global(ns.access, state->package, name);
+ minfo->return_type = return_type;
+ } else if(getset != KW_GET && getset != KW_SET) {
+ //class method
+ memberinfo_t* m = registry_findmember(state->cls->info, ns.name, name, 0);
+ if(m) {
+ syntaxerror("class already contains a %s '%s'", infotypename((slotinfo_t*)m), m->name);
+ }
+ minfo = methodinfo_register_onclass(state->cls->info, ns.access, ns.name, name);
+ 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?SUBTYPE_GET:SUBTYPE_SET;
+ classinfo_t*type=0;
+ if(getset == KW_GET) {
+ type = return_type;
+ } else if(params->list && params->list->param && !params->list->next) {
+ type = params->list->param->type;
+ } else
+ syntaxerror("setter function needs to take exactly one argument");
+ // not sure wether to look into superclasses here, too
+ minfo = (methodinfo_t*)registry_findmember(state->cls->info, ns.name, name, 1);
+ if(minfo) {
+ if(minfo->kind!=INFOTYPE_VAR)
+ syntaxerror("class already contains a method called '%s'", name);
+ if(!(minfo->subtype & (SUBTYPE_GETSET)))
+ syntaxerror("class already contains a field called '%s'", name);
+ if(minfo->subtype & gs)
+ syntaxerror("getter/setter for '%s' already defined", name);
+ /* make a setter or getter into a getset */
+ minfo->subtype |= gs;
+
+ /*
+ FIXME: this check needs to be done in pass 2
+
+ if((!minfo->return_type != !type) ||
+ (minfo->return_type && type &&
+ !strcmp(minfo->return_type->name, type->name))) {
+ syntaxerror("different type in getter and setter: %s and %s",
+ minfo->return_type?minfo->return_type->name:"*",
+ type?type->name:"*");
+ }*/
+ } else {
+ minfo = methodinfo_register_onclass(state->cls->info, ns.access, ns.name, name);
+ minfo->kind = INFOTYPE_VAR; //hack
+ minfo->subtype = gs;
+ minfo->return_type = type;
+ }
+
+ /* can't assign a slot as getter and setter might have different slots */
+ //minfo->slot = slot;
+ }
+ if(mod->flags&FLAG_FINAL) minfo->flags |= FLAG_FINAL;
+ if(mod->flags&FLAG_STATIC) minfo->flags |= FLAG_STATIC;
+ if(mod->flags&FLAG_OVERRIDE) minfo->flags |= FLAG_OVERRIDE;
+
+ return minfo;
+}
+
+static void innerfunction(char*name, params_t*params, classinfo_t*return_type)
+{
+ //parserassert(state->method && state->method->info);
+
+ methodstate_t*parent_method = state->method;
+
+ if(as3_pass==1) {
+ return_type = 0; // not valid in pass 1
+ }
+
+ new_state();
+ state->new_vars = 1;
+ state->allvars = dict_new();
+
+ if(as3_pass == 1) {
+ state->method = rfx_calloc(sizeof(methodstate_t));
+ state->method->inner = 1;
+ state->method->variable_count = 0;
+ state->method->abc = rfx_calloc(sizeof(abc_method_t));
+
+ NEW(methodinfo_t,minfo);
+ minfo->kind = INFOTYPE_METHOD;
+ minfo->access = ACCESS_PACKAGEINTERNAL;
+ minfo->name = name;
+ state->method->info = minfo;
+
+ if(parent_method)
+ list_append(parent_method->innerfunctions, state->method);
+
+ dict_put(global->token2info, (void*)(ptroff_t)as3_tokencount, state->method);
+
+ function_initvars(state->method, params, 0, 1);
+ }
+
+ if(as3_pass == 2) {
+ state->method = dict_lookup(global->token2info, (void*)(ptroff_t)as3_tokencount);
+ state->method->variable_count = 0;
+ parserassert(state->method);
+
+ state->method->info->return_type = return_type;
+ function_initvars(state->method, params, 0, 1);
+ }
+}
+
+static void startfunction(modifiers_t*mod, enum yytokentype getset, char*name,
+ params_t*params, classinfo_t*return_type)
+{
+ if(state->method && state->method->info) {
+ syntaxerror("not able to start another method scope");
+ }
+ new_state();
+ state->new_vars = 1;
+ state->allvars = dict_new();
+
+ if(as3_pass == 1) {
+ state->method = rfx_calloc(sizeof(methodstate_t));
+ state->method->has_super = 0;
+
+ if(state->cls) {
+ state->method->is_constructor = !strcmp(state->cls->info->name,name);
+ } else {
+ state->method->is_global = 1;
+ state->method->late_binding = 1; // for global methods, always push local_0 on the scope stack
+ }
+ if(state->method->is_constructor)
+ name = "__as3_constructor__";
+
+ state->method->info = registerfunction(getset, mod, name, params, return_type, 0);
+
+ function_initvars(state->method, params, mod->flags, 1);
+
+ dict_put(global->token2info, (void*)(ptroff_t)as3_tokencount, state->method);
+ }
+
+ if(as3_pass == 2) {
+ state->method = dict_lookup(global->token2info, (void*)(ptroff_t)as3_tokencount);
+ state->method->variable_count = 0;
+ parserassert(state->method);
+
+ if(state->cls) {
+ memberinfo_t*m = registry_findmember(state->cls->info, mod->ns, name, 2);
+ check_override(m, mod->flags);
+ }
+
+ if(state->cls) {
+ state->cls->has_constructor |= state->method->is_constructor;
+ }
+
+ function_initvars(state->method, params, mod->flags, 1);
+ }
+}