Beispiel #1
0
 def toDialect(self, writer):
     writer = writer.newChildWriter()
     srcType = self.source.check(writer.context)
     elemType = srcType.checkIterator(writer.context)
     itemName = self.v1 if self.v2 is None else self.v2
     writer.context.registerValue(Variable(itemName, elemType))
     if self.v2 is not None:
         writer.context.registerValue(
             Variable(self.v1, IntegerType.instance))
     super().toDialect(writer)
Beispiel #2
0
 def check(self, context: Context):
     resultType = self.resolveAndCheck(context)
     context = context.newChildContext()
     if self.resultName is not None:
         context.registerValue(Variable(self.resultName, resultType))
     self.andThen.check(context, VoidType.instance)
     return VoidType.instance
Beispiel #3
0
 def interpret(self, context):
     record = super(FetchManyStatement, self).interpret(context)
     context = context.newChildContext()
     context.registerValue(Variable(self.name, CursorType(self.typ)))
     context.setValue(self.name, record)
     self.stmts.interpret(context)
     return None
Beispiel #4
0
 def toEDialect(self, writer):
     writer.append("sorted ")
     if self.desc:
         writer.append("descending ")
     self.source.toDialect(writer)
     if self.key is not None:
         typ = self.source.check(writer.context)
         itemType = typ.itemType
         local = self.contextualizeWriter(writer, itemType)
         local.append(" with ")
         keyExp = self.key
         if isinstance(keyExp, UnresolvedIdentifier):
             try:
                 keyExp = keyExp.resolve(writer.context, False)
             except:
                 pass # TODO add warning
         if isinstance(keyExp, ArrowExpression):
             for arg in keyExp.args:
                 param = Variable(arg, itemType)
                 local.context.registerValue(param)
             keyExp.toDialect(local)
         elif isinstance(keyExp, InstanceExpression):
             keyExp.toDialect(local, False)
         else:
             keyExp.toDialect(local)
         writer.append(" as key")
 def interpret(self, context):
     record = super(ReadStatement, self).interpret(context)
     context = context.newChildContext()
     context.registerValue(Variable(self.name, TextType.instance))
     context.setValue(self.name, record)
     self.stmts.interpret(context)
     return None
Beispiel #6
0
 def getIterator(self, context):
     for value in self.source:
         child = context.newChildContext()
         child.registerValue(Variable(self.name, self.itemType))
         child.setValue(self.name, value)
         value = self.expression.interpret(child)
         yield value
Beispiel #7
0
 def interpret(self, context):
     if context.getRegisteredValue(INamedInstance,
                                   self.parameter.getName()) is None:
         context.registerValue(
             Variable(self.parameter.getName(), self.getExpression()))
     context.setValue(self.parameter.getName(),
                      self.getExpression().interpret(context))
     return None
Beispiel #8
0
 def readRegisteredValue(self, klass, name):
     actual = self.instances.get(name, None)
     # not very pure, but avoids a lot of complexity when registering a value
     if actual is None:
         attr = self.getRegisteredDeclaration(AttributeDeclaration, name)
         typ = attr.getType()
         actual = Variable(name, typ)
         self.instances[name] = actual
     return actual
Beispiel #9
0
 def interpret(self, context: Context):
     resultType = self.resolveAndCheck(context)
     resultValue = super().interpret(context)
     context = context.newChildContext()
     if self.resultName is not None:
         context.registerValue(Variable(self.resultName, resultType))
         context.setValue(self.resultName, resultValue)
     self.andThen.interpret(context)
     return None
Beispiel #10
0
 def checkAssignValue(self, context, valueType):
     actual = context.getRegisteredValue(INamedInstance, self.name)
     if actual is None:
         context.registerValue(Variable(self.name, valueType))
         return valueType
     else:
         # need to check type compatibility
         actualType = actual.getType(context)
         actualType.checkAssignableFrom(context, valueType)
         return actualType
