Пример #1
0
 def __init__(self, obj, prop):
   if isstring(obj): obj = Object(obj)
   assert isinstance(obj, Object), "got " + obj.__class__.__name__
   if isstring(prop): prop = Identifier(prop)
   assert isinstance(prop, Identifier)
   super(StructProperty, self).__init__({"obj" : obj, "prop": prop})
   self.obj  = obj
   self.prop = prop
Пример #2
0
 def __init__(self, obj, prop, type=None):
   if isstring(obj): obj = Object(obj)
   assert isinstance(obj, Object), "got " + obj.__class__.__name__
   if isstring(prop): prop = Identifier(prop)
   assert isinstance(prop, Identifier)
   if type is None: type = VoidType()
   assert isinstance(type, Type)
   super(ObjectProperty, self).__init__({"obj" : obj, "prop": prop})
   self.obj  = obj
   self.prop = prop
   self.type = type
Пример #3
0
 def __init__(self, name, type):
   if isstring(name): name = Identifier(name)
   assert isinstance(name, Identifier)
   assert isinstance(type, Type), "expected Type but got " + type.__class__.__name__
   super(Property, self).__init__({"name": name, "type": type})
   self.name = name
   self.type = type
Пример #4
0
 def __init__(self, operand, expression):
   if isstring(operand): operand = SimpleVariable(operand)
   assert isinstance(operand, Variable)
   assert isinstance(expression, Expression)
   Statement.__init__(self, {"operand": operand, "expression": expression})
   self.operand    = operand
   self.expression = expression
Пример #5
0
 def __init__(self, id, type):
   if isstring(id): id = Identifier(id)
   assert isinstance(id,   Identifier)
   assert isinstance(type, Type), "got " + type.__class__.__name__
   super(VariableDecl, self).__init__({"id":id, "type":type})
   self.id   = id
   self.type = type
Пример #6
0
  def __init__(self, id, value, type=None):
    # name
    if isstring(id): id = Identifier(id)
    assert isinstance(id, Identifier), "Name should be an identifier, not" + \
                                       id.__class__.__name__

    # TODO: add some value-checking ? (to avoid havoc)
    if isstring(value): value = Identifier(value)

    if type is None: type = VoidType()
    assert isinstance(type, Type), "Type should be a Type, not " + \
                                   type.__class__.__name__

    super(Constant, self).__init__({"id": id, "value": value, "type": type})
    self.id    = id
    self.value = value
    self.type  = type
Пример #7
0
 def __init__(self, function, arguments=[], type=None):
   if isstring(function): function = Identifier(function)
   assert isinstance(function, Identifier)
   if type is None: type = VoidType()
   assert isinstance(type, Type), "but got " + type.__class__.__name__
   super(FunctionCall, self).__init__({"function": function}, arguments)
   self.function  = function
   self.type      = type
Пример #8
0
 def __init__(self, comp, expression=None):
   if isstring(comp): comp = Comparator(comp)
   assert isinstance(comp, Comparator), \
          "Expected Comparator but got " + comp.__class__.__module__ + ":" + comp.__class__.__name__
   assert expression == None or isinstance(expression, Expression)
   super(Match, self).__init__({"comp": comp, "exp": expression})
   self.comp       = comp
   self.expression = expression
Пример #9
0
 def __init__(self, id, type=None):
   if isstring(id): id = Identifier(id)
   assert isinstance(id, Identifier)
   if type is None: type = VoidType()
   assert isinstance(type, Type)
   super(Object, self).__init__({"id": id, "type": type})
   self.id   = id
   self.type = type
Пример #10
0
 def __init__(self, obj, method, arguments=[], type=None):
   assert isinstance(obj, Object) or isinstance(obj, ObjectProperty), \
          "Expected Object(Property), but got " + obj.__class__.__name__
   if isstring(method): method = Identifier(method)
   if type is None: type = VoidType()
   assert isinstance(type, Type), "but got " + type.__class__.__name__
   assert isinstance(method, Identifier)
   super(MethodCall, self).__init__({"obj": obj, "method": method}, arguments)
   self.obj       = obj
   self.method    = method
   self.type      = type
Пример #11
0
  def __init__(self, string, *args):
    # string
    if isstring(string): string = StringLiteral(string)
    assert isinstance(string, StringLiteral)
    
    # TODO: assert args to be expressions

    super(Print, self).__init__({"string": string, "args": args})
    
    self.string = string
    self.args   = args
Пример #12
0
  def __init__(self, id, type=None, default=None):
    # name
    if isstring(id): id = Identifier(id)
    assert isinstance(id, Identifier)
    # type
    if type is None: type = VoidType()
    assert isinstance(type, Type)

    assert default == None or isinstance(default, Expression)
    super(Parameter, self).__init__({"id": id, "type": type, "default": default})
    self.id      = id
    self.type    = type
    self.default = default
