public bool containsLiteral(SwitchCaseExpression sce) { if (sce is DefaultExpression) { return(false); } CaseExpression caseExp = (CaseExpression)sce; switch (caseExp.literal.value.type) { case Token.TokenValue.STRING: if (stringCases == null) { return(false); } return(stringCases.Contains(caseExp.literal.value.stringValue)); case Token.TokenValue.INT: if (intCases == null) { return(false); } return(intCases.Contains(caseExp.literal.value.intValue)); } return(true); }
public object Visit(SwitchCaseExpression node) { if (node.Body != null) { Visit(node.Body); } return(null); }
public void addCase(SwitchCaseExpression ce) { if (cases == null) { cases = new List<SwitchCaseExpression>(); } cases.Add(ce); if (ce is DefaultExpression) { hasDefaultCase = true; return; } if (ce is CaseExpression) { SwitchCaseExpression tmp = ce; while (tmp != null) { if (tmp is DefaultExpression) { hasDefaultCase = true; return; } else { CaseExpression caseExp = (CaseExpression)tmp; switch (caseExp.literal.value.type) { case Token.TokenValue.STRING: if (stringCases == null) { stringCases = new List<string>(); } stringCases.Add(caseExp.literal.value.stringValue); break; case Token.TokenValue.INT: if (intCases == null) { intCases = new List<int>(); } intCases.Add(caseExp.literal.value.intValue); break; } tmp = caseExp.next; } } } }
public void addCase(SwitchCaseExpression ce) { if (cases == null) { cases = new List <SwitchCaseExpression>(); } cases.Add(ce); if (ce is DefaultExpression) { hasDefaultCase = true; return; } if (ce is CaseExpression) { SwitchCaseExpression tmp = ce; while (tmp != null) { if (tmp is DefaultExpression) { hasDefaultCase = true; return; } else { CaseExpression caseExp = (CaseExpression)tmp; switch (caseExp.literal.value.type) { case Token.TokenValue.STRING: if (stringCases == null) { stringCases = new List <string>(); } stringCases.Add(caseExp.literal.value.stringValue); break; case Token.TokenValue.INT: if (intCases == null) { intCases = new List <int>(); } intCases.Add(caseExp.literal.value.intValue); break; } tmp = caseExp.next; } } } }
public static void Write(SwitchCaseExpression switchCaseExpression, IndentedStreamWriter writer) { writer.WriteLine($"({switchCaseExpression.Expression}) switch"); writer.OpenBrackets(); foreach (CaseExpression @case in switchCaseExpression.CaseExpressions) { writer.WriteLine($"{@case.Case} => {@case.Body},"); } if (switchCaseExpression.DefaultCaseBody is { })
public bool isCatched(string value, SwitchCaseExpression sce, bool preCatch) { if (sce is CaseExpression) { CaseExpression cExp = (CaseExpression)sce; if (cExp.next == null) { if (preCatch) { evalExpression(cExp.body); return(true); } //if (!cExp.literal.value.stringValue.Equals(value) && !preCatch) if (!cExp.literal.value.stringValue.Equals(value)) { return(false); } else { evalExpression(cExp.body); return(true); } } else { if (preCatch) { return(isCatched(value, cExp.next, preCatch)); } if (cExp.literal.value.stringValue.Equals(value)) { return(isCatched(value, cExp.next, true)); } return(isCatched(value, cExp.next, preCatch)); } } else if (sce is DefaultExpression) { evalExpression(((DefaultExpression)sce).body); return(true); } return(false); }
public bool isCatched(int value, SwitchCaseExpression sce, bool preCatch) { if (sce is CaseExpression) { CaseExpression cExp = (CaseExpression)sce; if (cExp.next == null) { if (preCatch) { evalExpression(cExp.body); return(true); } if (cExp.literal.value.intValue != value && !preCatch) { return(false); } else { evalExpression(cExp.body); return(true); } } else { if (preCatch) { return(isCatched(value, cExp.next, preCatch)); } if (cExp.literal.value.intValue == value) { return(isCatched(value, cExp.next, true)); } return(isCatched(value, cExp.next, preCatch)); } } else if (sce is DefaultExpression) { evalExpression(((DefaultExpression)sce).body); return(true); } return(false); }
public void addCase(SwitchCaseExpression ce) { if (cases == null) { cases = new List<SwitchCaseExpression>(); } cases.Add(ce); if (ce is DefaultExpression) { hasDefaultCase = true; return; } if (ce is CaseExpression) { SwitchCaseExpression tmp = ce; while (tmp != null) { if (tmp is DefaultExpression) { hasDefaultCase = true; return; } else { CaseExpression caseExp = (CaseExpression)tmp; if (intCases == null) { intCases = new List<int>(); } intCases.Add(caseExp.literal.value.intValue); tmp = caseExp.next; } } } }
public void addCase(SwitchCaseExpression ce) { if (cases == null) { cases = new List <SwitchCaseExpression>(); } cases.Add(ce); if (ce is DefaultExpression) { hasDefaultCase = true; return; } if (ce is CaseExpression) { SwitchCaseExpression tmp = ce; while (tmp != null) { if (tmp is DefaultExpression) { hasDefaultCase = true; return; } else { CaseExpression caseExp = (CaseExpression)tmp; if (intCases == null) { intCases = new List <int>(); } intCases.Add(caseExp.literal.value.intValue); tmp = caseExp.next; } } } }
public string Visit(SwitchCaseExpression matchCase) { var codeWriter = new XzaarCodeWriter(); if (matchCase.IsDefaultCase) { codeWriter.Write("default:", currentIndent); } else { insideExpressionCount++; codeWriter.Write("case ", currentIndent); codeWriter.Write(Visit(matchCase.Match)); codeWriter.Write(":"); insideExpressionCount--; } codeWriter.NewLine(); currentIndent++; codeWriter.Write(Visit(matchCase.Body)); currentIndent--; return(codeWriter.ToString()); }
public bool isCatched(int value, SwitchCaseExpression sce, bool preCatch) { if (sce is CaseExpression) { CaseExpression cExp = (CaseExpression)sce; if (cExp.next == null) { if (preCatch) { evalExpression(cExp.body); return true; } if (cExp.literal.value.intValue != value && !preCatch) { return false; } else { evalExpression(cExp.body); return true; } } else { if (preCatch) { return isCatched(value, cExp.next, preCatch); } if (cExp.literal.value.intValue == value) { return isCatched(value, cExp.next, true); } return isCatched(value, cExp.next, preCatch); } } else if (sce is DefaultExpression) { evalExpression(((DefaultExpression)sce).body); return true; } return false; }
public bool isCatched(string value, SwitchCaseExpression sce, bool preCatch) { if (sce is CaseExpression) { CaseExpression cExp = (CaseExpression)sce; if (cExp.next == null) { if (preCatch) { evalExpression(cExp.body); return true; } //if (!cExp.literal.value.stringValue.Equals(value) && !preCatch) if (!cExp.literal.value.stringValue.Equals(value)) { return false; } else { evalExpression(cExp.body); return true; } } else { if (preCatch) { return isCatched(value, cExp.next, preCatch); } if (cExp.literal.value.stringValue.Equals(value)) { return isCatched(value, cExp.next, true); } return isCatched(value, cExp.next, preCatch); } } else if (sce is DefaultExpression) { evalExpression(((DefaultExpression)sce).body); return true; } return false; }
public bool containsLiteral(SwitchCaseExpression sce) { if (sce is DefaultExpression) { return false; } CaseExpression caseExp = (CaseExpression)sce; switch (caseExp.literal.value.type) { case Token.TokenValue.STRING: if (stringCases == null) { return false; } return stringCases.Contains(caseExp.literal.value.stringValue); case Token.TokenValue.INT: if (intCases == null) { return false; } return intCases.Contains(caseExp.literal.value.intValue); } return true; }
public object Visit(SwitchCaseExpression node) { return(null); }
public object Visit(SwitchCaseExpression matchCase) { throw new System.NotImplementedException(); }