@Override protected String parseFromInternal(String expression) { // first the boolean operator for this clause if (expression.startsWith("|| ")) { m_isAnOr = true; } if (expression.startsWith("|| ") || expression.startsWith("&& ")) { // strip the boolean operator expression = expression.substring(3, expression.length()); } if (expression.charAt(0) == '!') { setNegated(true); expression = expression.substring(1, expression.length()); } if (expression.charAt(0) != '[') { throw new IllegalArgumentException("Was expecting a \"[\" to start this ExpressionClause!"); } expression = expression.substring(1, expression.length()); m_lhsAttributeName = expression.substring(0, expression.indexOf("@EC@")); expression = expression.substring(expression.indexOf("@EC@") + 4, expression.length()); String oppName = expression.substring(0, expression.indexOf("@EC@")); expression = expression.substring(expression.indexOf("@EC@") + 4, expression.length()); for (ExpressionType n : ExpressionType.values()) { if (n.toString().equals(oppName)) { m_operator = n; break; } } if (expression.startsWith("@@")) { // rhs is an attribute expression = expression.substring(2, expression.length()); // strip off // "@@" m_rhsIsAttribute = true; } m_rhsOperand = expression.substring(0, expression.indexOf(']')); expression = expression.substring(expression.indexOf(']') + 1, expression.length()); // remove "]" if (expression.charAt(0) == ' ') { expression = expression.substring(1, expression.length()); } return expression; }
void processOutput(OutputContext oc) { assertCond(classLiteralValue != null); int s0 = classLiteralValue.objectSize(); if (s0 != Type.OBJECTARRAY) { oc.cPrint(classLiteralValue.signatureClass().getClassRefStr(s0 > Type.CLASSINTERFACE)); } else { oc.cPrint(md != null ? md.routineCName() : MethodDefinition.UNKNOWN_NAME); Main.dict.normalCalls++; oc.cPrint("("); oc.cPrint(classLiteralValue.signatureClass().getClassRefStr(false)); oc.cPrint(", "); oc.cPrint(Integer.toString(classLiteralValue.signatureDimensions())); oc.cPrint(")"); } }
void discoverObjLeaks() { assertCond(exprType != null); terms[0].discoverObjLeaks(); if (exprType.objectSize() >= Type.CLASSINTERFACE) { terms[0].setObjLeaks(null); } }
ExpressionType traceClassInit() { assertCond(classLiteralValue != null); Main.dict.addDynClassToTrace(classLiteralValue.signatureClass()); if (md != null) { md.methodTraceClassInit(false, null, null); } return null; }
void processPass1(Context c) { if (classLiteralValue == null) { terms[0].processPass1(c); ExpressionType exprType0 = terms[0].exprType(); ClassDefinition cd = exprType0.signatureClass(); cd.predefineClass(c.forClass); cd.markUsed(); classLiteralValue = exprType0.signatureDimensions() > 0 ? exprType0 : cd.asExactClassType(); if (exprType0.objectSize() == Type.OBJECTARRAY) { cd = Main.dict.get(Names.JAVA_LANG_VMCLASS); cd.predefineClass(c.forClass); MethodDefinition md = cd.getMethod(Names.SIGN_ARRAYCLASSOF0X); if (md != null && md.isClassMethod()) { md.markUsed(null); this.md = md; } } classLiteralValue.signatureClass().setVTableUsed(false); } }
void processPass1(Context c) { exprType = c.currentVarType; terms[0].processPass1(c); int s0 = terms[0].exprType().objectSize(); c.arrInitCount++; int s1 = exprType.objectSize(); if (s0 == Type.BOOLEAN ? s1 != Type.BOOLEAN : s0 >= Type.CLASSINTERFACE ? s1 < Type.CLASSINTERFACE : s0 >= Type.LONG && s1 < s0) { fatalError(c, "Incompatible types in array initializer"); } }
/** * Class constructor. * * @param returns the number of values to return */ public LockWindowInstruction(int returns) { if (!SectionInfo.in() && !FunctionInfo.in()) throw new NslContextException(EnumSet.of(NslContext.Section, NslContext.Function), name); if (returns > 0) throw new NslReturnValueException(name); ArrayList<Expression> paramsList = Expression.matchList(); if (paramsList.size() != 1) throw new NslArgumentException(name, 1); this.value = paramsList.get(0); if (!ExpressionType.isString(this.value)) throw new NslArgumentException(name, 1, ExpressionType.String); }
@SuppressWarnings("unchecked") @Override public Function<Object[], ?> visit(UnaryExpression e) { final Function<Object[], ?> first = e.getFirst().accept(this); switch (e.getExpressionType()) { case ExpressionType.ArrayLength: return t -> Array.getLength(first.apply(t)); case ExpressionType.BitwiseNot: return (Function<Object[], ?>) bitwiseNot((Function<Object[], Number>) first); case ExpressionType.Convert: final Class<?> to = e.getResultType(); if (to.isPrimitive() || Number.class.isAssignableFrom(to)) return t -> { Object source = first.apply(t); if (source instanceof Number) { Number result = (Number) source; if (to.isPrimitive()) { if (to == Integer.TYPE) return result.intValue(); if (to == Long.TYPE) return result.longValue(); if (to == Float.TYPE) return result.floatValue(); if (to == Double.TYPE) return result.doubleValue(); if (to == Byte.TYPE) return result.byteValue(); if (to == Character.TYPE) return (char) result.intValue(); if (to == Short.TYPE) return result.shortValue(); } else if (result != null) { if (to == BigInteger.class) return BigInteger.valueOf(result.longValue()); if (to == BigDecimal.class) return BigDecimal.valueOf(result.doubleValue()); } } if (source instanceof Character) { if (to == Integer.TYPE) return (int) (char) source; if (to == Long.TYPE) return (long) (char) source; if (to == Float.TYPE) return (float) (char) source; if (to == Double.TYPE) return (double) (char) source; } return to.cast(source); }; return first; case ExpressionType.IsNull: return first.andThen(r -> r == null); case ExpressionType.LogicalNot: return normalize(not((Function<Object[], Boolean>) first)); case ExpressionType.Negate: return (Function<Object[], ?>) negate((Function<Object[], Number>) first); case ExpressionType.Quote: return constant(first); // case ExpressionType.UnaryPlus: // return abs((Function<? extends Number, Object[]>) first); default: throw new IllegalArgumentException(ExpressionType.toString(e.getExpressionType())); } }
private void toString(StringBuffer buff, boolean internal) { if (internal || m_showAndOr) { if (m_isAnOr) { buff.append("|| "); } else { buff.append("&& "); } } if (isNegated()) { buff.append("!"); } buff.append("["); buff.append(m_lhsAttributeName); if (internal) { buff.append("@EC@" + m_operator.toString()); } else { buff.append(" " + m_operator.toString()); } if (m_operator != ExpressionType.ISMISSING) { // @@ indicates that the rhs is an attribute if (internal) { buff.append("@EC@" + (m_rhsIsAttribute ? "@@" : "") + m_rhsOperand); } else { buff.append(" " + (m_rhsIsAttribute ? "ATT: " : "") + m_rhsOperand); } } else { if (internal) { buff.append("@EC@"); } else { buff.append(" "); } } buff.append("]"); }
boolean storeClassLiteralsGuess(ObjVector parmSig, boolean isActual) { ExpressionType exprType0; if (isActual) { exprType0 = terms[0].actualExprType(); int s0 = exprType0.objectSize(); if (s0 < Type.CLASSINTERFACE) return false; if (s0 == Type.CLASSINTERFACE) { ClassDefinition cd = exprType0.receiverClass(); exprType0 = cd.name().equals(Names.JAVAX_SWING_PLAF_COLORUIRESOURCE) ? cd.superClass() : cd.mapToPrimType(); } } else { exprType0 = terms[0].classLiteralValGuess(); if (exprType0 == null) return false; if (exprType0.signatureDimensions() == 0) { exprType0 = exprType0.receiverClass(); } } parmSig.addElement(exprType0); return true; }
void processOutput(OutputContext oc) { int s0 = exprType.objectSize(); if (oc.arrInitCount >= 0) { ConstValue constVal0; if (s0 >= Type.CLASSINTERFACE ? terms[0].exprType().objectSize() != Type.NULLREF : (constVal0 = terms[0].evaluateConstValue()) == null || constVal0.isNonZero()) { assertCond(oc.arrInitLevel > 0); oc.arrayIndent(); oc.cPrint("JCGO_ARR_INTERNALACC("); oc.cPrint(Type.cName[s0 < Type.CLASSINTERFACE ? s0 : Type.CLASSINTERFACE]); oc.cPrint(", ("); oc.cPrint( Type.cName[ s0 < Type.BOOLEAN || s0 > Type.DOUBLE ? Type.OBJECTARRAY : Type.CLASSINTERFACE + s0]); oc.cPrint(")"); oc.cPrint(OutputContext.getRcvrName(oc.arrInitLevel, Type.CLASSINTERFACE)); oc.cPrint(", "); oc.cPrint(Integer.toString(oc.arrInitCount)); oc.cPrint(")= "); if (s0 >= Type.CLASSINTERFACE || s0 == Type.BOOLEAN || terms[0].exprType().objectSize() != s0 || (s0 >= Type.BYTE && s0 < Type.INT && terms[0].isLiteral())) { oc.cPrint("("); oc.cPrint(Type.cName[s0 < Type.CLASSINTERFACE ? s0 : Type.CLASSINTERFACE]); oc.cPrint(")"); terms[0].atomaryOutput(oc); } else { terms[0].processOutput(oc); } oc.cPrint(","); } oc.arrInitCount++; } else { if (s0 >= Type.CLASSINTERFACE || terms[0].exprType().objectSize() != s0) { oc.cPrint("("); oc.cPrint(Type.cName[s0 < Type.CLASSINTERFACE ? s0 : Type.CLASSINTERFACE]); oc.cPrint(")"); terms[0].atomaryOutput(oc); } else { terms[0].processOutput(oc); } oc.cPrint(", "); } }
@Override public boolean evaluate(Instance inst, boolean result) { boolean thisNode = m_operator.evaluate( inst, m_lhsAttIndex, m_rhsOperand, m_numericOperand, m_regexPattern, m_rhsIsAttribute, m_rhsAttIndex); if (isNegated()) { thisNode = !thisNode; } return (isOr() ? (result || thisNode) : (result && thisNode)); }
@SuppressWarnings("unchecked") @Override public Function<Object[], ?> visit(BinaryExpression e) { final Function<Object[], ?> first = e.getFirst().accept(this); final Function<Object[], ?> second = e.getSecond().accept(this); switch (e.getExpressionType()) { case ExpressionType.Add: return normalize( add((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.BitwiseAnd: return normalize( bitwiseAnd((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.LogicalAnd: return normalize( and((Function<Object[], Boolean>) first, (Function<Object[], Boolean>) second)); case ExpressionType.ArrayIndex: return t -> Array.get(first.apply(t), (Integer) second.apply(t)); // return new Function<Object, Object[]>() { // // @Override // public Object invoke(Object[] t) throws Throwable { // return Array.get(first.invoke(t), (Integer) second // .invoke(t)); // } // }; // case ExpressionType.Coalesce: // return coalesce((Function<?, Object[]>) first, // (Function<?, Object[]>) second); case ExpressionType.Conditional: return iif((Function<Object[], Boolean>) e.getOperator().accept(this), first, second); case ExpressionType.Divide: return normalize( divide((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.Equal: return normalize(equal(first, second)); case ExpressionType.ExclusiveOr: return normalize( xor((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.GreaterThan: return normalize( greaterThan((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.GreaterThanOrEqual: return normalize( greaterThanOrEqual( (Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.LeftShift: return normalize( shiftLeft((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.LessThan: return normalize( lessThan((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.LessThanOrEqual: return normalize( lessThanOrEqual( (Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.Modulo: return normalize( modulo((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.Multiply: return normalize( multiply((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.NotEqual: return normalize(equal(first, second).negate()); case ExpressionType.BitwiseOr: return normalize( bitwiseOr((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.LogicalOr: return normalize( or((Function<Object[], Boolean>) first, (Function<Object[], Boolean>) second)); // case ExpressionType.Power: // return power((Function<Number, Object[]>) first, // (Function<Number, Object[]>) second); case ExpressionType.RightShift: return normalize( shiftRight((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.Subtract: return normalize( subtract((Function<Object[], Number>) first, (Function<Object[], Number>) second)); case ExpressionType.InstanceOf: return normalize(instanceOf(first, (Class<?>) second.apply(null))); default: throw new IllegalArgumentException(ExpressionType.toString(e.getExpressionType())); } }
@Override public ExpressionType getType() { return ExpressionType.getType(getQtiClassName()); }
/** * Sets the type of this expression. * * @param expressionType the expression type to use. * @return this ExpressionBuilder itself, for chain calls. * @see ExpressionType */ public ExpressionBuilder setExpressionType(final ExpressionType expressionType) { expression.setExpressionType(expressionType.name()); return this; }
@Override public int hashCode() { int result = nodeType != null ? nodeType.hashCode() : 0; result = 31 * result + (type != null ? type.hashCode() : 0); return result; }
/** * Class constructor. * * @param returns the number of values to return */ public CreateFontInstruction(int returns) { if (PageExInfo.in()) throw new NslContextException( EnumSet.of(NslContext.Section, NslContext.Function, NslContext.Global), name); if (returns != 1) throw new NslReturnValueException(name); ArrayList<Expression> paramsList = Expression.matchList(); int paramsCount = paramsList.size(); if (paramsCount < 1 || paramsCount > 6) throw new NslArgumentException(name, 1, 6); this.fontFace = paramsList.get(0); if (!ExpressionType.isString(this.fontFace)) throw new NslArgumentException(name, 1, ExpressionType.String); if (paramsCount > 1) { this.height = paramsList.get(1); if (!ExpressionType.isInteger(this.height)) throw new NslArgumentException(name, 2, ExpressionType.Integer); if (paramsCount > 2) { this.weight = paramsList.get(2); if (!ExpressionType.isInteger(this.weight)) throw new NslArgumentException(name, 3, ExpressionType.Integer); if (paramsCount > 3) { this.italic = paramsList.get(3); if (!ExpressionType.isBoolean(this.italic)) throw new NslArgumentException(name, 4, ExpressionType.Boolean); if (paramsCount > 4) { this.underline = paramsList.get(4); if (!ExpressionType.isBoolean(this.underline)) throw new NslArgumentException(name, 5, ExpressionType.Boolean); if (paramsCount > 5) { this.strike = paramsList.get(5); if (!ExpressionType.isBoolean(this.strike)) throw new NslArgumentException(name, 6, ExpressionType.Boolean); } else { this.strike = null; } } else { this.underline = null; this.strike = null; } } else { this.italic = null; this.underline = null; this.strike = null; } } else { this.weight = null; this.italic = null; this.underline = null; this.strike = null; } } else { this.height = null; this.weight = null; this.italic = null; this.underline = null; this.strike = null; } }
boolean isLiteral() { assertCond(classLiteralValue != null); return classLiteralValue.objectSize() != Type.OBJECTARRAY; }