Beispiel #1
0
 def __init__(self, aai):
     SinglePartCompilable.__init__(self)
     self.value = DuckTypedDict(['compile'])
     for k, v in aai.items():
         if isinstance(v, SinglePartCompilable):
             self.value[k] = v
         else:
             self.value[k] = self.type_map[type(v)](v)
Beispiel #2
0
    def __init__(self, name):
        SinglePartCompilable.__init__(self)

        self.__name = name
        self.members = DuckTypedDict(['compile'])
        self.statics = DuckTypedDict(['compile'])
        self.ctor = ConstructorDefinition(self.name)
        self.dtor = DestructorDefinition(self.name)
        self.preamble = DuckTypedList(['compile'])
        self.mixins = DuckTypedList(['compile'])
        self.mixins.append(ObjectReference("qx.locale.MTranslation"))
        self.base_class = None
        self.assets = set()
Beispiel #3
0
class AssociativeArrayInitialization(SinglePartCompilable):
    type_map = {
        int: DecimalInteger,
        str: String,
    }

    def __init__(self, aai):
        SinglePartCompilable.__init__(self)
        self.value = DuckTypedDict(['compile'])
        for k, v in aai.items():
            if isinstance(v, SinglePartCompilable):
                self.value[k] = v
            else:
                self.value[k] = self.type_map[type(v)](v)

    def __len__(self):
        return len(self.value)

    def compile(self, dialect):
        retval = js.primitive.Object()

        for k, v in self.value.items():
            retval.set_member(k, v.compile(dialect))

        return retval
Beispiel #4
0
class AssociativeArrayInitialization(SinglePartCompilable):
    type_map={
        int: DecimalInteger,
        str: String,
    }

    def __init__(self, aai):
        SinglePartCompilable.__init__(self)
        self.value = DuckTypedDict(['compile'])
        for k,v in aai.items():
            if isinstance(v, SinglePartCompilable):
                self.value[k] = v
            else:
                self.value[k] = self.type_map[type(v)](v)

    def __len__(self):
        return len(self.value)

    def compile(self, dialect):
        retval = js.primitive.Object()

        for k,v in self.value.items():
            retval.set_member(k, v.compile(dialect))

        return retval
Beispiel #5
0
 def __init__(self, aai):
     SinglePartCompilable.__init__(self)
     self.value = DuckTypedDict(['compile'])
     for k,v in aai.items():
         if isinstance(v, SinglePartCompilable):
             self.value[k] = v
         else:
             self.value[k] = self.type_map[type(v)](v)
Beispiel #6
0
    def __init__(self,name):
        SinglePartCompilable.__init__(self)

        self.__name = name
        self.members = DuckTypedDict(['compile'])
        self.statics = DuckTypedDict(['compile'])
        self.ctor = ConstructorDefinition(self.name)
        self.dtor = DestructorDefinition(self.name)
        self.preamble = DuckTypedList(['compile'])
        self.mixins = DuckTypedList(['compile'])
        self.mixins.append(ObjectReference("qx.locale.MTranslation"))
        self.base_class = None
        self.assets = set()
Beispiel #7
0
class Object(Base):
    def __init__(self):
        self.__members = DuckTypedDict(['to_stream'])

    def set_member(self,key,value):
        self.__members[key]=value

    def del_member(self,key):
        del self.__members[key]

    def to_stream(self, os):
        os.write("{")
        i=0
        keys = self.__members.keys()
        keys.sort()
        for k in keys:
            os.write(k)
            os.write(":")
            self.__members[k].to_stream(os)
            if i != len(self.__members) -1:
                os.write(",")
            i+=1

        os.write("}")
Beispiel #8
0
class Object(Base):
    def __init__(self):
        self.__members = DuckTypedDict(['to_stream'])

    def set_member(self, key, value):
        self.__members[key] = value

    def del_member(self, key):
        del self.__members[key]

    def to_stream(self, os):
        os.write("{")
        i = 0
        keys = self.__members.keys()
        keys.sort()
        for k in keys:
            os.write(k)
            os.write(":")
            self.__members[k].to_stream(os)
            if i != len(self.__members) - 1:
                os.write(",")
            i += 1

        os.write("}")
Beispiel #9
0
 def __init__(self):
     self.__members = DuckTypedDict(['to_stream'])
