Esempio n. 1
0
 def getStaticMemberValue(self, context:Context, name:str):
     from prompto.declaration.EnumeratedNativeDeclaration import EnumeratedNativeDeclaration
     decl = context.getRegisteredDeclaration(IDeclaration, self.typeName)
     if not isinstance (decl, EnumeratedNativeDeclaration):
         raise SyntaxError(self.typeName + " is not an enumerated type!")
     if "symbols" == name:
         return decl.getSymbols()
     else:
         raise SyntaxError("Unknown member:" + name)
Esempio n. 2
0
 def getCategoryCandidates(self, context: Context):
     from prompto.declaration.ConcreteCategoryDeclaration import ConcreteCategoryDeclaration
     from prompto.type.CategoryType import CategoryType
     itype = self.checkParent(context)
     if not isinstance(itype, CategoryType):
         raise SyntaxError(self.parent.toString() + " is not a category")
     cd = context.getRegisteredDeclaration(ConcreteCategoryDeclaration,
                                           itype.typeName)
     if cd is None:
         raise SyntaxError("Unknown category:" + itype.typeName)
     return cd.getMemberMethods(context, self.name)
Esempio n. 3
0
 def newInstanceCheckContext(self, context: Context):
     from prompto.type.CategoryType import CategoryType
     from prompto.type.TypeType import TypeType
     from prompto.declaration.IDeclaration import IDeclaration
     from prompto.declaration.SingletonCategoryDeclaration import SingletonCategoryDeclaration
     typ = self.parent.check(context)
     # if calling singleton method, parent is the singleton type
     if isinstance(typ, TypeType):
         decl = context.getRegisteredDeclaration(IDeclaration,
                                                 typ.typ.typeName)
         if isinstance(decl, SingletonCategoryDeclaration):
             typ = decl.getType(context)
     if isinstance(typ, CategoryType):
         context = context.newInstanceContext(None, typ)
         return context.newChildContext()
     else:
         return context.newChildContext()
Esempio n. 4
0
 def check(self, context: Context):
     from prompto.declaration.CategoryDeclaration import CategoryDeclaration
     from prompto.type.CategoryType import CategoryType
     cd = context.getRegisteredDeclaration(CategoryDeclaration,
                                           self.itype.typeName)
     if cd is None:
         raise SyntaxError("Unknown category " + self.itype.typeName)
     self.checkFirstHomonym(context, cd)
     cd.checkConstructorContext(context)
     if self.copyFrom is not None:
         cft = self.copyFrom.check(context)
         if not isinstance(cft, (CategoryType, DocumentType)):
             raise SyntaxError("Cannot copy from " + cft.getName())
     if self.arguments is not None:
         for argument in self.arguments:
             if not cd.hasAttribute(context, argument.getName()):
                 raise SyntaxError("\"" + argument.getName() +
                                   "\" is not an attribute of " +
                                   self.itype.typeName)
             argument.check(context)
     return cd.getType(context).asMutable(context, self.itype.mutable)
Esempio n. 5
0
 def interpret(self, context: Context):
     from prompto.declaration.CategoryDeclaration import CategoryDeclaration
     cd = context.getRegisteredDeclaration(CategoryDeclaration,
                                           self.itype.typeName)
     if cd is None:
         raise SyntaxError("Unknown category " + self.itype.typeName)
     self.checkFirstHomonym(context, cd)
     instance = self.itype.newInstance(context)
     instance.mutable = True
     if self.copyFrom is not None:
         copyObj = self.copyFrom.interpret(context)
         if isinstance(copyObj, IInstance):
             for name in copyObj.getMemberNames():
                 if name == "dbId":
                     continue
                 elif cd.hasAttribute(context, name):
                     value = copyObj.getMemberValue(context, name)
                     if value is not None and value.mutable and not self.itype.mutable:
                         raise NotMutableError()
                     instance.setMember(context, name, value)
         elif isinstance(copyObj, DocumentValue):
             for name in copyObj.getMemberNames():
                 if name == "dbId":
                     continue
                 elif cd.hasAttribute(context, name):
                     value = copyObj.getMemberValue(context, name)
                     if value is not None and value.mutable and not self.itype.mutable:
                         raise NotMutableError()
                     # TODO convert to attribute type
                     instance.setMember(context, name, value)
     if self.arguments is not None:
         for argument in self.arguments:
             value = argument.getExpression().interpret(context)
             if value is not None and value.mutable and not self.itype.mutable:
                 raise NotMutableError()
             instance.setMember(context, argument.getName(), value)
     instance.mutable = self.itype.mutable
     return instance