public static object GetTypedValue(object value, MmlDataType type) { switch (type) { case MmlDataType.Any: return value; case MmlDataType.String: return value.ToString (); case MmlDataType.Number: if (value is double) return value; if (value is int) return (double) (int) value; if (value is byte) return (double) (byte) value; if (value is MmlLength) return (double) ((MmlLength) value).GetSteps (MmlValueExpr.BaseCount); break; // error case MmlDataType.Length: if (value is MmlLength) return value; int denom = 0; if (value is double) denom = (int) (double) value; else if (value is int) denom = (int) value; else if (value is byte) denom = (byte) value; else break; // error return new MmlLength (denom); } // FIXME: supply location throw new MmlException (String.Format ("Invalid value {0} for the expected data type {1}", value, type), null); }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { Content.Resolve (ctx, type); ResolvedValue = Content.ResolvedValue; }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { Left.Resolve (ctx, type); Right.Resolve (ctx, type); if (type == MmlDataType.Length) ResolvedValue = new MmlLength ((int) (Left.DoubleValue + Right.DoubleValue)) { IsValueByStep = true }; else ResolvedValue = Left.DoubleValue + Right.DoubleValue; }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { if (ResolvedValue == null) { if (type == MmlDataType.Buffer) ResolvedValue = new StringBuilder (); else ResolvedValue = GetTypedValue (Value, type); } }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { // multiplication cannot be straightforward. Number * Length must be Length, // but the number must not be converted to a length e.g. "1" must not be // interpreted as %{$__base_count}. Actually Length * Length must be invalid. Left.Resolve (ctx, MmlDataType.Number); Right.Resolve (ctx, type); if (type == MmlDataType.Length) ResolvedValue = new MmlLength ((int) (Left.DoubleValue * Right.DoubleValue)) { IsValueByStep = true }; else ResolvedValue = Left.DoubleValue * Right.DoubleValue; }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { Left.Resolve (ctx, type); Right.Resolve (ctx, type); switch (ComparisonType) { case ComparisonType.Lesser: ResolvedValue = ((IComparable) Left.ResolvedValue).CompareTo (Right.ResolvedValue) < 0 ? 1 : 0; break; case ComparisonType.LesserEqual: ResolvedValue = ((IComparable) Left.ResolvedValue).CompareTo (Right.ResolvedValue) <= 0 ? 1 : 0; break; case ComparisonType.Greater: ResolvedValue = ((IComparable) Left.ResolvedValue).CompareTo (Right.ResolvedValue) > 0 ? 1 : 0; break; case ComparisonType.GreaterEqual: ResolvedValue = ((IComparable) Left.ResolvedValue).CompareTo (Right.ResolvedValue) >= 0 ? 1 : 0; break; } }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { Condition.Resolve (ctx, MmlDataType.Number); TrueExpr.Resolve (ctx, type); FalseExpr.Resolve (ctx, type); ResolvedValue = Condition.IntValue != 0 ? TrueExpr.ResolvedValue : FalseExpr.ResolvedValue; }
void ResolveCore(MmlResolveContext ctx, MmlDataType type, bool excludeMacroArgs) { if (!excludeMacroArgs) { // reference to macro argument takes precedence object _arg = ctx.MacroArguments [Name]; if (_arg != null) { var arg = (KeyValuePair<MmlSemanticVariable,object>) _arg; ResolvedValue = GetTypedValue (arg.Value, type); return; } } var variable = (MmlSemanticVariable) ctx.SourceTree.Variables [Name]; if (variable == null) // FIXME: supply location throw new MmlException (String.Format ("Cannot resolve variable '{0}'", Name), null); var val = ctx.EnsureDefaultResolvedVariable (variable); ResolvedValue = GetTypedValue (val, type); }
public override void Resolve(MmlResolveContext ctx, MmlDataType type) { if (Scope == 3) { if (ctx.GlobalContext == null) throw new MmlException (String.Format ("Global variable '{0}' cannot be resolved at this compilation phase", Name), null); ResolveCore (ctx.GlobalContext, type, true); } else ResolveCore (ctx, type, Scope > 1); }
public abstract void Resolve(MmlResolveContext ctx, MmlDataType type);
public MmlSemanticVariable(string name, MmlDataType type) { Name = name; Type = type; }
public MmlConstantExpr(MmlDataType type, object value) { Type = type; Value = value; }