def check(self, context):
     named = context.getRegistered(self.name)
     if isinstance(named, MethodDeclarationMap):
         method = named.getFirst()
         return MethodType(method)
     else:
         raise SyntaxError("No method with name:" + self.name)
Exemplo n.º 2
0
 def checkReference(self, context):
     finder = MethodFinder(context, self)
     method = finder.findBest(False)
     if method is not None:
         return MethodType(method)
     else:
         return None
Exemplo n.º 3
0
 def readValue(self, name):
     decl = self.getDeclaration()
     if decl.hasAttribute(self, name):
         return self.instance.getMemberValue(self.calling, name)
     elif decl.hasMethod(self, name):
         method = decl.getMemberMethodsMap(self, name).getFirst()
         return ClosureValue(self, MethodType(method))
     else:
         return None
 def interpret(self, context):
     if context.hasValue(self.name):
         return context.getValue(self.name)
     else:
         named = context.getRegistered(self.name)
         if isinstance(named, MethodDeclarationMap):
             decl = named.getFirst()
             return ClosureValue(context, MethodType(decl))
         else:
             raise SyntaxError("No method with name:" + self.name)
Exemplo n.º 5
0
 def interpret(self, context):
     if isinstance(self.declaration, ConcreteMethodDeclaration):
         method = self.declaration
         method.register(context)
         typ = MethodType(method)
         context.registerValue( Variable(method.getName(), typ))
         context.setValue(method.getName(), ClosureValue(context, typ))
         return None
     else:
         raise SyntaxError("Unsupported:" + type(self.declaration).__name__)
Exemplo n.º 6
0
def getTargetAtomicType(context, itype):
    decl = context.getRegisteredDeclaration(IDeclaration, itype.typeName)
    if decl is None:
        raise SyntaxError("Unknown identifier: " + itype.typeName)
    elif isinstance(decl, MethodDeclarationMap):
        if len(decl) == 1:
            return MethodType(decl.getFirst())
        else:
            raise SyntaxError("Ambiguous identifier: " + itype.typeName)
    else:
        return decl.getType(context)
Exemplo n.º 7
0
 def interpretReference(self, context):
     # resolve parent to keep clarity
     parent = self.resolveParent(context)
     instance = parent.interpret(context)
     if instance is None or instance is NullValue.instance:
         raise NullReferenceError()
     elif isinstance(instance, IInstance):
         category = instance.getDeclaration()
         methods = category.getMemberMethodsMap(context, self.name)
         method = methods.getFirst() # TODO check prototype
         return ClosureValue(context.newInstanceContext(instance, None, True), MethodType(method))
     else:
         raise SyntaxError("Should never get here!")
Exemplo n.º 8
0
 def interpret(self, context):
     if context.hasValue(self.name):
         v = context.getValue(self.name)
         # TODO not sure why interpret is needed in Python only
         if isinstance(v, IExpression):
             v = v.interpret(context)
         return v
     else:
         named = context.getRegistered(self.name)
         if isinstance(named, MethodDeclarationMap):
             decl = named.getFirst()
             return ClosureValue(context, MethodType(decl))
         else:
             raise SyntaxError("No value or method with name:" + self.name)
Exemplo n.º 9
0
 def checkCategoryMember(self, context, decl, name):
     if decl.storable and "dbId" == name:
         return AnyType.instance
     elif decl.hasAttribute(context, name):
         ad = context.getRegisteredDeclaration(AttributeDeclaration, name)
         if ad is None:
             raise SyntaxError("Missing attribute:" + name)
         else:
             return ad.getType(context)
     elif "text" == name:
         return TextType.instance
     elif decl.hasMethod(context, name):
         method = decl.getMemberMethodsMap(context, name).getFirst()
         return MethodType(method)
     else:
         raise SyntaxError("No attribute:" + name + " in category:" +
                           self.typeName)
Exemplo n.º 10
0
 def check(self, context):
     expression = self.expression
     if isinstance(expression, UnresolvedSelector):
         parent = expression.parent
         if parent is not None:
             typ = parent.check(context)
             if isinstance(typ, CategoryType):
                 expression = UnresolvedIdentifier(expression.name, Dialect.O)
                 context = context.newInstanceContext(None, typ, True)
             else:
                 raise SyntaxError("Not a method: " + str(self.expression))
     if isinstance(expression, UnresolvedIdentifier):
         name = expression.name
         named = context.getRegistered(name)
         if isinstance(named, MethodDeclarationMap):
             method = named.getFirst()
             return MethodType(method)
         else:
             raise SyntaxError("No method with name:" + name)
     else:
         return SyntaxError("Not implemented !")
Exemplo n.º 11
0
 def check(self, context):
     from prompto.declaration.CategoryDeclaration import CategoryDeclaration
     named = context.getRegistered(self.name)
     if named is None:
         named = context.getRegisteredDeclaration(IDeclaration, self.name)
     if named is None:
         raise SyntaxError("Unknown identifier:" + self.name)
     elif isinstance(named, Variable):  # local variable
         return named.getType(context)
     elif isinstance(named, LinkedVariable):  # linked variable
         return named.getType(context)
     elif isinstance(named, IParameter):  # named argument
         return named.getType(context)
     elif isinstance(named, CategoryDeclaration):  # any p with x
         return named.getType(context)
     elif isinstance(named, AttributeDeclaration):  # in category method
         return named.getType(context)
     elif isinstance(named, MethodDeclarationMap):  # global method or closure
         method = named.getFirst()
         return MethodType(method)
     else:
         raise SyntaxError(self.name + "  is not a value or method:" + type(named).__name__)
Exemplo n.º 12
0
 def resolve(self, context, onError=None):
     if self.resolved is None:
         typ = self.anyfy()
         if isinstance(typ, NativeType):
             self.resolved = typ
         else:
             if (isinstance(context, CategoryType)):
                 raise SyntaxError("what!!")
             decl = context.getRegisteredDeclaration(
                 IDeclaration, typ.typeName)
             if decl is None:
                 if onError is not None:
                     onError(typ)
                     return None
                 else:
                     raise SyntaxError("Unknown type:" + typ.typeName)
             elif isinstance(decl, MethodDeclarationMap):
                 self.resolved = MethodType(decl.getFirst())
             else:
                 found = decl.getType(context)
                 self.resolved = typ if type(found) == type(typ) else found
     return self.resolved
Exemplo n.º 13
0
 def interpret(self, context):
     expression = self.expression
     if isinstance(expression, UnresolvedSelector):
         parent = expression.parent
         if parent is not None:
             value = parent.interpret(context)
             if isinstance(value, IInstance):
                 expression = UnresolvedIdentifier(expression.name, Dialect.O)
                 context = context.newInstanceContext(value, None, True)
             else:
                 return NullValue.instance
     if isinstance(expression, UnresolvedIdentifier):
         name = expression.name
         if context.hasValue(name):
             return context.getValue(name)
         else:
             named = context.getRegistered(name)
             if isinstance(named, MethodDeclarationMap):
                 decl = named.getFirst()
                 return ClosureValue(context, MethodType(decl))
             else:
                 raise SyntaxError("No method with name:" + name)
Exemplo n.º 14
0
 def interpretReference(self, context):
     declaration = self.findDeclaration(context)
     return ClosureValue(context, MethodType(declaration))
Exemplo n.º 15
0
 def getType(self, context):
     method = self.getDeclaration(context)
     return MethodType(method)