def createPropertyGet(self, target, namespace, name, memberTypeFlags): if namespace is None and (memberTypeFlags == 0): if target is None: return self.createName(name) self.checkActivationName(name, Token.GETPROP) if ScriptRuntime.isSpecialProperty(name): ref = Node(Token.REF_SPECIAL, target) ref.putProp(Node.NAME_PROP, name) return Node(Token.GET_REF, ref) return Node(Token.GETPROP, target, self.createString(name)) elem = self.createString(name) memberTypeFlags |= Node.PROPERTY_FLAG return self.createMemberRefGet(target, namespace, elem, memberTypeFlags)
def createUnary(self, nodeType, child): childType = child.getType() if nodeType == Token.DELPROP: n = None#Node() if (childType == Token.NAME): child.setType(Token.BINDNAME) left = child right = Node.newString(child.getString()) n = Node(nodeType, left, right) else: if (childType == Token.GETPROP) or (childType == Token.GETELEM): left = child.getFirstChild() right = child.getLastChild() child.removeChild(left) child.removeChild(right) n = Node(nodeType, left, right) else: if (childType == Token.GET_REF): ref = child.getFirstChild() child.removeChild(ref) n = Node(Token.DEL_REF, ref) else: n = Node(Token.TRUE) return n elif nodeType == Token.TYPEOF: if (childType == Token.NAME): child.setType(Token.TYPEOFNAME) return child elif nodeType == Token.BITNOT: if (childType == Token.NUMBER): value = ScriptRuntime.toInt32(child.getDouble()) child.setDouble(~value) return child elif nodeType == Token.NEG: if (childType == Token.NUMBER): child.setDouble(-child.getDouble()) return child elif nodeType == Token.NOT: status = self.isAlwaysDefinedBoolean(child) if (status != 0): type = 0 if (status == self.ALWAYS_TRUE_BOOLEAN): type = Token.FALSE else: type = Token.TRUE if (childType == Token.TRUE) or (childType == Token.FALSE): child.setType(type) return child return Node(type) return Node(nodeType, child)
def createBinary(self, nodeType, left, right): if nodeType == Token.ADD: if (left.type == Token.STRING): s2 = "" if (right.type == Token.STRING): s2 = right.getString() else: if (right.type == Token.NUMBER): s2 = ScriptRuntime.numberToString(right.getDouble(), 10) else: pass s1 = left.getString() left.setString(s1+s2) return left else: if (left.type == Token.NUMBER): if (right.type == Token.NUMBER): left.setDouble(left.getDouble() + right.getDouble()) return left else: if (right.type == Token.STRING): s1 = "" s2 = "" s1 = ScriptRuntime.numberToString(left.getDouble(), 10) s2 = right.getString() right.setString(s1.concat(s2)) return right elif nodeType == Token.SUB: if (left.type == Token.NUMBER): ld = left.getDouble() if (right.type == Token.NUMBER): left.setDouble(ld - right.getDouble()) return left else: if (ld == 0.0): return Node(Token.NEG, right) else: if (right.type == Token.NUMBER): if (right.getDouble() == 0.0): return Node(Token.POS, left) elif nodeType == Token.MUL: if (left.type == Token.NUMBER): ld = left.getDouble() if (right.type == Token.NUMBER): left.setDouble(ld * right.getDouble()) return left else: if (ld == 1.0): return Node(Token.POS, right) else: if (right.type == Token.NUMBER): if (right.getDouble() == 1.0): return Node(Token.POS, left) elif nodeType == Token.DIV: if (right.type == Token.NUMBER): rd = right.getDouble() if (left.type == Token.NUMBER): left.setDouble(left.getDouble() / rd) return left else: if (rd == 1.0): return Node(Token.POS, left) elif nodeType == Token.AND: leftStatus = self.isAlwaysDefinedBoolean(left) if (leftStatus == self.ALWAYS_FALSE_BOOLEAN): return left else: if (leftStatus == self.ALWAYS_TRUE_BOOLEAN): return right elif nodeType == Token.OR: leftStatus = self.isAlwaysDefinedBoolean(left) if (leftStatus == self.ALWAYS_TRUE_BOOLEAN): return left else: if (leftStatus == self.ALWAYS_FALSE_BOOLEAN): return right return Node(nodeType, left, right)