public void SwitchStatementProducesSwitch() { var statement1 = JS.Switch(JS.Id("a")) .Case("a").Do(JS.Return("a")); Assert.AreEqual("switch(a){case \"a\":return \"a\";}", statement1.ToString()); var statement2 = JS.Switch(JS.Id("b")) .Case(1).Do(JS.Return(100)) .Case(2).Case(3).Do(JS.Return(200)) .Case(4, 5, 6).Do(new List<Statement> { JS.Alert("Not Done!"), JS.Break() }) .Case(Enumerable.Range(7, 4).Select(i => (Expression) JS.Number(i))).Do( JS.Alert(JS.Id("a")), JS.Break()) .Default().Do(JS.Break()); statement2.Cases.Add(null); Assert.AreEqual( "switch(b){case 1:return 100;case 2:case 3:return 200;" + "case 4:case 5:case 6:alert(\"Not Done!\");break;" + "case 7:case 8:case 9:case 10:alert(a);break;default:break;}", statement2.ToString()); CaseStatement test = new CaseStatement(3); test.Value = 4; test.Statements.Add(JS.Break()); var cases = new List<CaseStatement> { new CaseStatement(1, JS.Break()), new CaseStatement(2, new List<Statement> { JS.Break() }), test }; var statement3 = new SwitchStatement(JS.Id("c"), cases); Assert.AreEqual("switch(c){case 1:break;case 2:break;case 4:break;}", statement3.ToString()); }
public void AcceptCase(CaseStatement stmt) { }
private void GenerateCaseStatements( IEnumerable <MemberPath> members, HashSet <FragmentQuery> outputUsedViews) { CellTreeNode rightDomainQuery = (CellTreeNode) new OpCellTreeNode(this._context, CellTreeOpType.Union, (CellTreeNode[])this._context.AllWrappersForExtent.Where <LeftCellWrapper>((Func <LeftCellWrapper, bool>)(w => this._usedViews.Contains(w.FragmentQuery))).Select <LeftCellWrapper, LeafCellTreeNode>((Func <LeftCellWrapper, LeafCellTreeNode>)(wrapper => new LeafCellTreeNode(this._context, wrapper))).ToArray <LeafCellTreeNode>()); foreach (MemberPath member in members) { List <Constant> list = this.GetDomain(member).ToList <Constant>(); CaseStatement caseStatement = new CaseStatement(member); Tile <FragmentQuery> tile = (Tile <FragmentQuery>)null; bool flag = list.Count != 2 || !list.Contains <Constant>(Constant.Null, Constant.EqualityComparer) || !list.Contains <Constant>(Constant.NotNull, Constant.EqualityComparer); foreach (Constant domainValue in list) { if (domainValue == Constant.Undefined && this._context.ViewTarget == ViewTarget.QueryView) { caseStatement.AddWhenThen(BoolExpression.False, (ProjectedSlot) new ConstantProjectedSlot(Constant.Undefined)); } else { FragmentQuery memberConditionQuery = this.CreateMemberConditionQuery(member, domainValue); Tile <FragmentQuery> rewriting; if (this.FindRewritingAndUsedViews((IEnumerable <MemberPath>)memberConditionQuery.Attributes, memberConditionQuery.Condition, outputUsedViews, out rewriting)) { if (this._context.ViewTarget == ViewTarget.UpdateView) { tile = tile != null?this._qp.Union(tile, rewriting) : rewriting; } if (flag) { if (this.AddRewritingToCaseStatement(rewriting, caseStatement, member, domainValue)) { break; } } } else if (!QueryRewriter.IsDefaultValue(domainValue, member) && !ErrorPatternMatcher.FindMappingErrors(this._context, this._domainMap, this._errorLog)) { StringBuilder builder = new StringBuilder(); string str1 = StringUtil.FormatInvariant("{0}", (object)this._extentPath); string str2 = this._context.ViewTarget == ViewTarget.QueryView ? Strings.ViewGen_Entities : Strings.ViewGen_Tuples; if (this._context.ViewTarget == ViewTarget.QueryView) { builder.AppendLine(Strings.Viewgen_CannotGenerateQueryViewUnderNoValidation((object)str1)); } else { builder.AppendLine(Strings.ViewGen_Cannot_Disambiguate_MultiConstant((object)str2, (object)str1)); } RewritingValidator.EntityConfigurationToUserString(memberConditionQuery.Condition, builder, this._context.ViewTarget == ViewTarget.UpdateView); this._errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.AmbiguousMultiConstants, builder.ToString(), (IEnumerable <LeftCellWrapper>) this._context.AllWrappersForExtent, string.Empty)); } } } if (this._errorLog.Count == 0) { if (this._context.ViewTarget == ViewTarget.UpdateView && flag) { this.AddElseDefaultToCaseStatement(member, caseStatement, list, rightDomainQuery, tile); } if (caseStatement.Clauses.Count > 0) { this._caseStatements[member] = caseStatement; } } } }
public static CaseStatement Read (XmlReader reader) { CaseStatement result = new CaseStatement (); if (reader.MoveToFirstAttribute ()) { do { result.SetAttribute (reader.LocalName, reader.Value); } while (reader.MoveToNextAttribute ()); } result.Children = Node.ReadNodeList (reader, XmlTag); return result; }
protected override Statement ExpandImpl(MacroStatement @case) { CaseStatement statement; if (@case == null) { throw new ArgumentNullException("case"); } this.__macro = @case; CaseStatement statement1 = statement = new CaseStatement(); ExpressionCollection collection1 = statement.Expressions = @case.get_Arguments(); Block block1 = statement.Body = @case.get_Body(); return statement; }
public void AcceptCase(CaseStatement stmt) { foreach (Statement branch in stmt.Branches) branch.Accept(this); }
public void AcceptCase(CaseStatement stmt) { Result = stmt; }
public void AcceptCase(CaseStatement stmt) { List<Statement> result = new List<Statement>(); foreach (Statement branch in stmt.Branches) { Statement abranch = branch.GetInnermostAtomicStatement(); if (abranch != null) result.Add(abranch); } Statement succ = GetAtomicSuccessor(stmt); if (succ != null) result.Add(succ); Result = result; }
/// <summary> /// Returns an array of size <see cref="TotalSlots"/> which indicates the slots that are needed to constuct value at <paramref name="caseMemberPath"/>, /// e.g., CPerson may need pid and name (say slots 2 and 5 - then bools[2] and bools[5] will be true. /// </summary> /// <param name="caseMemberPath">must be part of <see cref="m_caseStatements"/></param> private void GetRequiredSlotsForCaseMember(MemberPath caseMemberPath, bool[] requiredSlots) { Debug.Assert(true == m_caseStatements.ContainsKey(caseMemberPath), "Constructing case for regular field?"); Debug.Assert(requiredSlots.Length == TotalSlots, "Invalid array size for populating required slots"); CaseStatement statement = m_caseStatements[caseMemberPath]; // Find the required slots from the when then clause conditions // and values bool requireThisSlot = false; foreach (CaseStatement.WhenThen clause in statement.Clauses) { clause.Condition.GetRequiredSlots(m_projectedSlotMap, requiredSlots); ProjectedSlot slot = clause.Value; if (!(slot is ConstantProjectedSlot)) { // If this slot is a scalar and a non-constant, // we need the lower down blocks to generate it for us requireThisSlot = true; } } EdmType edmType = caseMemberPath.EdmType; if (Helper.IsEntityType(edmType) || Helper.IsComplexType(edmType)) { foreach (EdmType instantiatedType in statement.InstantiatedTypes) { foreach (EdmMember childMember in Helper.GetAllStructuralMembers(instantiatedType)) { int slotNum = GetSlotIndex(caseMemberPath, childMember); requiredSlots[slotNum] = true; } } } else if (caseMemberPath.IsScalarType()) { // A scalar does not need anything per se to be constructed // unless it is referring to a field in the tree below, i.e., the THEN // slot is not a constant slot if (requireThisSlot) { int caseMemberSlotNum = m_projectedSlotMap.IndexOf(caseMemberPath); requiredSlots[caseMemberSlotNum] = true; } } else if (Helper.IsAssociationType(edmType)) { // For an association, get the indices of the ends, e.g., // CProduct and CCategory in CProductCategory1 // Need just it's ends AssociationSet associationSet = (AssociationSet)caseMemberPath.Extent; AssociationType associationType = associationSet.ElementType; foreach (AssociationEndMember endMember in associationType.AssociationEndMembers) { int slotNum = GetSlotIndex(caseMemberPath, endMember); requiredSlots[slotNum] = true; } } else { // For a reference, all we need are the keys RefType refType = edmType as RefType; Debug.Assert(refType != null, "What other non scalars do we have? Relation end must be a reference type"); EntityTypeBase refElementType = refType.ElementType; // Go through all the members of elementType and get the key properties EntitySet entitySet = MetadataHelper.GetEntitySetAtEnd((AssociationSet)caseMemberPath.Extent, (AssociationEndMember)caseMemberPath.LeafEdmMember); foreach (EdmMember entityMember in refElementType.KeyMembers) { int slotNum = GetSlotIndex(caseMemberPath, entityMember); requiredSlots[slotNum] = true; } } }
/// <summary> /// Given the <paramref name="viewBlock"/> tree generated by the cell merging process and the <paramref name="parentRequiredSlots"/>, /// generates the block tree for the case statement at or past the startSlotNum, i.e., only for case statements that are beyond startSlotNum. /// </summary> private CqlBlock ConstructCaseBlocks(CqlBlock viewBlock, int startSlotNum, bool[] parentRequiredSlots, IEnumerable <WithRelationship> withRelationships) { int numMembers = m_projectedSlotMap.Count; // Find the next slot for which we have a case statement, i.e., // which was in the multiconstants int foundSlot = FindNextCaseStatementSlot(startSlotNum, parentRequiredSlots, numMembers); if (foundSlot == -1) { // We have bottomed out - no more slots to generate cases for // Just get the base view block return(viewBlock); } // Compute the requiredSlots for this member, i.e., what slots are needed to produce this member. MemberPath thisMember = m_projectedSlotMap[foundSlot]; bool[] thisRequiredSlots = new bool[TotalSlots]; GetRequiredSlotsForCaseMember(thisMember, thisRequiredSlots); Debug.Assert(thisRequiredSlots.Length == parentRequiredSlots.Length && thisRequiredSlots.Length == TotalSlots, "Number of slots in array should not vary across blocks"); // Merge parent's requirements with this requirements for (int i = 0; i < TotalSlots; i++) { // We do ask the children to generate the slot that we are // producing if it is available if (parentRequiredSlots[i]) { thisRequiredSlots[i] = true; } } // If current case statement depends on its slot value, then make sure the value is produced by the child block. CaseStatement thisCaseStatement = m_caseStatements[thisMember]; thisRequiredSlots[foundSlot] = thisCaseStatement.DependsOnMemberValue; // Recursively, determine the block tree for slots beyond foundSlot. CqlBlock childBlock = ConstructCaseBlocks(viewBlock, foundSlot + 1, thisRequiredSlots, null); // For each slot, create a SlotInfo object SlotInfo[] slotInfos = CreateSlotInfosForCaseStatement(parentRequiredSlots, foundSlot, childBlock, thisCaseStatement, withRelationships); m_currentBlockNum++; // We have a where clause only at the top level BoolExpression whereClause = startSlotNum == 0 ? m_topLevelWhereClause : BoolExpression.True; if (startSlotNum == 0) { // only slot #0 is required by parent; reset all 'required by parent' booleans introduced above for (int i = 1; i < slotInfos.Length; i++) { slotInfos[i].ResetIsRequiredByParent(); } } CaseCqlBlock result = new CaseCqlBlock(slotInfos, foundSlot, childBlock, whereClause, m_identifiers, m_currentBlockNum); return(result); }
public void AcceptCase(CaseStatement stmt) { stmt.Branches.Accept(this); }
protected abstract void VisitCase(CaseStatement statement);
public virtual void VisitCaseStatement(CaseStatement caseStatement) { DefaultVisit(caseStatement); }
public void AcceptCase(CaseStatement stmt) { SimpleResult(stmt); }
/// <summary> /// Transforms a "case" statement. The default implementation clones that statement. /// </summary> /// <param name="stmt">"case" statement</param> public virtual void AcceptCase(CaseStatement stmt) { var caseStmt = Switch(stmt.Selector.Transform(this)); _caseMap[stmt] = caseStmt; { for (int i = 0; i < stmt.Cases.Count; i++) { Case(stmt.Cases[i].Transform(this)); { stmt.Branches[i].Accept(this); } EndCase(); } } if (stmt.Branches.Count > stmt.Cases.Count) { DefaultCase(); { stmt.Branches.Last().Accept(this); } EndCase(); } EndSwitch(); CopyAttributesToLastStatement(stmt); }
public void AcceptCase(CaseStatement stmt) { Switch(stmt.Selector); { for (int i = 0; i < stmt.Cases.Count; i++) { Case(stmt.Cases[i]); { stmt.Branches[i].Accept(this); } EndCase(); } } if (stmt.Branches.Count > stmt.Cases.Count) { DefaultCase(); { stmt.Branches.Last().Accept(this); } EndCase(); } EndSwitch(); }
public void AcceptCase(CaseStatement stmt) { IsEmpty = false; }
protected override void DeclareAlgorithm() { Dissect(); Initialize(); InitializeCoFSMs(); DecompileStates(); CreateStateValues(); CreateCoStateValues(); SignalRef curState = new SignalRef(_stateSignal.Desc, SignalRef.EReferencedProperty.Cur); ProcessDescriptor pd = (ProcessDescriptor)_code; Func <bool> predFunc = pd.Instance.Predicate; LiteralReference predInstRef = LiteralReference.CreateConstant(predFunc.Target); StackElement arg = new StackElement(predInstRef, predFunc.Target, EVariability.ExternVariable); Expression cond = _templ.GetCallExpression(predFunc.Method, arg).Expr; Expression[] e0 = new Expression[0]; Variable[] v0 = new Variable[0]; If(cond); { foreach (var kvp in _coFSMs) { CoFSMInfo cfi = kvp.Value; SignalRef srCor = new SignalRef(cfi.CoStateSignal.Desc, SignalRef.EReferencedProperty.Cur); Expression lrCo = new LiteralReference(srCor); CaseStatement csc = Switch(lrCo); { for (int i = 0; i < cfi.TotalStates; i++) { CoStateInfo csi = cfi.StateInfos[i]; Expression stateValue = LiteralReference.CreateConstant(csi.StateValue); CoStateInfo csin = csi.Next; if (csin == null && cfi.HasNeutralTA) { csin = cfi.FirstNeutral; } Case(stateValue); { if (csin != null) { ImplementCoStateAction(cfi, csin, this); } Break(csc); } EndCase(); } } EndSwitch(); } CaseStatement cs = Switch(curState); { IEnumerable <StateInfo> states = _stateLookup.Values.OrderBy(si => si.StateIndex); foreach (StateInfo state in states) { Case(state.StateExpr.PlaceHolder); { InlineCall(state.StateFun, e0, v0, true); Break(cs); } EndCase(); } } EndSwitch(); } EndIf(); }
public void AcceptCase(CaseStatement stmt) { _result.Add(stmt); stmt.Branches.Accept(this); }
static void Main(string[] args) { //bool dummyInput = true; // Made to pass into bool to method //GetSet obj = new GetSet(); //Console.WriteLine($"{obj.OutputOne(7)}"); //Console.WriteLine($"{obj.One}"); Typing dicy = new Typing(); bool isItThere = dicy.pair.ContainsKey(0); bool isKd = dicy.pair.ContainsValue("KD"); dicy.pair.Add(9, "Cook"); if (!dicy.pair.ContainsKey(10)) { dicy.pair[11] = "my man"; } bool isEleven = dicy.pair.ContainsKey(11); Console.WriteLine(isItThere + " Mother f****r"); Console.WriteLine(isKd + " KD"); Console.WriteLine(isEleven + " 11"); Console.WriteLine(dicy.pair[11]); // Outputting the contents of a loop. int addKeys = 0; string conValue = ""; foreach (KeyValuePair <int, string> KV in dicy.pair) { addKeys += KV.Key; conValue += KV.Value; Console.WriteLine(KV.Key + " " + KV.Value); } Console.WriteLine("Key Total equals " + addKeys); Console.WriteLine("Value Total equals " + conValue); TryCatch.TryCatchWhile(); // This is the while loop on try catch. //BoolToMethod.BoolSubtract(dummyInput); TryCatch tcobject = new TryCatch(); tcobject.TryAndCatchDoWhile(); TryCatch.TryAndCatch(); Adder mathOne = new Adder("John", 41); Adder mathTwo = new Adder("Carl", 31); Subtractor minus = new Subtractor("Jenny", 53); Dictionary <int, string> Mydics = new Dictionary <int, string>(); Mydics.Add(1, "One"); Mydics.Add(2, "Two"); Mydics.Add(3, "Three"); Mydics.Add(4, "Four"); Mydics.Add(5, "Five"); Mydics.Add(6, "Six"); Mydics.Add(7, "Seven"); foreach (KeyValuePair <int, string> dic in Mydics) { switch (dic.Key) // have to use dic.key or dic.value { case 1: Console.WriteLine("first level"); break; case 2: case 3: case 4: case 5: Console.WriteLine("second level"); break; case 6: Console.WriteLine("third level"); break; case 7: Console.WriteLine("fourth level"); break; } } foreach (KeyValuePair <int, string> mic in Mydics) { switch (mic.Value) // have to use dic.key or dic.value { case "One": Console.WriteLine("first"); break; case "Two": case "Three": case "Four": case "Five": Console.WriteLine("second"); break; case "Six": Console.WriteLine("third"); break; case "Seven": Console.WriteLine("fourth"); break; } } Console.WriteLine("Enter a Name: "); string enteredName = Console.ReadLine(); Console.WriteLine("Enter one, two, three, or four for the dictionary: "); string getvar = Console.ReadLine(); Console.WriteLine("Enter 9,8,7,6 For your int to string output "); int num = int.Parse(Console.ReadLine()); CaseStatement.Cae('D'); // working with dictionaries // Make a method out of this Console.WriteLine(mathOne.GetName()); Console.WriteLine($"WIll it still print the name?: {mathTwo.GetName()}"); Console.WriteLine(mathOne.ChangeName("Bill")); Console.WriteLine(mathOne.ChangeName(enteredName)); //Overload Method Console.WriteLine("Overload Method. Want to put the methods in there own class. OO classes also really helps with nameing conlisions. "); Console.WriteLine(minus.Subtract()); Console.WriteLine(minus.Subtract(53)); Console.WriteLine(minus.Subtract(53, 25)); Console.WriteLine($" mathtwo is {mathTwo.AddAge(4)} years old"); Console.WriteLine($" mathtwo is {mathTwo.SecondLevelAgeAdder(4, "Larry")} years old, and name is {mathTwo.GetName()}"); Console.WriteLine($"{mathTwo.ChangeName("Paul")}"); Console.WriteLine($" The new name is {mathOne.GetName()}"); Console.WriteLine($" mathtwo is {mathTwo.SecondLevelAgeAdder(4, "Pearl")} years old, and name is {mathTwo.GetName()}"); TowObjInteractAdderSubtract.TwoClasses(mathOne, minus); Console.WriteLine($"{mathOne.Name}, {minus.Age}"); PracDict.Dicswitch(getvar); PracDict.IntStringTester(num); // working with dictionaries Console.ReadKey(); }
public override void AcceptCase(CaseStatement stmt) { Success = false; }
public bool VisitNode(CaseStatement node) { throw new NotImplementedException(); }
public void GotoCase(CaseStatement cstmt, int index) { throw new NotSupportedException(); }
public virtual void Visit(CaseStatement node) { DefaultVisit(node); }
public void Break(CaseStatement stmt) { throw new NotSupportedException(); }
public void AcceptCase(CaseStatement stmt) { Check(stmt); stmt.Branches.Accept(this); }
public virtual Statement visit(CaseStatement statement) { return(visit((Statement)statement)); }