public Expression processIdentifier(String name) { /*//@changedalgebra String hashname = NameTable.getInstance().add(name); if (mode != null && mode.isConstant(hashname)) { return mode.getConstant(hashname); } else { return new Variable(hashname); } */ return new Variable(name); } public Expression processFunction(String name, List<Expression> args) {
/** * A human readable string representation of this multivector component. * @return The string "name[bladeIndex]" where name is the name of the multivector and bladeIndex is the index * returned by <code>getBladeIndex()</code>. */ @Override public String toString() { return super.toString() + "[" + bladeIndex + "]"; }
@Override public Variable copy() { Variable v = new Variable(this.name); v.global = global; v.setMaxValue(this.getMaxValue()); v.setMinValue(this.getMinValue()); return v; }
@Override public void replaceExpression(Expression old, Expression newExpression) { if (old instanceof Variable && newExpression instanceof Variable) { Variable oldVar = (Variable) old; Variable newVar = (Variable) newExpression; if (oldVar.getName() == name && oldVar.getMinValue() == minValue && oldVar.getMaxValue() == maxValue) { name = newVar.getName(); minValue = newVar.getMinValue(); maxValue = newVar.getMaxValue(); } } }
@Override public void visit(AssignmentNode node) { if (assigned.contains(node.getVariable().getName())) { log.warn("Reuse of variable " + node.getVariable().getName() + ". Make sure to reset this variable or use another name."); code.append("\n"); appendIndentation(); code.append("// Warning: reuse of variable "); code.append(node.getVariable().getName()); code.append(".\n"); appendIndentation(); code.append("// Make sure to reset this variable or use another name.\n"); assigned.remove(node.getVariable().getName()); } appendIndentation(); node.getVariable().accept(this); code.append(" = "); node.getValue().accept(this); code.append(";\n"); node.getSuccessor().accept(this); } }
/** * Searches the expression for variable references. If an undeclared reference is found, it is added to the input variables of * the graph. * * @param expression The expression to search in. */ private void findUndeclaredVariables(Expression expression) { UsedVariablesVisitor visitor = new UsedVariablesVisitor(); expression.accept(visitor); for (Variable usedVariable : visitor.getVariables()) { if (!graph.getLocalVariables().contains(usedVariable)) { // in case we have pragmas giving ranges for the variable, add them if (graph.getPragmaMinValue().containsKey(usedVariable.getName())) { usedVariable.setMinValue(graph.getPragmaMinValue().get(usedVariable.getName())); } if (graph.getPragmaMaxValue().containsKey(usedVariable.getName())) { usedVariable.setMaxValue(graph.getPragmaMaxValue().get(usedVariable.getName())); } graph.addInputVariable(usedVariable); } } }
@Override public void visit(StoreResultNode node) { node.getValue().accept(expressionVisitor); super.visit(node); } }
@Override public void visit(Variable node) { MvExpressions v = null; String key = node.toString(); if (variables.containsKey(key)) { v = createNewMvExpressions(); for (int i = 0; i < bladeCount; i++) { if (variables.get(key).bladeExpressions[i] != null) { v.bladeExpressions[i] = new MultivectorComponent(node.getName(), i); } } } else { //input variable! v = createNewMvExpressions(); v.bladeExpressions[0] = node; } expressions.put(node, v); }
@Override public void visit(Variable variable) { if (variable.globalAccess()) { code.append("::"); } code.append(variable.getName().replace(optSuffix, suffix)); }
@Override public Object visitOutputAssignmentCaseQ(CluCalcParser.OutputAssignmentCaseQContext ctx) { AssignmentNode assignment = (AssignmentNode) visit(ctx.val); SequentialNode n2 = graphBuilder.handlePrint(assignment.getVariable().copy()); if (inMacro) macroNodes.add(n2); else nodes.add(n2); return null; }
@Override public void visit(AssignmentNode node) { if (assigned.contains(node.getVariable().getName())) { log.warn("Reuse of variable " + node.getVariable().getName() + ". Make sure to reset this variable or use another name."); code.append("\n"); appendIndentation(); code.append("// Warning: reuse of variable "); code.append(node.getVariable().getName()); code.append(".\n"); appendIndentation(); code.append("// Make sure to reset this variable or use another name.\n"); assigned.remove(node.getVariable().getName()); } appendIndentation(); node.getVariable().accept(new MultivectorComponentWriteVisitor()); code.append(" = "); node.getValue().accept(this); code.append(";\n"); node.getSuccessor().accept(this); }
result = new Variable("x"); if (node.getName().equals("_V_Y")) result = new Variable("y"); if (node.getName().equals("_V_Z")) result = new Variable("z"); sb.append("\n"); for (AssignmentNode node: list) { String name = node.getVariable().getName(); String newName = renderingExpressions.get(name).toString(); AssignmentNode nodeCpy = node.copyElements();
/** * Searches the expression for variable references. If an undeclared reference is found, it is added to the * input variables of the graph. * * @param expression The expression to search in. * @param inMacro */ private void findUndeclaredVariables(Expression expression) { UsedVariablesVisitor visitor = new UsedVariablesVisitor(); expression.accept(visitor); for (Variable usedVariable : visitor.getVariables()) { checkIllegalVariable(usedVariable); if (!graph.getLocalVariables().contains(usedVariable)) { // in case we have pragmas giving ranges for the variable, add them if (graph.getPragmaMinValue().containsKey(usedVariable.getName())) { usedVariable.setMinValue(graph.getPragmaMinValue().get(usedVariable.getName())); } if (graph.getPragmaMaxValue().containsKey(usedVariable.getName())) { usedVariable.setMaxValue(graph.getPragmaMaxValue().get(usedVariable.getName())); } graph.addInputVariable(usedVariable); } } }
@Override public void visit(StoreResultNode node) { node.getValue().accept(visitorExp); super.visit(node); } };
@Override public StoreResultNode copyElements() { return new StoreResultNode(getGraph(), value.copy()); }
/** * Create a new temporary, recently unused variable name * @return The new name */ private Variable getNewTemporaryVariable() { tempCounter++; while (variables.contains("temp" + tempCounter)) { tempCounter++; } return new Variable("temp" + tempCounter); } private HashMap<Variable, Expression> toInsert = new HashMap<Variable, Expression>();
@Override public void visit(AssignmentNode node) { String variable = node.getVariable().getName(); if (assigned.contains(variable)) { String message = "Variable " + variable + " has been reset for reuse."; log.warn(message); Notifications.addWarning(message); code.append("\n"); appendIndentation(); code.append("memset("); code.append(variable); code.append(", 0, sizeof("); code.append(variable); code.append(")); // Reset variable for reuse.\n"); assigned.remove(variable); } appendIndentation(); node.getVariable().accept(this); code.append(" = "); node.getValue().accept(this); code.append(";"); if (node.getVariable() instanceof MultivectorComponent) { code.append(" // "); MultivectorComponent component = (MultivectorComponent) node.getVariable(); code.append(node.getGraph().getAlgebraDefinitionFile().getBladeString(component.getBladeIndex())); } code.append('\n'); node.getSuccessor().accept(this); }