/// <summary> /// Define a constant in the MSL. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="constant"></param> private void BuildConstant <T>(Variable <T> constant) { if (constant.IsBase) { if (ShouldInlineConstant(constant)) { // do nothing. the value will be put inline. } else { // check if we have defined a constant with the same value already IVariableDeclaration ivd; bool useExisting = false; object key = constant.ObservedValue; if (ReferenceEquals(key, null)) { key = new NullValue <T>(); } if (constants.TryGetValue(key, out ivd)) { // use the declaration of the existing constant useExisting = constant.SetDeclaration(ivd); } if (!useExisting) { // create a new declaration ivd = (IVariableDeclaration)constant.GetDeclaration(); var rhs = Quoter.Quote(constant.ObservedValue); if (ReferenceEquals(constant.ObservedValue, null)) { rhs = Builder.CastExpr(rhs, typeof(T)); } AddStatement(Builder.AssignStmt(Builder.VarDeclExpr(ivd), rhs)); constants[key] = ivd; } FinishGivenOrConstant(constant, ivd); } } else if (constant.IsArrayElement) { // do nothing } else { throw new NotImplementedException("Unhandled constant type: " + constant); } }
internal IStatement GetAccumulateStatement(BasicTransformContext context, IExpression accumulator, IExpression value) { IExpression imie = Builder.StaticGenericMethod(accumulateMethod, new Type[] { accumulator.GetExpressionType() }, accumulator, value); return(Builder.AssignStmt(accumulator, imie)); }