/// <summary> /// Create a for loop statement. /// </summary> /// <param name="loopVariable">The variable that will be running in the loop</param> /// <param name="arraySizeVar">The size of the array. Evaluated just once before the loop is run.</param> /// <param name="startValue">Initial spot in array, defaults to zero</param> public StatementForLoop(IDeclaredParameter loopVariable, IValue arraySizeVar, IValue startValue = null) { if (loopVariable == null) { throw new ArgumentNullException("loopVariable"); } if (arraySizeVar == null) { throw new ArgumentNullException("arraySizeVar"); } ArrayLength = arraySizeVar; _loopVariable = loopVariable; InitialValue = startValue; if (InitialValue == null) { InitialValue = new ValSimple("0", typeof(int), null); } if (ArrayLength.Type != typeof(int)) { throw new ArgumentException("arraySizeVar must be an integer"); } if (InitialValue.Type != typeof(int)) { throw new ArgumentException("startValue must be an integer"); } arrIndex = typeof(int).CreateUniqueVariableName(); }
/// <summary>Test stub for CanHandle(IVariable)</summary> ///[PexMethod] internal bool CanHandle(SaveVarObject target, IDeclaredParameter iVariable) { bool result = target.CanHandle(iVariable); return(result); // TODO: add assertions to method SaveVarObjectTest.CanHandle(SaveVarObject, IVariable) }
public TooManyStatemnets() { var vInt = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)); vInt.SetInitialValue("2"); ResultValues = new IDeclaredParameter[] { vInt }; }
/// <summary> /// Create a reference to a ROOT variable that is going to be loaded remotely. /// </summary> /// <param name="varName"></param> /// <param name="rootType"></param> public ROOTObjectCopiedValue(string varName, Type rootType, string CPPType, string name, string title) { if (string.IsNullOrWhiteSpace(varName)) throw new ArgumentException("invalid variable name"); if (string.IsNullOrWhiteSpace(CPPType)) throw new ArgumentException("Invalid C++ type name"); if (rootType == null) throw new ArgumentException("Invalid type"); /// /// The type and the loader string /// Type = rootType; OriginalName = name; OriginalTitle = title; StringBuilder loadString = new StringBuilder(); loadString.AppendFormat("LoadFromInputList<{0}>(\"{1}\")", CPPType, varName); RawValue = loadString.ToString(); Dependants = new IDeclaredParameter[] { DeclarableParameter.CreateDeclarableParameterExpression(varName, rootType) }; }
/// <summary> /// Generate the code to save this to a ROOT file to be passed back. /// We don't pass back the whole file - rather we just do the file path. /// </summary> /// <param name="v"></param> /// <returns></returns> public IEnumerable <string> SaveToFile(IDeclaredParameter v) { // To save this right we need to store a string with a lookup key. Unfortunately, TObjString // won't do that - it's Name is the same as its value. So lets just use a TH1 - as it has a name and // title. :-) if (v.InitialValue == null) { throw new InvalidOperationException($"Unable to save OutputTextFileType because it's parameter has no declared value!"); } // Close the file. yield return($"{v.RawValue}.close();"); // Write out the path. var fileAsCPPString = (v.InitialValue as OutputCSVTextFileType).OutputFile().FullName.AddCPPEscapeCharacters(); yield return(string.Format("TH1D *{0}_hist = new TH1D(\"{0}\", \"{1}\", 1, 0.0, 1.0);", v.RawValue, fileAsCPPString)); yield return(v.RawValue + "_hist->SetDirectory(0);"); yield return("Book(" + v.RawValue + "_hist);"); // Write out the mod time and the file size. yield return($"Long64_t {v.RawValue}_size;"); yield return($"Long_t {v.RawValue}_modification_time;"); yield return($"gSystem->GetPathInfo(\"<><>{fileAsCPPString}<><>\", 0, &{v.RawValue}_size, 0, &{v.RawValue}_modification_time);"); foreach (var s in SaveIntValue($"{v.RawValue}_size")) { yield return(s); } }
/// <summary> /// Rename succeeds if we can find the declared variable, among other things. /// </summary> /// <param name="oldName">Name of the old parameter that we are replacing</param> /// <param name="newParam">The new parameter we will replace it with</param> /// <param name="newHolderBlock">The booking context we are currently looking at for the new name (the _holder) of the statement we are looking at</param> /// <returns>True if the variables could be renamed (and the rename is done), false otherwise</returns> /// <remarks> /// The newHolderBlock is needed because it is used to determine if the new variable is declared in the same place /// or not. /// </remarks> public bool TryRenameVarialbeOneLevelUp(string oldName, IDeclaredParameter newParam) { // // First, see if we can find the block where the variable is declared. // var vr = FindDeclaredVariable(oldName, _holderBlockOld); if (vr == null) return false; // // Make sure that the variable we are switching to is also declared. If it is an "external" then we // are going to have a problem here! And, the variables had better be declared the same "scope" above, or // that means they are also being used for something different. // var vrNew = FindDeclaredVariable(newParam.ParameterName, _holderBlockNew); if (vrNew == null || vrNew.Item3 != vr.Item3) return false; // Check that its initialization is the same! bool initValueSame = (vr.Item1.InitialValue == null && newParam.InitialValue == null) || (vr.Item1.InitialValue != null && (vr.Item1.InitialValue.Type == newParam.InitialValue.Type && vr.Item1.InitialValue.RawValue == newParam.InitialValue.RawValue)); if (!initValueSame) return false; // Rename the variable! vr.Item2.RenameVariable(oldName, newParam.ParameterName); return true; }
/// <summary> /// Loop over all the indicies we are given (sort of like an indirect) in a double loop. For each one /// make sure that they satisfy the function. if we find any failing, mark both as bad. You must set /// the TEST variable, but do it after this guy is part of the generated code - scoping must be tracked /// correctly!! /// </summary> /// <param name="indiciesToInspect">The list of indicies we should set index1 and index2 to</param> /// <param name="index1">The name we should use for index 1</param> /// <param name="index2">the name we should use for index 2</param> /// <param name="passedArray">The initially empty bool vector that we will mark any index that satisfies everything as true</param> public StatementCheckLoopPairwise(IDeclaredParameter indiciesToInspect, IDeclaredParameter index1, IDeclaredParameter index2, IDeclaredParameter passedArray) { if (indiciesToInspect == null) { throw new ArgumentNullException("indiciesToInspect"); } if (index1 == null) { throw new ArgumentNullException("index1"); } if (index2 == null) { throw new ArgumentNullException("index2"); } if (passedArray == null) { throw new ArgumentNullException("passedArray"); } if (passedArray.Type == null) { throw new ArgumentNullException("Passed array type should not be null"); } if (!passedArray.Type.IsArray) { throw new ArgumentException("passedArray isn't an array type"); } _indciesToInspect = indiciesToInspect; _index1 = index1; _index2 = index2; _whatIsGood = passedArray; }
/// <summary> /// Generate a default value for a variable. /// </summary> /// <param name="v"></param> /// <returns></returns> private string GenerateDefaultValue(IDeclaredParameter v) { if (v == null) { throw new ArgumentNullException("v"); } if (v.InitialValue != null) { return(v.InitialValue.RawValue); } if (v.Type.IsNumberType()) { return("0"); } if (v.Type == typeof(bool)) { return("false"); } if (v.Type.IsArray) { return(""); } if (v.Type.IsClass || v.Type.IsGenericType) { return(""); } throw new NotSupportedException(string.Format("Don't know how to do default value for C++ variable of type {0}.", v.Type.ToString())); }
/// <summary> /// Fix up the filename for the cycle we have to deal with. /// </summary> /// <param name="iVariable"></param> /// <param name="obj"></param> /// <param name="cycle"></param> public void RenameForQueryCycle(IDeclaredParameter iVariable, NTObject[] obj, int cycle, DirectoryInfo queryDirectory) { if (obj == null || iVariable == null) { throw new ArgumentException("Null argument not permitted"); } var currentFile = GetFileInfo(iVariable, obj, alternatDirectory: queryDirectory); if (currentFile == null) { // If there is no current file - that manes that we are being asked to rename something that doesn't exist! GetFilePathFromObjects(obj, out NTH1 hPath, out NTH1 hSize); var pname = hPath == null ? "<noname>" : hPath.Title; var length = hSize == null ? 0 : (long)hSize.GetBinContent(1); throw new InvalidOperationException($"Unable to find the output file to rename (was looking for '{pname}' with no cycle and legnth {length})."); } var newFile = GetFileInfo(iVariable, obj, cycle, doChecks: false); if (newFile.Exists) { newFile.Delete(); } currentFile.MoveTo(newFile.FullName); }
/// <summary> /// Save how we are going to go after the statement and generate it. /// </summary> /// <param name="mapStorage">We own this variable - we can change its name</param> /// <param name="indexVar"></param> /// <param name="indexValue"></param> public StatementRecordPairValues(IDeclaredParameter mapStorage, IValue indexVar, IValue indexValue) { // // Input checks. // if (mapStorage == null) { throw new ArgumentNullException("mapStorage"); } if (indexVar == null) { throw new ArgumentNullException("indexVar"); } if (indexValue == null) { throw new ArgumentNullException("indexValue"); } // // Save for later // this._index = indexVar; AddSaver(mapStorage, indexValue); Debug.WriteLine("Emit StatementRecordPairValues: IndexVar {0}, indexValue {1}", indexVar.ToString(), indexValue.ToString()); }
/// <summary> /// Add a new saver to the list of things we are saving. /// </summary> /// <param name="val">The value that we should be caching</param> /// <param name="mr">The map we should cache it into</param> internal void AddSaver(IDeclaredParameter mr, IValue val) { _savers.Add(new saverInfo() { mapRecord = mr, indexValue = val }); }
/// <summary> /// Create a reference to a ROOT variable that is going to be loaded remotely. /// </summary> /// <param name="varName"></param> /// <param name="rootType"></param> public ROOTObjectCopiedValue(string varName, Type rootType, string CPPType, string name, string title) { if (string.IsNullOrWhiteSpace(varName)) { throw new ArgumentException("invalid variable name"); } if (string.IsNullOrWhiteSpace(CPPType)) { throw new ArgumentException("Invalid C++ type name"); } if (rootType == null) { throw new ArgumentException("Invalid type"); } /// /// The type and the loader string /// Type = rootType; OriginalName = name; OriginalTitle = title; StringBuilder loadString = new StringBuilder(); loadString.AppendFormat("LoadFromInputList<{0}>(\"{1}\")", CPPType, varName); RawValue = loadString.ToString(); Dependants = new IDeclaredParameter[] { DeclarableParameter.CreateDeclarableParameterExpression(varName, rootType) }; }
public StatementIncrementInteger Constructor(IDeclaredParameter i) { StatementIncrementInteger target = new StatementIncrementInteger(i); Assert.AreEqual(i, target.Integer, "initial value not set correctly"); return(null); }
/// <summary> /// Book a variable at the inner most scoping that is accepting variable /// declarations. /// </summary> /// <param name="v"></param> public void Add(IDeclaredParameter v, bool failIfALreadyThere = true) { if (v == null) { throw new ArgumentNullException("Cannot add a null variable!"); } CurrentDeclarationScopePointer.Add(v, failIfALreadyThere); }
/// <summary> /// Include files that need to be used. Since this is an file stream... /// </summary> /// <param name="iVariable"></param> /// <returns></returns> public IEnumerable <string> IncludeFiles(IDeclaredParameter iVariable) { yield return("TFile.h"); yield return("TTree.h"); yield return("TH1D.h"); }
public IVariableSaver Get(IDeclaredParameter var) { if (var == null) { throw new NotImplementedException("This should never happen"); } return(new SimpleVar()); }
/// <summary> /// Load up the item from the ROOT file. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="iVariable"></param> /// <param name="obj"></param> /// <returns></returns> public Task <T> LoadResult <T>(IDeclaredParameter iVariable, RunInfo[] objs) { var f = GetFileInfo(iVariable, objs.Select(fi => fi._result).ToArray(), objs.First()._cycle); return(Task.FromResult(f == null ? (T)(object)null : (T)(object)(new FileInfo[] { f }))); }
public void TestCombineDifInitial(IDeclaredParameter loopVarName, IValue ivalSize, IValue initialValue1, IValue initialValue2) { var p1 = new StatementForLoop(loopVarName, ivalSize, initialValue1); var p2 = new StatementForLoop(loopVarName, ivalSize, initialValue2); var r = p1.TryCombineStatement(p2, new dummyOpt()); Assert.IsFalse(r, "Should always be equal"); }
/// <summary> /// Include files that need to be used. Since this is an file stream... /// </summary> /// <param name="iVariable"></param> /// <returns></returns> public IEnumerable <string> IncludeFiles(IDeclaredParameter iVariable) { yield return("<fstream>"); yield return("TH1D.h"); yield return("TSystem.h"); }
/// <summary> /// Helper to create an assignment to a constant. /// </summary> /// <returns></returns> Tuple<IDeclaredParameter, IStatement> CreateConstAssignStatement(IDeclaredParameter p1 = null) { if (p1 == null) { p1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)); } IStatement s1 = new StatementAssign(p1, new ValSimple("5", typeof(int))); return Tuple.Create(p1, s1); }
Tuple<IDeclaredParameter, IStatement> CreateAssignStatement(IValue valToAssign, IDeclaredParameter p1 = null) { if (p1 == null) { p1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)); } IStatement s1 = new StatementAssign(p1, valToAssign); return Tuple.Create(p1, s1); }
/// <summary> /// We can deal with things like integers. /// </summary> /// <param name="iVariable"></param> /// <returns></returns> public bool CanHandle(IDeclaredParameter iVariable) { if (_types.ContainsKey(iVariable.Type)) { return(true); } return(false); }
/// <summary> /// Create a statement that will increment this integer. /// </summary> /// <param name="i"></param> public StatementIncrementInteger(IDeclaredParameter i) { if (i == null) throw new ArgumentNullException("The statement can't increment a null integer"); if (i.Type != typeof(int)) throw new ArgumentException("parameter i must be an integer"); Integer = i; }
/// <summary> /// When we are in a result operator and the result of its work needs to be visible "outside" we need /// to make sure the declaration happens at the right spot. That is what this guy does. /// </summary> /// <param name="p"></param> public void AddAtResultScope(IDeclaredParameter p) { if (CurrentResultScope == null) { throw new InvalidOperationException("Unable to add a parameter at the result scope - none is set"); } CurrentResultScope.Add(p); }
/// <summary> /// The lines of code that can be used to save this guy to a file. This is actually quite easy /// - we just book it! /// </summary> /// <param name="iVariable"></param> /// <returns></returns> public IEnumerable <string> SaveToFile(IDeclaredParameter iVariable) { StringBuilder bld = new StringBuilder(); bld.AppendFormat("{0}->SetName(\"{0}\");", iVariable.RawValue); yield return(bld.ToString()); yield return("Book(" + iVariable.RawValue + ");"); }
/// <summary> /// Helper to create an assignment to a constant. /// </summary> /// <returns></returns> Tuple <IDeclaredParameter, IStatement> CreateConstAssignStatement(IDeclaredParameter p1 = null) { if (p1 == null) { p1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)); } IStatement s1 = new StatementAssign(p1, new ValSimple("5", typeof(int))); return(Tuple.Create(p1, s1)); }
public StatementIfOnCount Constructor( IDeclaredParameter valueLeft, IValue valueRight, StatementIfOnCount.ComparisonOperator comp ) { StatementIfOnCount target = new StatementIfOnCount(valueLeft, valueRight, comp); return target; // TODO: add assertions to method StatementIfOnCountTest.Constructor(IValue, IValue, ComparisonOperator) }
/// <summary> /// Save sequence variables. Only valid if this guy is a sequence. /// </summary> /// <param name="loopIndexVariable"></param> /// <param name="loopExpression"></param> public void SequenceVariable(IDeclaredParameter loopIndexVariable, Expression loopExpression) { if (!IsSequence) { throw new InvalidOperationException("Can't stash sequence info in a non-sequence QM!"); } OldLoopExpression = loopExpression; OldLoopIndexVariable = loopIndexVariable; }
/// <summary> /// Create a statement that will record this index into this array each time through. /// </summary> /// <param name="intToRecord">Integer that should be cached on each time through</param> /// <param name="storageArray">The array where the indicies should be written</param> public StatementRecordIndicies(IValue intToRecord, IDeclaredParameter storageArray) { if (intToRecord == null) throw new ArgumentNullException("intToRecord"); if (storageArray == null) throw new ArgumentNullException("storageArray"); _intToRecord = intToRecord; _storageArray = storageArray; }
public StatementIfOnCount Constructor( IDeclaredParameter valueLeft, IValue valueRight, StatementIfOnCount.ComparisonOperator comp ) { StatementIfOnCount target = new StatementIfOnCount(valueLeft, valueRight, comp); return(target); // TODO: add assertions to method StatementIfOnCountTest.Constructor(IValue, IValue, ComparisonOperator) }
/// <summary> /// Set the loop variable to a new value /// </summary> /// <param name="loopExpression">Evaluate to the current value, looping over whatever we are looping over</param> /// <param name="indexVariable">The current index - this is what we are walking through right now. Null if this index variable makes no sense.</param> public void SetLoopVariable(Expression loopExpression, IDeclaredParameter indexVariable) { if (loopExpression == null) { throw new ArgumentNullException("can not set a null loop variable"); } Debug.WriteLine("SetLoopVariable: Index changing from {0} => {1}", LoopIndexVariable == null ? "null" : LoopIndexVariable.ToString(), indexVariable == null ? "null" : indexVariable.ToString()); LoopVariable = loopExpression; LoopIndexVariable = indexVariable; }
public StatementForLoop TestCTor(IDeclaredParameter loopVarName, IValue ivalSize, IValue initialValue) { var p = new StatementForLoop(loopVarName, ivalSize, initialValue); Assert.AreEqual(typeof(int), ivalSize.Type, "size value"); if (initialValue != null) Assert.AreEqual(typeof(int), initialValue.Type, "inital value type"); Assert.AreEqual(p.ArrayLength.RawValue, ivalSize.RawValue, "Initial value must be set"); return p; }
/// <summary> /// Generate the code that will save this guy to a file. /// </summary> /// <param name="iVariable"></param> /// <returns></returns> public IEnumerable <string> SaveToFile(IDeclaredParameter iVariable) { var tn = _types[iVariable.Type]._htype; yield return(string.Format("{0} *{1}_hist = new {0}(\"{1}\", \"var transport\", 1, 0.0, 1.0);", tn, iVariable.RawValue)); yield return(iVariable.RawValue + "_hist->SetDirectory(0);"); yield return(iVariable.RawValue + "_hist->SetBinContent(1, " + iVariable.RawValue + ");"); yield return("Book(" + iVariable.RawValue + "_hist);"); }
public StatementAssign(IDeclaredParameter result, IValue val) { if (result == null) throw new ArgumentNullException("Accumulator must not be zero"); if (val == null) throw new ArgumentNullException("funcResolved must not be null"); ResultVariable = result; Expression = val; ResultVariables = new HashSet<string>() { result.RawValue }; DependentVariables = new HashSet<string>(val.Dependants.Select(v => v.RawValue)); }
/// <summary> /// Return a parameter as an expression. /// </summary> /// <param name="param"></param> /// <returns></returns> public static Expression AsExpression(this IDeclaredParameter param) { // Some of the expressions are already parameters, so... var e = param as Expression; if (e != null) { return(e); } return(Expression.Parameter(param.Type, param.RawValue)); }
/// <summary> /// Simple loop over a set of indicies, passing on only those that satisfy the actual index. /// </summary> /// <param name="indiciesToCheck"></param> /// <param name="indexIsGood"></param> /// <param name="index"></param> public StatementLoopOverGood(IValue indiciesToCheck, IValue indexIsGood, IDeclaredParameter index) { if (indiciesToCheck == null) throw new ArgumentNullException("indiciesToCheck"); if (indexIsGood == null) throw new ArgumentNullException("indexIsGood"); if (index == null) throw new ArgumentNullException("index"); _indiciesToCheck = indiciesToCheck; _indexIsGood = indexIsGood; _index = index; }
/// <summary> /// We need to load the variable saver back in. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="iVariable"></param> /// <param name="obj"></param> /// <returns></returns> public Task <T> LoadResult <T>(IDeclaredParameter iVariable, RunInfo[] obj) { var h = obj[0]._result as ROOTNET.NTH1; if (h == null) { throw new InvalidOperationException("Object of type '" + h.ClassName() + "' is not an integer histogram, which is what we were expecting for this result!"); } object result = _types[iVariable.Type]._converter(h); return(Task.FromResult((T)result)); }
/// <summary> /// Create a statement that will increment this integer. /// </summary> /// <param name="i"></param> public StatementIncrementInteger(IDeclaredParameter i) { if (i == null) { throw new ArgumentNullException("The statement can't increment a null integer"); } if (i.Type != typeof(int)) { throw new ArgumentException("parameter i must be an integer"); } Integer = i; }
/// <summary> /// Look at predicate. Set result to the marked value when the predicate fires, and also pop out of the /// current loop. /// </summary> /// <param name="predicate">The test that needs to be done. Null if it is "any" test</param> /// <param name="aresult">The result that should be altered, and tested against.</param> /// <param name="aresultFastTest">A text expression we can use to short-circuit the predicate if it has already gone.</param> /// <param name="markedValue">How we should set the result when the if statement fires</param> /// <param name="addBreak">Add a break statement to terminate loop early - this is dangerous as when loops are combined...</param> /// <remarks> /// We keep the aresultFastTest separate so that we can make sure try-combine works properly when we have two /// identical guys. /// </remarks> public StatementAnyAllDetector(IValue predicate, IDeclaredParameter aresult, IValue aresultFastTest, string markedValue) { if (aresultFastTest == null) throw new ArgumentNullException("aresultFastTest"); if (aresult == null) throw new ArgumentNullException("aresult"); if (markedValue == null) throw new ArgumentNullException("markedValue"); Predicate = predicate; Result = aresult; ResultValueToBe = markedValue; ResultFastTest = aresultFastTest; }
public StatementForLoop TestCTor(IDeclaredParameter loopVarName, IValue ivalSize, IValue initialValue) { var p = new StatementForLoop(loopVarName, ivalSize, initialValue); Assert.AreEqual(typeof(int), ivalSize.Type, "size value"); if (initialValue != null) { Assert.AreEqual(typeof(int), initialValue.Type, "inital value type"); } Assert.AreEqual(p.ArrayLength.RawValue, ivalSize.RawValue, "Initial value must be set"); return(p); }
public StatementPairLoop(IDeclaredParameter arrayRecord, IDeclaredParameter index1, IDeclaredParameter index2) { if (arrayRecord == null) throw new ArgumentNullException("arrayRecord"); if (index1 == null) throw new ArgumentNullException("index1"); if (index2 == null) throw new ArgumentNullException("index2"); // TODO: Complete member initialization this.arrayRecord = arrayRecord; this.index1 = index1; this.index2 = index2; }
/// <summary> /// Add a variable one level up from the current scope. Fail if we can't! /// </summary> /// <param name="valSimple"></param> public void AddOneLevelUp(IDeclaredParameter valSimple) { if (valSimple == null) { throw new ArgumentNullException("cannot add null variable!"); } if (PreviousDeclarationScopePointer == null) { throw new InvalidOperationException("Can't declare one variable one level up when one level up doesn't exist!"); } PreviousDeclarationScopePointer.Add(valSimple); }
#pragma warning restore 0649 /// <summary> /// Find a saver for a particular variable. /// </summary> /// <param name="iVariable"></param> /// <returns></returns> public IVariableSaver Get(IDeclaredParameter iVariable) { if (iVariable == null) throw new ArgumentNullException("iVariable can't be null"); if (_varSaverList == null) throw new InvalidOperationException("The list of variable saver objects is null - was MEF correctly initalized!?"); var saver = (from s in _varSaverList where s.CanHandle(iVariable) select s).FirstOrDefault(); if (saver == null) throw new InvalidOperationException("Unable to find an IVariableSaver for " + iVariable.Type.Name); return saver; }
/// <summary> /// Create the statement block /// </summary> /// <param name="indexSeen"></param> /// <param name="indexValue"></param> /// <param name="valueWasSeen"></param> /// <param name="recordOnlyFirstValue"></param> public StatementRecordValue(IDeclaredParameter indexSaveLocation, IValue indexExpression, IDeclaredParameter markWhenSeen, bool recordOnlyFirstValue) { if (indexSaveLocation == null) throw new ArgumentNullException("_indexSeen"); if (indexExpression == null) throw new ArgumentNullException("indexExpression"); if (markWhenSeen == null) throw new ArgumentNullException("markWhenSeen"); AddNewSaver(indexSaveLocation, indexExpression); this._recordOnlyFirstValue = recordOnlyFirstValue; this._valueWasSeen = markWhenSeen; }
/// <summary> /// Create code block for a test /// </summary> /// <param name="vIsFilled"></param> /// <param name="vMaxMin"></param> /// <param name="exprToMinOrMaximize"></param> public StatementMinMaxTest(IDeclaredParameter vIsFilled, IDeclaredParameter vMaxMin, IValue exprToMinOrMaximize, bool doMax) { this.vIsFilled = vIsFilled; this.MaxMinVariable = vMaxMin; this.exprToMinOrMaximize = exprToMinOrMaximize; if (doMax) { CompareOperator = ">"; } else { CompareOperator = "<"; } TempVariable = DeclarableParameter.CreateDeclarableParameterExpression(vMaxMin.Type); }
/// <summary> /// Create with value1 comp value2 - if that is true, then we will execute our /// inner statements and declarations. /// </summary> /// <param name="counter"></param> /// <param name="IValue"></param> public StatementIfOnCount(IDeclaredParameter counter, IValue limit, ComparisonOperator comp) { /// /// Make sure that nothing is crazy here! /// if (counter == null) throw new ArgumentNullException("Can't have a left hand value that is null"); if (limit == null) throw new ArgumentNullException("Cant have a right hand value that is null!"); /// /// Remember! /// Counter = counter; Limit = limit; Comparison = comp; }
/// <summary> /// Loop over all the indicies we are given (sort of like an indirect) in a double loop. For each one /// make sure that they satisfy the function. if we find any failing, mark both as bad. You must set /// the TEST variable, but do it after this guy is part of the generated code - scoping must be tracked /// correctly!! /// </summary> /// <param name="indiciesToInspect">The list of indicies we should set index1 and index2 to</param> /// <param name="index1">The name we should use for index 1</param> /// <param name="index2">the name we should use for index 2</param> /// <param name="passedArray">The initially empty bool vector that we will mark any index that satisfies everything as true</param> public StatementCheckLoopPairwise(IDeclaredParameter indiciesToInspect, IDeclaredParameter index1, IDeclaredParameter index2, IDeclaredParameter passedArray) { if (indiciesToInspect == null) throw new ArgumentNullException("indiciesToInspect"); if (index1 == null) throw new ArgumentNullException("index1"); if (index2 == null) throw new ArgumentNullException("index2"); if (passedArray == null) throw new ArgumentNullException("passedArray"); if (passedArray.Type == null) throw new ArgumentNullException("Passed array type should not be null"); if (!passedArray.Type.IsArray) throw new ArgumentException("passedArray isn't an array type"); _indciesToInspect = indiciesToInspect; _index1 = index1; _index2 = index2; _whatIsGood = passedArray; }
/// <summary> /// Save how we are going to go after the statement and generate it. /// </summary> /// <param name="mapStorage">We own this variable - we can change its name</param> /// <param name="indexVar"></param> /// <param name="indexValue"></param> public StatementRecordPairValues(IDeclaredParameter mapStorage, IValue indexVar, IValue indexValue) { // // Input checks. // if (mapStorage == null) throw new ArgumentNullException("mapStorage"); if (indexVar == null) throw new ArgumentNullException("indexVar"); if (indexValue == null) throw new ArgumentNullException("indexValue"); // // Save for later // this._index = indexVar; AddSaver(mapStorage, indexValue); Debug.WriteLine("Emit StatementRecordPairValues: IndexVar {0}, indexValue {1}", indexVar.ToString(), indexValue.ToString()); }
/// <summary> /// Find all used query variables that sit above us and have been currently being referenced. /// </summary> /// <param name="gc"></param> /// <param name="cc"></param> /// <param name="alreadySeen"></param> /// <param name="startStatement">The first statement to start our scan from</param> public static IEnumerable<IDeclaredParameter> GetUsedQuerySourceVariables(this IGeneratedQueryCode gc, IStatement startStatement, IDeclaredParameter alreadySeen = null) { var scope = startStatement as IStatement; HashSet<string> whatWeSaw = new HashSet<string>(); if (alreadySeen != null) whatWeSaw.Add(alreadySeen.RawValue); while (scope != gc.CurrentResultScope) { if (scope is IStatementLoop) { var ls = scope as IStatementLoop; foreach (var loopIndexVar in ls.LoopIndexVariable) { if (!whatWeSaw.Contains(loopIndexVar.RawValue)) { yield return loopIndexVar; whatWeSaw.Add(loopIndexVar.RawValue); } } } scope = scope.Parent; } }
public bool TryRenameVarialbeOneLevelUp(string oldName, IDeclaredParameter newVariable) { s2.RenameVariable(oldName, newVariable.ParameterName); return true; }
public void TestStatementCheckLoopPairwiseConstructor(IDeclaredParameter indiciesToInspect, IDeclaredParameter index1, IDeclaredParameter index2, IDeclaredParameter passedArray) { StatementCheckLoopPairwise target = new StatementCheckLoopPairwise(indiciesToInspect, index1, index2, passedArray); }
/// <summary> /// Add to the list of variables that are to be recorded. /// </summary> /// <param name="saver"></param> /// <param name="loopIndexVar"></param> public void AddNewSaver(IDeclaredParameter saver, IValue loopIndexVar) { _savers.Add(Tuple.Create(saver, loopIndexVar)); }
/// <summary> /// Add a result. Very bad if it isn't unique. /// </summary> /// <param name="var"></param> public void AddResult(IDeclaredParameter var) { if (var == null) throw new ArgumentNullException("Can't add a null result"); var sameV = from v in _results where v.ParameterName == var.ParameterName select v; if (sameV.Any()) throw new ArgumentException(string.Format("Attempt to add duplicate result named '{0}' to a combined code.", var.ParameterName)); _results.Add(var); }
/// <summary> /// Create a loop pair wise test. /// </summary> /// <param name="passAll"></param> /// <param name="iValue"></param> public StatementTestLoopPairwise(IDeclaredParameter passAll, IValue iValue) { this._whatIsGood = passAll; this._test = iValue; }
public bool TryRenameVarialbeOneLevelUp(string oldName, IDeclaredParameter newVariable) { Renames.Add(oldName); return true; }
internal StatementPairLoop StatementPairLoopCtor(IDeclaredParameter varArray, IDeclaredParameter index1, IDeclaredParameter index2) { var target = new StatementPairLoop(varArray, index1, index2); return target; }
public StatementIncrementInteger Constructor(IDeclaredParameter i) { StatementIncrementInteger target = new StatementIncrementInteger(i); Assert.AreEqual(i, target.Integer, "initial value not set correctly"); return null; }
public bool TryRenameVarialbeOneLevelUp(string oldName, IDeclaredParameter newVariable) { throw new NotImplementedException(); }
public CombineSameStatement(IDeclaredParameter vdecl2) { // TODO: Complete member initialization this.vdecl2 = vdecl2; }