Beispiel #11
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__)
Beispiel #12
0
 def toDialect(self, writer, expression):
     if expression is not None:
         try:
             actual = writer.context.getRegisteredValue(
                 INamedInstance, self.name)
             if actual is None:
                 typ = expression.check(writer.context)
                 writer.context.registerValue(Variable(self.name, typ))
         except:
             pass
     writer.append(self.name)
Beispiel #13
0
 def check(self, context):
     actual = context.getRegisteredValue(INamedInstance, self.parameter.getName())
     if actual is None:
         actualType = self.getExpression().check(context)
         context.registerValue(Variable(self.parameter.getName(), actualType))
     else:
         # need to check type compatibility
         actualType = actual.getType(context)
         newType = self.getExpression().check(context)
         actualType.checkAssignableFrom(context, newType)
     return VoidType.instance
 def doProcessCategory(self, annotation, context, declaration):
     fieldName = annotation.getArgument("name")
     fieldType = annotation.getArgument("type")
     if not isinstance(fieldName, TextLiteral):
         raise SyntaxError("WidgetField requires a Text value for argument 'name'")
     elif not isinstance(fieldType, (TypeExpression, TypeLiteral)):
         raise SyntaxError("WidgetField requires a Type value for argument 'type'")
     else:
         name = str(fieldName)
         typ = fieldType.typ
         context.registerValue(Variable(name[1:-1], typ), False)
Beispiel #15
0
 def checkResource(self, context):
     expressionType = self.expression.check(context)
     if not isinstance(expressionType, ResourceType):
         raise SyntaxError("Not a resource!")
     actual = context.getRegisteredValue(INamedInstance, self.name)
     if actual is None:
         context.registerValue(Variable(self.name, expressionType))
     else:
         # need to check type compatibility
         actualType = actual.getType(context)
         actualType.checkAssignableFrom(context, expressionType)
     return VoidType.instance
Beispiel #16
0
 def interpret(self, context):
     value = self.expression.interpret(context)
     if not isinstance(value, TupleValue):
         raise SyntaxError("Expecting a tuple expression, got " +
                           type(value).__name__)
     i = 1
     for name in self.names:
         item = value.getItem(context, IntegerValue(i))
         i += 1
         if context.getRegisteredValue(INamedInstance, name) is None:
             context.registerValue(Variable(name, item.itype))
         context.setValue(name, item)
     return None
Beispiel #17
0
 def toDialect(self, writer, typ):
     writer.append(" then with ").append(self.name)
     if writer.dialect is Dialect.O:
         writer.append(" {")
     else:
         writer.append(":")
     writer = writer.newChildWriter()
     writer.context.registerValue(Variable(self.name, typ))
     writer.newLine().indent()
     self.statements.toDialect(writer)
     writer.dedent()
     if writer.dialect is Dialect.O:
         writer.append("}")
 def toDialect(self, writer):
     super(ReadStatement, self).toDialect(writer)
     writer.append(" then with ").append(self.name)
     if writer.dialect is Dialect.O:
         writer.append(" {")
     else:
         writer.append(":")
     writer = writer.newChildWriter()
     writer.context.registerValue(Variable(self.name, TextType.instance))
     writer.newLine().indent()
     self.stmts.toDialect(writer)
     writer.dedent()
     if writer.dialect is Dialect.O:
         writer.append("}")
Beispiel #19
0
 def toDialect(self, writer):
     super(FetchManyStatement, self).toDialect(writer)
     writer.append(" then with ").append(self.name)
     if writer.dialect is Dialect.O:
         writer.append(" {")
     else:
         writer.append(":")
     writer = writer.newChildWriter()
     writer.context.registerValue(Variable(self.name, CursorType(self.typ)))
     writer.newLine().indent()
     self.stmts.toDialect(writer)
     writer.dedent()
     if writer.dialect is Dialect.O:
         writer.append("}")
