Skip to content
Browse files

move more namespace generation into NamespaceGen class and avoid doub…

…le definitions of Sub ids
  • Loading branch information...
1 parent 53aab0c commit 5323c333734ce938908eed49091f0c1505ee0b27 @NotFound committed Jun 13, 2012
Showing with 70 additions and 40 deletions.
  1. +70 −40 winxedxx.winxed
View
110 winxedxx.winxed
@@ -2261,41 +2261,6 @@ function emit_namespacest(out, ns)
}
}
-function emit_namespace_initializers(var out, var ns)
-{
- var childs = {};
- for (var child in ns.namespaces) {
- string name = child.name;
- if (name == "Winxed_Builtins")
- continue;
- if (! exists childs[name])
- childs[name] = child;
- }
-
- int is_root = ns instanceof RootNamespace;
- if (! is_root)
- out.print("namespace ", ns.name, "\n{\n");
-
- out.print("static WxxNamespace &wxxGetCurrentNamespace()\n");
- out.print("{\n");
- out.print(" return getRootNamespace()");
- string nschain = "";
- var curns = ns;
- while (! (curns instanceof RootNamespace)) {
- nschain = ".childNamespace(\"" + string(curns.name) + "\")" + nschain;
- curns = curns.parent;
- }
- out.print(nschain, ";\n}\n");
-
- for (string childname in childs) {
- var child = childs[childname];
- emit_namespace_initializers(out, child);
- }
-
- if (! is_root)
- out.print("\n} // ", ns.name, "\n");
-}
-
function get_main(ns)
{
var functions = ns.funcont.functions;
@@ -2318,23 +2283,45 @@ class NamespaceGen
var childs;
var functions;
var classes;
+ var items;
function NamespaceGen(var namespacest)
{
self.st = namespacest;
var functions [];
+ var genitems [];
+ var genchilds [];
for_each(namespacest.items,
function(item)
{
- if (item instanceof FunctionStatement)
+ if (item instanceof FunctionStatement) {
push(functions, item);
+ push(genitems, item);
+ }
+ else if (item instanceof NamespaceStatement) {
+ var child = new ChildNamespaceGen(item);
+ push(genchilds, child);
+ push(genitems, child);
+ }
+ else
+ push(genitems, item);
});
self.functions = functions;
var childs [];
for (var childst in namespacest.namespaces) {
- push(childs, new ChildNamespaceGen(childst));
+ var child;
+ for (var ch in genchilds) {
+ if (ch.st === childst) {
+ child = ch;
+ break;
+ }
+ }
+ if (child == null)
+ child = new ChildNamespaceGen(childst);
+ push(childs, child);
}
self.childs = childs;
+ self.items = genitems;
}
function emit_declare(var out)
{
@@ -2361,8 +2348,10 @@ class NamespaceGen
}
function emit_declare_childsubid(var out, var key)
{
- for (var child in self.childs)
- child.emit_declare_subid(out, key);
+ for (var child in self.items) {
+ if (child instanceof NamespaceGen)
+ child.emit_declare_subid(out, key);
+ }
}
function emit_initialize(var out, string nsvarname)
{
@@ -2388,6 +2377,47 @@ class NamespaceGen
child.emit_initialize(out, childvarname);
}
}
+
+ function emit_namespace_initializers(var out)
+ {
+ var childs = {};
+ for (var child in self.childs) {
+ string name = child.name;
+ if (name == "Winxed_Builtins")
+ continue;
+ if (! exists childs[name])
+ childs[name] = child;
+ }
+
+ string nspath[];
+ for (var curns = self.st;
+ ! (curns instanceof RootNamespace);
+ curns = curns.parent)
+ unshift(nspath, curns.name);
+
+ out.print("// Initializing ");
+ if (elements(nspath))
+ out.print("namespace ", join(".", nspath));
+ else
+ out.print("root namespace");
+ out.print("\n");
+
+ self.emit_nsopen(out);
+
+ out.print("static WxxNamespace &wxxGetCurrentNamespace()\n");
+ out.print("{\n");
+ out.print(" return getRootNamespace()");
+ for (string nsname in nspath)
+ out.print(".childNamespace(\"" + nsname + "\")");
+ out.print(";\n}\n");
+
+ for (string childname in childs) {
+ var child = childs[childname];
+ child.emit_namespace_initializers(out);
+ }
+
+ self.emit_nsclose(out);
+ }
}
class ChildNamespaceGen : NamespaceGen
@@ -2551,7 +2581,7 @@ INITIALIZEREND:>>
emit_namespacest(self, ns);
- emit_namespace_initializers(self, ns);
+ nsgen.emit_namespace_initializers(self);
self.emit_initializer(parsed.rootns);

0 comments on commit 5323c33

Please sign in to comment.
Something went wrong with that request. Please try again.