%nonassoc "false" "true" "null" "undefined" "super" "function"
%left above_function
-
%{
methodstate_t*is_inner_method;
} variable_t;
-static variable_t* find_variable(state_t*s, char*name)
+static variable_t* find_variable(state_t*s, const char*name)
{
if(s->method->no_variable_scoping) {
return dict_lookup(s->allvars, name);
syntaxerror("invalid combination of access levels and namespaces");
ns.access = ACCESS_NAMESPACE;
state_t*s = state;
- const char*url = (const char*)trie_lookup(active_namespaces, mod->ns);
+ const char*url = (const char*)trie_lookup(active_namespaces, (unsigned char*)mod->ns);
if(!url) {
/* shouldn't happen- the tokenizer only reports something as a namespace
if it was already registered */
}
FOR_IN : FOR_START FOR_IN_INIT "in" EXPRESSION ')' IF_CODEBLOCK {
- variable_t*var = find_variable(state, $2);
- if(!var) {
- syntaxerror("variable %s not known in this scope", $2);
- }
+ node_t*n = resolve_identifier($2);
+ typedcode_t w = node_write(n);
+
int it = alloc_local();
int array = alloc_local();
$$ = abc_nextname($$);
else
$$ = abc_nextvalue($$);
- $$ = converttype($$, 0, var->type);
- $$ = abc_setlocal($$, var->index);
+
+ $$ = converttype($$, 0, w.t);
+ $$ = code_append($$, w.c);
$$ = code_append($$, $6);
$$ = abc_jump($$, loopstart);
$$.c = code_append($$.c, paramcode);
$$.c = abc_constructprop2($$.c, name, $4.number);
multiname_destroy(name);
+ } else if(is_getlocal($$.c)) {
+ $$.c = code_append($$.c, paramcode);
+ $$.c = abc_construct($$.c, $4.number);
} else if(TYPE_IS_CLASS(v.t) && v.t->data) {
code_free($$.c);
classinfo_t*c = v.t->data;
SUBNODE: X_IDENTIFIER
| '*' {$$="*";}
-/*
-MAYBE_NS: T_IDENTIFIER "::" {$$=$1;}
- | T_NAMESPACE "::" {$$=(char*)$1;}
- | '*' "::" {$$="*";}
- | {$$=0;}*/
+%code {
+ node_t* resolve_identifier(const char*name);
+ node_t* get_descendants(node_t*e,const char*ns,const char*subnode,char multi, char attr)
+ {
+ typedcode_t v = node_read(e);
+ typedcode_t w;
+
+ multiname_t m = {0,0,0,subnode};
+ namespace_t zero = {ZERONAMESPACE,"*"};
+ if(!strcmp(ns,"*")) {
+ m.ns = &zero;
+ m.type = attr?QNAMEA:QNAME;
+ } else {
+ typedcode_t w = node_read(resolve_identifier(ns));
+ if(!TYPE_IS_NAMESPACE(w.t)) {
+ as3_softwarning("%s might not be a namespace", ns);
+ }
+ v.c = code_append(v.c, w.c);
+ v.c = converttype(v.c, w.t, TYPE_NAMESPACE);
+ m.type = attr?RTQNAMEA:RTQNAME;
+ }
+
+ if(!multi) {
+ v.c = abc_getproperty2(v.c, &m);
+ } else {
+ v.c = abc_getdescendants2(v.c, &m);
+ }
+
+ if(TYPE_IS_XML(v.t)) {
+ v.t = TYPE_XMLLIST;
+ } else {
+ v.c = abc_coerce_a(v.c);
+ v.t = TYPE_ANY;
+ }
+ return mkcodenode(v);
+ }
+};
E : E '.' ID_OR_NS "::" SUBNODE {
- typedcode_t v = node_read($1);
- typedcode_t w = node_read(resolve_identifier($3));
- v.c = code_append(v.c, w.c);
- if(!TYPE_IS_NAMESPACE(w.t)) {
- as3_softwarning("%s might not be a namespace", $3);
- }
- v.c = converttype(v.c, w.t, TYPE_NAMESPACE);
- multiname_t m = {RTQNAME, 0, 0, $5};
- v.c = abc_getproperty2(v.c, &m);
- if(TYPE_IS_XML(v.t)) {
- v.t = TYPE_XMLLIST;
- } else {
- v.c = abc_coerce_a(v.c);
- v.t = TYPE_ANY;
- }
- $$ = mkcodenode(v);
+ $$ = get_descendants($1, $3, $5, 0, 0);
}
E : E ".." SUBNODE {
typedcode_t v = node_read($1);
v.t = TYPE_XMLLIST;
$$ = mkcodenode(v);
}
+E : E ".." ID_OR_NS "::" SUBNODE {
+ $$ = get_descendants($1, $3, $5, 1, 0);
+}
E : E '.' '[' E ']' {
typedcode_t v = node_read($1);
typedcode_t w = node_read($4);
v.t = TYPE_STRING;
$$ = mkcodenode(v);
}
+
+E : E '.' '@' ID_OR_NS "::" SUBNODE {
+ $$ = get_descendants($1, $4, $6, 0, 1);
+}
+
E : E ".." '@' SUBNODE {
typedcode_t v = node_read($1);
multiname_t m = {MULTINAMEA, 0, &nopackage_namespace_set, $4};
v.t = TYPE_STRING;
$$ = mkcodenode(v);
}
+E : E ".." '@' ID_OR_NS "::" SUBNODE {
+ $$ = get_descendants($1, $4, $6, 1, 1);
+}
+
E : E '.' '@' '[' E ']' {
typedcode_t v = node_read($1);
typedcode_t w = node_read($5);
}
%code {
- node_t* resolve_identifier(char*name)
+ node_t* var_read(variable_t*v)
+ {
+ typedcode_t o;
+ o.c = abc_getlocal(0, v->index);
+ o.t = v->type;
+ return mkcodenode(o);
+ }
+
+ node_t* resolve_identifier(const char*name)
{
typedcode_t o;
o.t = 0;
/* look at variables */
if((v = find_variable(state, name))) {
// name is a local variable
- o.c = abc_getlocal(o.c, v->index);
- o.t = v->type;
- return mkcodenode(o);
+ return var_read(v);
}
if((v = find_slot(state->method, name))) {
o.c = abc_getscopeobject(o.c, 1);
if(!state->xmlfilter &&
(dict_contains(state->import_toplevel_packages, name) ||
registry_ispackage(name))) {
- o.c = abc___pushpackage__(o.c, name);
+ o.c = abc___pushpackage__(o.c, (char*)name);
o.t = 0;
return mkcodenode(o); //?
}
}
};
+/* TODO: causes 16 r/r conflicts */
+VAR_READ : T_NAMESPACE {
+ PASS2
+ $$ = resolve_identifier($1);
+}
VAR_READ : T_IDENTIFIER {
PASS1
/* Queue unresolved identifiers for checking against the parent
}
NAMESPACE_DECLARATION : MAYBE_MODIFIERS NAMESPACE_ID {
PASS12
- trie_put(active_namespaces, $2->name, (void*)$2->url);
+ trie_put(active_namespaces, (unsigned char*)$2->name, (void*)$2->url);
namespace_t access = modifiers2access(&$1);
varinfo_t* var = varinfo_register_global(access.access, state->package, $2->name);
DEFAULT_NAMESPACE : "default xml" "namespace" '=' E
{
- as3_warning("default xml namespaces not supported yet");
$$ = 0;
+ $$ = code_append($$, node_read($4).c);
+ $$ = abc_dxnslate($$);
}
USE_NAMESPACE : "use" "namespace" CLASS_SPEC {
syntaxerror("%s.%s is not a namespace", $3->package, $3->name);
url = s->value->ns->name;
- trie_put(active_namespaces, $3->name, (void*)url);
+ trie_put(active_namespaces, (unsigned char*)$3->name, (void*)url);
add_active_url(url);
$$=0;
}