de.gaalop.dfg.Expression类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中de.gaalop.dfg.Expression类的一些代码示例,展示了Expression类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Expression类的具体详情如下:
包路径:de.gaalop.dfg.Expression
类名称:Expression

Expression介绍

[英]This class represents a node of a dataflow graph.
[中]此类表示数据流图的节点。

代码示例

代码示例来源:origin: CallForSanity/Gaalop

private boolean containsMacroCall(Expression e) {
  final LinkedList<MacroCall> calls = new LinkedList<MacroCall>();
  e.accept(new DFGTraversalVisitor() {
    @Override
    public void visit(MacroCall node) {
      calls.add(node);
    }
  });
  return !calls.isEmpty();
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public ColorNode copyElements() {
  return new ColorNode(getGraph(), r.copy(), g.copy(), b.copy());
}

代码示例来源:origin: CallForSanity/Gaalop

if (old == left) {
  left = newExpression;
} else if (left.isComposite()) {
  left.replaceExpression(old, newExpression);
} else if (right.isComposite()) {
  right.replaceExpression(old, newExpression);

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void visit(AssignmentNode node) {
  node.getValue().accept(dfgReplacer);
  if (dfgReplacer.result != null) {
    node.setValue(dfgReplacer.result);
    dfgReplacer.result = null;
  }
  if (replaceMap.containsKey(node.getVariable().getName()))
    node.setVariable((Variable) replaceMap.get(node.getVariable().getName()).copy());
}

代码示例来源:origin: CallForSanity/Gaalop

/**
 * Performs constant propagtion on an expression and returns the result expression
 * @param expression the expression for constant propagtion
 * @return the result expression, where constant variables are constant
 */
private Expression performConstantPropagationOnExpression(Expression expression) {
  dfgVisitorUsedVariables.getVariables().clear();
  expression.accept(dfgVisitorUsedVariables);
  for (VariableComponent varComp : dfgVisitorUsedVariables.getVariables()) {
    if (mapConstants.containsKey(varComp)) {
      // replace variable with constant
      if (expression == varComp.getReferredExpression()) { 
        expression = mapConstants.get(varComp);
      } else {
        expression.replaceExpression(varComp.getReferredExpression(), mapConstants.get(varComp));
      }
      setGraphModified();
    }
  }
  // do a constant folding on the value
  expression.accept(constantFolding);
  if (constantFolding.isGraphModified()) {
    setGraphModified();
  }
  return constantFolding.getResultExpr();
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void replaceExpression(Expression old, Expression newExpression) {
  if (old == operand) {
    operand = newExpression;
  } else {
    operand.replaceExpression(old, newExpression);
  }
}

代码示例来源:origin: CallForSanity/Gaalop

public static String bracketComposite(Expression expression) {
  if (expression.isComposite()) {
    return "(" + expression + ")";
  } else {
    return expression.toString();
  }
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void visit(Multiplication node) {
  node.getLeft().accept(this);
  Expression dLeft = result;
  node.getRight().accept(this);
  Expression dRight = result;
  
  
  if (dLeft == zero) {
    if (dRight == zero) {
      result = zero;
    } else {
      result = new Multiplication(node.getLeft().copy(), dRight);
    }
  } else {
    //dLeft != zero !!
    if (dRight == zero) {
      result = new Multiplication(dLeft, node.getRight().copy());
    } else {
      result = new Addition(
        new Multiplication(dLeft, node.getRight().copy()),
        new Multiplication(node.getLeft().copy(), dRight)
          );
    }
  }
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void replaceExpression(Expression old, Expression newExpression) {
  if (variable == old && newExpression instanceof Variable) {
    variable = (Variable) newExpression;
  }
  if (value == old) {
    value = newExpression;
  } else {
    // recursively try to replace expression
    value.replaceExpression(old, newExpression);
  }
}

代码示例来源:origin: CallForSanity/Gaalop

private String bladeToString(Expression blade) {
  if (!blade.isComposite()) return blade.toString();
  OuterProduct outerProduct = (OuterProduct) blade;
  return bladeToString(outerProduct.getLeft())+"^"+bladeToString(outerProduct.getRight());
}

代码示例来源:origin: CallForSanity/Gaalop

protected void addChild(Expression parent, Expression child) {
  if (OperatorPriority.hasLowerPriority(parent, child)) {
    code.append('(');
    child.accept(this);
    code.append(')');
  } else {
    child.accept(this);
  }
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void visit(Division node) {
  node.getLeft().accept(this);
  Expression dLeft = result;
  node.getRight().accept(this);
  Expression dRight = result;
          new Division(
            new Multiplication(
              node.getLeft().copy(),
              dRight
            ),
            new Multiplication(
              node.getRight().copy(), 
              node.getRight().copy()
            new Multiplication(
              dLeft,
              node.getRight().copy()
            ),
            new Multiplication(
              node.getRight().copy(), 
              node.getRight().copy()
      result = new Division(
        new Subtraction(
          new Multiplication(dLeft, node.getRight().copy()),
          new Multiplication(node.getLeft().copy(), dRight)
        ),
        new Multiplication(node.getRight().copy(), node.getRight().copy()

代码示例来源:origin: CallForSanity/Gaalop

/**
 * Creates an expression node that negates the given expression.
 * 
 * @param value The expression that should be negated. A deep copy will be created.
 * @return A Negation object that negates the given expression.
 */
public static Negation negate(Expression value) {
  return new Negation(value.copy());
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void replaceExpression(Expression old, Expression newExpression) {
  if (expression == old) {
    expression = newExpression;
  } else {
    expression.replaceExpression(old, newExpression);
  }
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void visit(Inequality node) {
  result.append("notequal(");
  node.getLeft().accept(this);
  result.append(",");
  node.getRight().accept(this);
  result.append(")");
}

代码示例来源:origin: CallForSanity/Gaalop

Expression copiedReturnVal = macro.getReturnValue().copy();
copiedReturnVal.accept(d);

代码示例来源:origin: CallForSanity/Gaalop

/**
 * Creates an exponentation node that squares the given expression.
 * 
 * @param base The expression that should be squared. A deep copy will be created.
 * @return An exponentation object that exponentiates the given base with a float constant of 2.0.
 */
public static Multiplication square(Expression base) {
  return new Multiplication(base, base.copy());
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void replaceExpression(Expression old, Expression newExpression) {
  for (int i = 0; i < args.size(); i++) {
    Expression arg = args.get(i);
    if (arg == old) {
      args.set(i, newExpression);
    } else {				
      arg.replaceExpression(old, newExpression);
    }            
  }
}

代码示例来源:origin: CallForSanity/Gaalop

/**
 * Returns the direct summands of a given expression
 * @param expresssion The expression
 * @return The direct summands
 */
public static Sum getSignedSummands(Expression expresssion) {
  SignedSummandsGetter getter = new SignedSummandsGetter();
  expresssion.accept(getter);
  return getter.summands;
}

代码示例来源:origin: CallForSanity/Gaalop

@Override
public void visit(Exponentiation node) {
  node.getLeft().accept(this);
  Expression dLeft = result;
  node.getRight().accept(this);
  Expression dRight = result;
          node.getRight().copy(), 
          new Exponentiation(
            node.getLeft().copy(),
            new Subtraction(node.getRight().copy(), new FloatConstant(1))
      node.getRight().accept(this);
      Expression dv = result;
      result = new Multiplication(
            new Multiplication(dv, new MathFunctionCall(node.getLeft().copy(), MathFunction.LOG)),
            node.copy()
          );
    } else {
      node.getRight().accept(this);
      Expression dv = result;
      result = new Multiplication(new Addition(
            new Multiplication(dv, new MathFunctionCall(node.getLeft().copy(), MathFunction.LOG)),
            new Division(new Multiplication(node.getRight().copy(), dLeft), node.getLeft().copy())
          ),
          node.copy());

相关文章

微信公众号

最新文章

更多