Beispiel #10
0
class ClassDefinition(SinglePartCompilable):
    def __init__(self, name):
        SinglePartCompilable.__init__(self)

        self.__name = name
        self.members = DuckTypedDict(['compile'])
        self.statics = DuckTypedDict(['compile'])
        self.ctor = ConstructorDefinition(self.name)
        self.dtor = DestructorDefinition(self.name)
        self.preamble = DuckTypedList(['compile'])
        self.mixins = DuckTypedList(['compile'])
        self.mixins.append(ObjectReference("qx.locale.MTranslation"))
        self.base_class = None
        self.assets = set()

    def set_name(self, name):
        self.__name = name
        self.ctor.name = name
        self.dtor.name = name

    def get_name(self):
        return self.__name

    name = property(get_name, set_name)

    def set_member(self, key, val):
        self.members[key] = val
        val.set_parent(self)

    def get_member(self, key, val, default=None):
        return self.__elts['members'].get(key, default)

    def compile(self, dialect):
        lang = js.primitive.FunctionCall("qx.Class.define")
        lang.add_argument(js.primitive.String(self.name))

        if self.base_class == None:
            base_class = js.primitive.ObjectReference('qx.core.Object')
        else:
            base_class = js.primitive.ObjectReference(self.base_class)

        class_members = js.primitive.Object()

        # MPC gets compiled first because they can make changes
        # anywhere, including members dict.
        for k, v in self.members.items():
            if isinstance(v, MultiPartCompilable):  # FIXME!
                v.compile(dialect, self)

        for k, v in self.members.items():
            if isinstance(v, SinglePartCompilable):  # FIXME!
                class_members.set_member(k, v.compile(dialect))

        st = FunctionCall('this.base')
        st.add_argument(ObjectReference('arguments'))
        self.ctor.insert_statement(0, st)

        properties = js.primitive.Object()
        widget_property = js.primitive.Object()
        widget_property.set_member("check",
                                   js.primitive.String('qx.ui.core.Widget'))
        properties.set_member("widget", widget_property)

        mixins = js.primitive.Array()
        for m in self.mixins:
            mixins.append(m.compile(dialect))

        class_dict = js.primitive.Object()
        class_dict.set_member("members", class_members)
        class_dict.set_member("extend", base_class)
        class_dict.set_member("construct", self.ctor.compile(dialect))
        class_dict.set_member("destruct", self.dtor.compile(dialect))
        class_dict.set_member("properties", properties)
        class_dict.set_member("include", mixins)

        lang.add_argument(class_dict)
        if len(self.assets) > 0:
            self.preamble.insert(
                0,
                Comment(
                    "".join(["\n#asset(%s)" % a
                             for a in sorted(self.assets)]) + "\n"))

        return lang
Beispiel #11
0
class ClassDefinition(SinglePartCompilable):
    def __init__(self,name):
        SinglePartCompilable.__init__(self)

        self.__name = name
        self.members = DuckTypedDict(['compile'])
        self.statics = DuckTypedDict(['compile'])
        self.ctor = ConstructorDefinition(self.name)
        self.dtor = DestructorDefinition(self.name)
        self.preamble = DuckTypedList(['compile'])
        self.mixins = DuckTypedList(['compile'])
        self.mixins.append(ObjectReference("qx.locale.MTranslation"))
        self.base_class = None
        self.assets = set()

    def set_name(self, name):
        self.__name = name
        self.ctor.name = name
        self.dtor.name = name

    def get_name(self):
        return self.__name

    name = property(get_name,set_name)

    def set_member(self, key, val):
        self.members[key]=val
        val.set_parent(self)

    def get_member(self, key, val, default=None):
        return self.__elts['members'].get(key, default)

    def compile(self, dialect):
        lang = js.primitive.FunctionCall("qx.Class.define")
        lang.add_argument(js.primitive.String(self.name))

        if self.base_class == None:
            base_class = js.primitive.ObjectReference('qx.core.Object')
        else:
            base_class = js.primitive.ObjectReference(self.base_class)

        class_members = js.primitive.Object()

        # MPC gets compiled first because they can make changes 
        # anywhere, including members dict.
        for k,v in self.members.items():
            if isinstance(v, MultiPartCompilable): # FIXME!
                v.compile(dialect, self)

        for k,v in self.members.items():
            if isinstance(v, SinglePartCompilable): # FIXME!
                class_members.set_member(k, v.compile(dialect))

        st = FunctionCall('this.base')
        st.add_argument(ObjectReference('arguments'))
        self.ctor.insert_statement(0,st)

        properties = js.primitive.Object()
        widget_property = js.primitive.Object()
        widget_property.set_member("check",
                               js.primitive.String('qx.ui.core.Widget'))
        properties.set_member("widget", widget_property)

        mixins = js.primitive.Array()
        for m in self.mixins:
            mixins.append(m.compile(dialect))

        class_dict = js.primitive.Object()
        class_dict.set_member("members", class_members)
        class_dict.set_member("extend", base_class)
        class_dict.set_member("construct", self.ctor.compile(dialect))
        class_dict.set_member("destruct", self.dtor.compile(dialect))
        class_dict.set_member("properties", properties)
        class_dict.set_member("include", mixins)

        lang.add_argument(class_dict)
        if len(self.assets) > 0:
            self.preamble.insert(0, Comment("".join(
                    ["\n#asset(%s)" % a for a in sorted(self.assets)]) + "\n"))

        return lang
Beispiel #12
0
 def __init__(self):
     self.__members = DuckTypedDict(['to_stream'])