public static List <Tuple <NumberRep, CodePiece> > GenerateAllCode(long value, bool filter, bool reversed = false) { List <Tuple <NumberRep, CodePiece> > result = new List <Tuple <NumberRep, CodePiece> >(); // Order is Priority !!! result.Add(Tuple.Create(NumberRep.Boolean, NumberCodeFactoryBoolean.GenerateCode(value, reversed))); result.Add(Tuple.Create(NumberRep.Digit, NumberCodeFactoryDigit.GenerateCode(value, reversed))); result.Add(Tuple.Create(NumberRep.Base9, NumberCodeFactoryBase9.GenerateCode(value, reversed))); result.Add(Tuple.Create(NumberRep.Factorization, NumberCodeFactoryFactorization.GenerateCode(value, reversed))); result.Add(Tuple.Create(NumberRep.StringmodeChar, NumberCodeFactoryStringmodeChar.GenerateCode(value, reversed))); result.Add(Tuple.Create(NumberRep.Stringify, NumberCodeFactoryStringify.GenerateCode(value, reversed))); if (filter) { return(result.Where(p => p.Item2 != null).ToList()); } else { return(result); } }
public static CodePiece GenerateCode(long value) { CodePiece p; if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.Best) { List <Tuple <NumberRep, CodePiece> > representations = GenerateAllCode(value, true); int min = representations.Min(lp => lp.Item2.Width); foreach (var rep in representations) { if (rep.Item2.Width == min) { LastRep = rep.Item1; p = rep.Item2; return(p); } } } else if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.StringmodeChar) { p = NumberCodeFactoryStringmodeChar.GenerateCode(value); LastRep = NumberRep.StringmodeChar; return(p); } else if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.Base9) { p = NumberCodeFactoryBase9.GenerateCode(value); LastRep = NumberRep.Base9; return(p); } else if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.Factorization) { p = NumberCodeFactoryFactorization.GenerateCode(value); LastRep = NumberRep.Factorization; return(p); } else if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.Stringify) { p = NumberCodeFactoryStringify.GenerateCode(value); LastRep = NumberRep.Stringify; return(p); } else if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.Digit) { p = NumberCodeFactoryDigit.GenerateCode(value); LastRep = NumberRep.Digit; return(p); } else if (ASTObject.CGO.NumberLiteralRepresentation == NumberRep.Boolean) { p = NumberCodeFactoryBoolean.GenerateCode(value); LastRep = NumberRep.Boolean; return(p); } throw new WTFException(); }