Пример #1
0
        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);
        }
Пример #2
0
 public object Visit(SwitchCaseExpression node)
 {
     if (node.Body != null)
     {
         Visit(node.Body);
     }
     return(null);
 }
Пример #3
0
        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;
                    }
                }
            }
        }
Пример #4
0
        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;
                    }
                }
            }
        }
Пример #5
0
        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 { })
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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;
                    }
                }
            }
        }
Пример #9
0
        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;
                    }
                }
            }
        }
Пример #10
0
        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());
        }
Пример #11
0
        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;
        }
Пример #12
0
        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;
        }
Пример #13
0
        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();
 }