+ memberinfo_t*minfo = 0;
+ if(!state->cls) {
+ //package method
+ minfo = rfx_calloc(sizeof(memberinfo_t));
+ classinfo_t*c = classinfo_register(flags2access(flags), state->package, name, 0);
+ c->flags |= FLAG_METHOD;
+ c->function = minfo;
+ minfo->kind = MEMBER_METHOD;
+ minfo->name = name;
+ minfo->flags = FLAG_STATIC;
+ 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();
+ 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;
+ new_variable("globalscope", 0, 0);
+
+ /* for global methods, always push local_0 on the scope stack: */
+ state->method->late_binding = 1;
+ }
+
+ global->variable_count = 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)
+{
+ abc_method_t*f = 0;
+
+ multiname_t*type2 = sig2mname(return_type);
+ int slot = 0;
+ if(state->method->is_constructor) {
+ f = abc_class_getconstructor(state->cls->abc, type2);
+ } else if(!state->method->is_global) {
+ namespace_t mname_ns = {flags2access(flags), ""};
+ multiname_t mname = {QNAME, &mname_ns, 0, name};
+
+ if(flags&FLAG_STATIC)
+ f = abc_class_staticmethod(state->cls->abc, type2, &mname);
+ else
+ f = abc_class_method(state->cls->abc, type2, &mname);
+ slot = f->trait->slot_id;
+ } else {
+ namespace_t mname_ns = {flags2access(flags), state->package};
+ multiname_t mname = {QNAME, &mname_ns, 0, name};
+
+ f = abc_method_new(global->file, type2, 1);
+ trait_t*t = trait_new_method(&global->init->traits, multiname_clone(&mname), f);
+ //abc_code_t*c = global->init->method->body->code;
+ }
+ //flash doesn't seem to allow us to access function slots
+ //state->method->info->slot = slot;
+
+ if(flags&FLAG_OVERRIDE) f->trait->attributes |= TRAIT_ATTR_OVERRIDE;
+ if(getset == KW_GET) f->trait->kind = TRAIT_GETTER;
+ if(getset == KW_SET) f->trait->kind = TRAIT_SETTER;
+ if(params->varargs) f->flags |= METHOD_NEED_REST;
+
+ char opt=0;
+ param_list_t*p=0;
+ for(p=params->list;p;p=p->next) {
+ if(params->varargs && !p->next) {
+ break; //varargs: omit last parameter in function signature
+ }
+ multiname_t*m = sig2mname(p->param->type);
+ list_append(f->parameters, m);
+ if(p->param->value) {
+ check_constant_against_type(p->param->type, p->param->value);
+ opt=1;list_append(f->optional_parameters, p->param->value);
+ } else if(opt) {
+ syntaxerror("non-optional parameter not allowed after optional parameters");
+ }
+ }
+ check_code_for_break(body);
+
+ if(f->body)
+ f->body->code = body;
+ else //interface
+ if(body)
+ syntaxerror("interface methods can't have a method body");
+
+ free(state->method);state->method=0;
+ old_state();