Пример #13
0
  def __init__(self, name, type=None, params=[]):
    # name
    assert not name is None, "A function needs at least a name." # TODO: extend
    if isstring(name): name = Identifier(name)
    assert isinstance(name, Identifier), "Name should be an identifier, not" + \
                                         name.__class__.__name__

    # type
    if type is None: type = VoidType()
    assert isinstance(type, Type), "Return-type should be a Type, not " + \
                                   type.__class__.__name__

    # params
    if isinstance(params, list): params = TypedList(Parameter, params)

    super(Function, self).__init__({"id":name, "type":type, "params": params})
    self.id     = name
    self.type   = type
    self.params = params
Пример #14
0
 def visit_MatchExp(self, exp):
     return (exp.operator.accept(self) if isstring(exp.operator) else exp.operator.accept(self)) + \
            ((" " + exp.operand.accept(self)) if exp.operand != None else "")
Пример #15
0
 def visit_MatchExp(self, exp):
   return (exp.operator.accept(self) if isstring(exp.operator) else exp.operator.accept(self)) + \
          ((" " + exp.operand.accept(self)) if exp.operand != None else "")
Пример #16
0
  def process(self, obj):
    # IDENTIFIERS
    if isinstance(obj, Identifier):
      return self.dot.node(obj.name, {"color":"seagreen"})

    # CLASSES
    if inspect.isclass(obj):
      options = {"color":"springgreen"} if "semantic.model" in obj.__module__ else {}
      node = self.dot.node(obj.__name__, options)
      return node

    # A SIMPLE TYPE
    if isstring(obj) or isinstance(obj, int) or isinstance(obj, float) or \
       isinstance(obj, bool):
      return self.dot.node(str(obj))

    # UNKNOWN TYPE
    if isinstance(obj, UnknownType):
      return self.dot.node(obj.__class__.__name__, {"color":"coral"})

    # ANY TYPE
    if isinstance(obj, AnyType):
      return self.dot.node(obj.__class__.__name__, {"color":"limegreen"})

    # ANYTHING EXP
    if isinstance(obj, AnythingExp):
      return self.dot.node(obj.__class__.__name__, {"color":"green"})

    # TYPES
    if isinstance(obj, TypeExp) and not isinstance(obj, ComplexType):
      return self.dot.node(obj.__class__.__name__, {"color":"limegreen"})

    # RECURSION & LOOP DETECTION
    if str(obj.__repr__) in self.processed:
      return self.dot.node("dict" if isinstance(obj, dict) else str(obj),
                           {"color":"lightblue"})

    self.processed.append(str(obj.__repr__))

    # ITERATABLES

    # SIMPLE DICT
    if isinstance(obj, dict):
      node = self.dot.node(obj.__class__.__name__)
      for key, value in obj.items():
        if not value is None:
          self.dot.vertex(node, self.process(value), {"label":key})
    # SIMPLE LIST
    elif isinstance(obj, list):
      node = self.dot.node(obj.__class__.__name__)
      for value in obj:
        if not value is None:
          self.dot.vertex(node, self.process(value))
    # OBJECT
    else:
      options = {"color":"limegreen"} if isinstance(obj, ComplexType) else \
      {"color":"green"} if "foo_lang.semantic" in obj.__module__ else {}
      node = self.dot.node(obj.__class__.__name__, options)

      # if the obj supports the .type property, add it as such
      if hasattr(obj, "type") and not isinstance(obj, TimestampType):
        subnode = self.process(obj.type)
        self.dot.vertex(node, subnode, {"label": "type"})

      # manual exception to allow modules to be processed in such a way that 
      # domains are processed sooner than functions, to make sure that types
      # defined in domains are added in detail and all other instances are shown
      # as references
      if isinstance(obj, Module):
        items = [ ["identifier", obj.identifier],
                  ["constants",  obj.constants],
                  ["externals",  obj.externals],
                  ["domains",    obj.domains],
                  ["functions",  obj.functions],
                  ["executions", obj.executions]
                ]
      elif isinstance(obj, Domain):
        items = [
                  ["extensions", obj.extensions],
                  ["node_t",     obj.node_t],
                  ["payload_t",  obj.payload_t]
                ]
      else:
        items = obj.__dict__.items()
      for key, value in items:
        if key not in ["_type", "type"] and not value is None:
          # SCOPE
          if isinstance(value, Scope):
            subnode = self.dot.node(value.__class__.__name__, {"color":"lightblue"})
          else:
            subnode = self.process(value)
          self.dot.vertex(node, subnode, {"label":key})

    return node
