Ejemplo n.º 1
0
 def checkReference(self, context):
     finder = MethodFinder(context, self)
     method = finder.findBest(False)
     if method is not None:
         return MethodType(method)
     else:
         return None
Ejemplo n.º 2
0
 def findDeclaration(self, context):
     method = self.findRegistered(context)
     if method is not None:
         return method
     else:
         finder = MethodFinder(context, self)
         return finder.findBest(True)
Ejemplo n.º 3
0
 def interpret(self, context):
     finder = MethodFinder(context, self)
     declaration = finder.findBest(True)
     if declaration is None:
         raise SyntaxError("No such method: " + str(self))
     local = self.selector.newLocalContext(context, declaration)
     declaration.registerParameters(local)
     self.assignArguments(context, local, declaration)
     return declaration.interpret(local)
Ejemplo n.º 4
0
 def checkAbstractOnly(self, context, declaration):
     if declaration.isReference:  # parameter or variable populated from a method call
         return
     if declaration.memberOf is not None:  # the category could be subclassed (if constructor called on abstract, that would raise an error anyway)
         return
     # if a global method, need to check for runtime dispatch
     finder = MethodFinder(context, self)
     potential = finder.findPotential()
     if potential.all(lambda decl: decl.isAbstract()):
         raise SyntaxError("Cannot call abstract method")
Ejemplo n.º 5
0
 def globalMethodExists(self, context, name):
     from prompto.statement.MethodCall import MethodCall
     from prompto.runtime.MethodFinder import MethodFinder
     try:
         exp = ValueExpression(self, self.newInstance(context))
         arg = Argument(None, exp)
         args = ArgumentList(items=[arg])
         proto = MethodCall(MethodSelector(name), args)
         finder = MethodFinder(context, proto)
         return finder.findBest(True) is not None
     except PromptoError:
         return False
Ejemplo n.º 6
0
 def check(self, context):
     finder = MethodFinder(context, self)
     declaration = finder.findBest(False)
     if declaration is None:
         return VoidType.instance
     if declaration.isAbstract():
         self.checkAbstractOnly(context, declaration)
         return VoidType.instance if declaration.returnType is None else declaration.returnType
     else:
         local = context if self.isLocalClosure(
             context) else self.selector.newLocalCheckContext(
                 context, declaration)
         return self.checkDeclaration(declaration, context, local)
Ejemplo n.º 7
0
 def requiresInvoke(self, writer):
     if writer.dialect is not Dialect.E or (self.arguments is not None
                                            and len(self.arguments) > 0):
         return False
     try:
         finder = MethodFinder(writer.context, self)
         declaration = finder.findBest(False)
         # if method is a reference, need to prefix with invoke
         return declaration.isAbstract(
         ) or declaration.closureOf is not None
     except:
         pass
         # ok
     return False