public static CGExpr BuildExpression(FullCellAddr addr, Dictionary<FullCellAddr, Variable> addressToVariable) { Cell cell; if (!addr.TryGetCell(out cell)) { return new CGTextConst(TextValue.EMPTY); } else if (cell is NumberCell) { return new CGNumberConst(((NumberCell)cell).value); } else if (cell is TextCell) { return new CGTextConst(((TextCell)cell).value); } else if (cell is QuoteCell) { return new CGTextConst(((QuoteCell)cell).value); } else if (cell is BlankCell) { return new CGError("#FUNERR: Blank cell in function"); } else if (cell is Formula) { // Translate the expr relative to its containing cell at addr CGExpressionBuilder cgBuilder = new CGExpressionBuilder(addressToVariable, addr); Expr expr = ((Formula)cell).Expr; expr.VisitorCall(cgBuilder); return cgBuilder.result; } else if (cell is ArrayFormula) { return new CGError("#FUNERR: Array formula in function"); } else { throw new ImpossibleException("BuildExpression: " + cell); } }
/// <summary> /// Count number of references from cell at fromFca to cell address toFca /// </summary> private static int GetCount(FullCellAddr fromFca, FullCellAddr toFca) { int count = 0; Cell fromCell; if (fromFca.TryGetCell(out fromCell)) { fromCell.DependsOn(fromFca, delegate(FullCellAddr fca) { if (toFca.Equals(fca)) { count++; } }); } return(count); }
public static CGExpr BuildExpression(FullCellAddr addr, Dictionary <FullCellAddr, Variable> addressToVariable) { Cell cell; if (!addr.TryGetCell(out cell)) { return(new CGTextConst(TextValue.EMPTY)); } else if (cell is NumberCell) { return(new CGNumberConst(((NumberCell)cell).value)); } else if (cell is TextCell) { return(new CGTextConst(((TextCell)cell).value)); } else if (cell is QuoteCell) { return(new CGTextConst(((QuoteCell)cell).value)); } else if (cell is BlankCell) { return(new CGError("#FUNERR: Blank cell in function")); } else if (cell is Formula) { // Translate the expr relative to its containing cell at addr CGExpressionBuilder cgBuilder = new CGExpressionBuilder(addressToVariable, addr); Expr expr = ((Formula)cell).Expr; expr.VisitorCall(cgBuilder); return(cgBuilder.result); } else if (cell is ArrayFormula) { return(new CGError("#FUNERR: Array formula in function")); } else { throw new ImpossibleException("BuildExpression: " + cell); } }
/// <summary> /// Count number of references from cell at fromFca to cell address toFca /// </summary> private static int GetCount(FullCellAddr fromFca, FullCellAddr toFca) { int count = 0; Cell fromCell; if (fromFca.TryGetCell(out fromCell)) { fromCell.DependsOn(fromFca, delegate(FullCellAddr fca) { if (toFca.Equals(fca)) { count++; } }); } return count; }