Beispiel #20
0
 def doSetMember(self, context, attrName, value, allowSetter):
     decl = context.getRegisteredDeclaration(AttributeDeclaration, attrName)
     setter = self.declaration.findSetter(context, attrName) if allowSetter else None
     if setter is not None:
         activeSetters.__dict__[attrName] = context
         # use attribute name as parameter name for incoming value
         context = context.newInstanceContext(self, None).newChildContext()
         context.registerValue(Variable(attrName, decl.getType()))
         context.setValue(attrName, value)
         value = setter.interpret(context)
     value = self.autocast(decl, value)
     self.values[attrName] = value
     if self.storable is not None and decl.storable:
         # TODO convert object graph if(value instanceof IInstance)
         self.storable.setData(attrName, value.getStorableData())
Beispiel #21
0
 def check(self, context):
     itype = self.expression.check(context)
     if itype != TupleType.instance:
         raise SyntaxError("Expecting a tuple expression, got " +
                           itype.getName())
     for name in self.names:
         actual = context.getRegistered(name)
         if actual is None:
             actualType = self.expression.check(context)
             context.registerValue(Variable(name, actualType))
         else:
             # need to check type compatibility
             actualType = actual.getType(context)
             newType = self.expression.check(context)
             actualType.checkAssignableFrom(context, newType)
     return VoidType.instance
Beispiel #22
0
 def toDialect(self, writer):
     super().toDialect(writer)
     resultType = self.resolveAndCheck(writer.context)
     writer.append(" then")
     writer = writer.newChildWriter()
     if self.resultName is not None:
         writer.append(" with ").append(self.resultName)
         writer.context.registerValue(Variable(self.resultName, resultType))
     if writer.dialect is Dialect.O:
         writer.append(" {")
     else:
         writer.append(":")
     writer = writer.newLine().indent()
     self.andThen.toDialect(writer)
     writer = writer.dedent()
     if writer.dialect is Dialect.O:
         writer.append("}")
Beispiel #23
0
 def filteredToDialect(self, writer, source):
     writer = writer.newChildWriter()
     sourceType = source.check(writer.context)
     itemType = sourceType.itemType
     writer.context.registerValue(Variable(self.itemName, itemType))
     if writer.dialect is Dialect.O:
         writer.append("filtered (")
         source.toDialect(writer)
         writer.append(") with (") \
             .append(self.itemName) \
             .append(") where (")
         self.predicate.toDialect(writer)
         writer.append(")")
     else:
         source.toDialect(writer)
         writer.append(" filtered with ") \
             .append(self.itemName) \
             .append(" where ")
         self.predicate.toDialect(writer)
Beispiel #24
0
 def checkFilter(self, context, itemType):
     child = context.newChildContext()
     child.registerValue(Variable(self.itemName, itemType))
     return self.predicate.check(child)
Beispiel #25
0
 def registerArrowArgs(self, context, itemType):
     for arg in self.args:
         context.registerValue(Variable(arg, itemType))
     return context
Beispiel #26
0
 def checkFilter(self, context, itemType):
     if self.args is None or len(self.args) != 1:
         raise SyntaxError("Expecting 1 parameter only!")
     context = context.newChildContext()
     context.registerValue(Variable(self.args[0], itemType))
     return self.statements.check(context, None)
Beispiel #27
0
 def check(self, context):
     elemType = self.source.check(context).checkIterator(context)
     child = context.newChildContext()
     context.registerValue(Variable(self.name, elemType))
     itemType = self.expression.check(child)
     return IteratorType(itemType)
Beispiel #28
0
 def assign(self, context, expression):
     value = expression.interpret(context)
     if context.getRegisteredValue(INamedInstance, self.name) is None:
         itype = expression.check(context)
         context.registerValue(Variable(self.name, itype))
     context.setValue(self.name, value)
Beispiel #29
0
 def callback(text):
     local = context.newChildContext()
     local.registerValue(
         Variable(self.thenWith.name, TextType.instance))
     local.setValue(self.thenWith.name, TextValue(text))
     self.thenWith.statements.interpret(local)
Beispiel #30
0
 def check(self, context):
     super(FetchManyStatement, self).check(context)
     context = context.newChildContext()
     context.registerValue(Variable(self.name, CursorType(self.typ)))
     self.stmts.check(context, None)
     return VoidType.instance