Пример #17
0
 def __init__(self, name, properties=[]):
   if isstring(name): name = Identifier(name)
   assert isinstance(name, Identifier)
   super(UnionType, self).__init__({"name":name})
   self.name       = name
Пример #18
0
 def __init__(self, name):
   assert isstring(name)
   super(NamedType, self).__init__({"name": name})
   self.name = name
Пример #19
0
 def __init__(self, id):
   if isstring(id): id = Identifier(id)
   assert isinstance(id, Identifier)
   super(AtomLiteral, self).__init__({"name": id.name})
   self.id = id
Пример #20
0
 def __init__(self, comment):
   assert isstring(comment)
   super(Comment, self).__init__({"comment": comment})
   self.comment = comment
Пример #21
0
 def __init__(self, id, info=None):
   if isstring(id): id = Identifier(id)
   assert isinstance(id, Identifier)
   super(SimpleVariable, self).__init__({"id": id, "info": info})
   self.id   = id
   self.info = info
Пример #22
0
 def __init__(self, id, index):
   if isstring(id): id = Identifier(id)
   assert isinstance(id, Identifier) or isinstance(id, Variable)
   super(ListVariable, self).__init__({"id": id, "index": index})
   self.id   = id
   self.index = index
Пример #23
0
    def process(self, obj):
        # IDENTIFIERS
        if isinstance(obj, Identifier):
            return self.dot.node(obj.name, {"color": "seagreen"})

        # CLASSES
        if inspect.isclass(obj):
            options = {
                "color": "springgreen"
            } if "semantic.model" in obj.__module__ else {}
            node = self.dot.node(obj.__name__, options)
            return node

        # A SIMPLE TYPE
        if isstring(obj) or isinstance(obj, int) or isinstance(obj, float) or \
           isinstance(obj, bool):
            return self.dot.node(str(obj))

        # UNKNOWN TYPE
        if isinstance(obj, UnknownType):
            return self.dot.node(obj.__class__.__name__, {"color": "coral"})

        # ANY TYPE
        if isinstance(obj, AnyType):
            return self.dot.node(obj.__class__.__name__,
                                 {"color": "limegreen"})

        # ANYTHING EXP
        if isinstance(obj, AnythingExp):
            return self.dot.node(obj.__class__.__name__, {"color": "green"})

        # TYPES
        if isinstance(obj, TypeExp) and not isinstance(obj, ComplexType):
            return self.dot.node(obj.__class__.__name__,
                                 {"color": "limegreen"})

        # RECURSION & LOOP DETECTION
        if str(obj.__repr__) in self.processed:
            return self.dot.node("dict" if isinstance(obj, dict) else str(obj),
                                 {"color": "lightblue"})

        self.processed.append(str(obj.__repr__))

        # ITERATABLES

        # SIMPLE DICT
        if isinstance(obj, dict):
            node = self.dot.node(obj.__class__.__name__)
            for key, value in obj.items():
                if not value is None:
                    self.dot.vertex(node, self.process(value), {"label": key})
        # SIMPLE LIST
        elif isinstance(obj, list):
            node = self.dot.node(obj.__class__.__name__)
            for value in obj:
                if not value is None:
                    self.dot.vertex(node, self.process(value))
        # OBJECT
        else:
            options = {"color":"limegreen"} if isinstance(obj, ComplexType) else \
            {"color":"green"} if "foo_lang.semantic" in obj.__module__ else {}
            node = self.dot.node(obj.__class__.__name__, options)

            # if the obj supports the .type property, add it as such
            if hasattr(obj, "type") and not isinstance(obj, TimestampType):
                subnode = self.process(obj.type)
                self.dot.vertex(node, subnode, {"label": "type"})

            # manual exception to allow modules to be processed in such a way that
            # domains are processed sooner than functions, to make sure that types
            # defined in domains are added in detail and all other instances are shown
            # as references
            if isinstance(obj, Module):
                items = [["identifier", obj.identifier],
                         ["constants", obj.constants],
                         ["externals",
                          obj.externals], ["domains", obj.domains],
                         ["functions", obj.functions],
                         ["executions", obj.executions]]
            elif isinstance(obj, Domain):
                items = [["extensions", obj.extensions],
                         ["node_t", obj.node_t], ["payload_t", obj.payload_t]]
            else:
                items = obj.__dict__.items()
            for key, value in items:
                if key not in ["_type", "type"] and not value is None:
                    # SCOPE
                    if isinstance(value, Scope):
                        subnode = self.dot.node(value.__class__.__name__,
                                                {"color": "lightblue"})
                    else:
                        subnode = self.process(value)
                    self.dot.vertex(node, subnode, {"label": key})

        return node