Пример #1
0
 def buildArguments(method, cmdLineArgs):
     arguments = ArgumentList()
     if len(method.parameters) == 1:
         name = method.parameters[0].getName()
         value = Interpreter.parseCmdLineArgs(cmdLineArgs)
         arguments.append(Argument(UnresolvedParameter(name), value))
     return arguments
Пример #2
0
 def toODialect(self, writer):
     self.itype.toDialect(writer)
     arguments = ArgumentList()
     if self.copyFrom is not None:
         from prompto.param.AttributeParameter import AttributeParameter
         arguments.append(
             Argument(AttributeParameter("from"), self.copyFrom))
     if self.arguments is not None:
         arguments.extend(self.arguments)
     arguments.toDialect(writer)
 def isAssignableTo(self, context, arguments, checkInstance):
     from prompto.grammar.ArgumentList import ArgumentList
     try:
         local = context.newLocalContext()
         self.registerArguments(local)
         argumentsList = ArgumentList(items=arguments)
         for argument in self.parameters:
             found = argumentsList.find(argument.getName())
             toRemove = found
             if found is None:  # missing argument
                 if argument.defaultExpression is None:
                     return False
                 found = Argument(argument, argument.defaultExpression)
             if not self.isArgAssignableTo(local, argument, found, checkInstance):
                 return False
             if toRemove is not None:
                 argumentsList.remove(toRemove)
         return len(argumentsList)==0
     except SyntaxError:
         return False
Пример #4
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
Пример #5
0
    def getGlobalMethodSortKeyReader(self, context, name):
        from prompto.statement.MethodCall import MethodCall
        exp = ValueExpression(self, self.newInstance(context))
        arg = Argument(None, exp)
        args = ArgumentList(items=[arg])
        call = MethodCall(MethodSelector(name), args)

        def keyGetter(o):
            argument = call.arguments[0]
            argument.setExpression(ValueExpression(self, o))
            return call.interpret(context)

        return keyGetter
Пример #6
0
 def populateError(self, e, context):
     error = e.getExpression(context)
     if error == None:
         exp = ConstructorExpression(CategoryType("Error"), None, None)
         args = ArgumentList()
         args.append(Argument(UnresolvedParameter("name"), TextLiteral(type(e).__name__)))
         args.append(Argument(UnresolvedParameter("text"), TextLiteral(e.getMessage())))
         exp.setArguments(args)
         error = exp
     if context.getRegisteredValue(INamedInstance, self.errorName) == None:
         context.registerValue(ErrorVariable(self.errorName))
     if isinstance(error, IExpression):
         error = error.interpret(context)
     context.setValue(self.errorName, error)
     return error
Пример #7
0
 def interpret(self, context, errorName):
     exp = self.getExpression(context)
     if exp is None:
         from prompto.grammar.Argument import Argument
         from prompto.grammar.ArgumentList import ArgumentList
         from prompto.expression.ConstructorExpression import ConstructorExpression
         from prompto.param.UnresolvedParameter import UnresolvedParameter
         from prompto.literal.TextLiteral import TextLiteral
         from prompto.type.CategoryType import CategoryType
         args = ArgumentList()
         args.append(
             Argument(UnresolvedParameter("name"),
                      TextLiteral(type(self).__name__)))
         args.append(
             Argument(UnresolvedParameter("text"),
                      TextLiteral(self.message)))
         exp = ConstructorExpression(CategoryType("Error"), args, None)
     if context.getRegisteredValue(object, errorName) is None:
         from prompto.runtime.ErrorVariable import ErrorVariable
         context.registerValue(ErrorVariable(errorName))
     error = exp.interpret(context)
     context.setValue(errorName, error)
     return error
Пример #8
0
 def makeArguments(self, context, declaration):
     if self.arguments is None:
         return ArgumentList()
     else:
         return self.arguments.makeArguments(context, declaration)