def testCloneRefToCoreObject(self): """ Clone reference to internal core object """ srcModule = WppCore.createMemModule('', 'hello') srcCore = srcModule.core srcDouble = srcCore.findItem('double') self.assertEqual(srcDouble.name, 'double') srcRef = srcModule.addItem(TaxonRef()) srcRef.setTarget(srcDouble) # source reference to double dstCore = DstCore.createInstance() dstDouble = dstCore.findItem('double') self.assertIsNot(srcDouble, dstDouble) dstModule = dstCore.setRoot(Taxon('hello')) dstRef = dstModule.addItem(srcRef.clone(dstModule)) self.assertIsInstance(dstRef, TaxonRef) self.assertIs(dstRef.core, dstCore) self.assertIsNot(srcRef, dstRef) self.assertEqual(dstRef.path, srcDouble.getPathExt()) self.assertIsNone(dstRef.target) # init reference dstModule.initAllRefs() self.assertIsInstance(dstRef.target, TaxonScalar) self.assertEqual(dstRef.target.name, 'double') self.assertIsNot(dstRef.target, srcDouble) self.assertIs(dstRef.target, dstDouble)
def exec(self): taxon = self.taxon decl, errMsg = findBinOpExt(taxon) if errMsg: taxon.throwError(errMsg) if not decl: taxon.throwError('Invalid binop "%s"' % taxon.opcode) taxon.addItem(TaxonRef.fromTaxon(decl)) taxon.check()
def replaceExt(callTaxon, target, args): owner = callTaxon.owner ndx = owner.items.index(callTaxon) owner.items.remove(callTaxon) newTaxon = owner.addItem(WppNew(), ndx) newTaxon._location = callTaxon._location newTaxon.addItem(TaxonRef.fromTaxon(target)) for arg in args: newTaxon.addItem(arg) # Нужно найти конструктор, соответствующий списку аргументов con = target.findConstructor() if not con and len(args) == 0: # Конструктора нет и список аргументов пуст return if con.type == 'constructor': msg = checkAgrs('Constructor', con.getParamsList(), args) if msg: newTaxon.throwError(msg) return if con.type == 'overload': suitable = TaxonOverload.findSuitablePure(args, con.items) if not suitable: newTaxon.throwError('Overloaded constructor is not ready') if suitable == 'NoSuitable': # Здесь возможен специальный случвй - все поля имеют дефолтные значения и используется неявный конструктор без праметров # Но будем считать, что в случае переопределения конструктора нужно явно определить конструктор без параметров # if len(args) == 0 and target.isAllFieldsInit(): # return newTaxon.throwError( 'No suitable constructor found for %s(%s)' % (target.name, ', '.join( [a.buildQuasiType().getDebugStr() for a in args]))) newTaxon.overloadKey = con.getOverloadKey(suitable) return tlist = ', '.join([t.buildQuasiType().exportString() for t in args]) newTaxon.throwError( 'No suitable constructor found for class %s with arguments (%s)' % (target.getName(), tlist))
def getRef(self): ref = self.findByTypeEx(TaxonRef) if not ref: ref = self.addItem(TaxonRef()) return ref
def setType(self, txType): prevRef = self.getReference() if prevRef: self.items.remove(prevRef) return self.addItem(TaxonRef.fromTaxon(txType))
def getRef(self): """ Always returns reference """ ref = self.findByType(TaxonRef.type) if not ref: ref = self.addItem(TaxonRef()) return ref
def setDeclaration(self, decl): if len(self.items) < 3: self.addItem(TaxonRef.fromTaxon(decl)) else: self.items[2].setTarget(decl)