Esempio n. 1
0
        private bool AddEnum(API.Nodes.Enum enm, List <Flag> flags)
        {
            bool result = true;

            foreach (var e in enm.Elements)
            {
                switch (e.NodeKind)
                {
                case NodeKind.Cnst:
                    var cnst = (Cnst)e;
                    switch (cnst.CnstKind)
                    {
                    case CnstKind.Numeric:
                        AddRange((Rational)cnst.Raw, (Rational)cnst.Raw);
                        break;

                    case CnstKind.String:
                        elements.Add(table.GetCnstSymbol((string)cnst.Raw));
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    break;

                case NodeKind.Range:
                    var rng = (Range)e;
                    AddRange(rng.Lower, rng.Upper);
                    break;

                case NodeKind.Id:
                    var symbol = Resolve((Id)e, flags, false);
                    if (symbol == null)
                    {
                        result = false;
                    }
                    else
                    {
                        elements.Add(symbol);
                    }

                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(result);
        }
Esempio n. 2
0
        private bool AddEnum(API.Nodes.Enum enm, List <Flag> flags)
        {
            bool     result = true;
            Rational r;

            foreach (var e in enm.Elements)
            {
                switch (e.NodeKind)
                {
                case NodeKind.Cnst:
                    var cnst = (Cnst)e;
                    switch (cnst.CnstKind)
                    {
                    case CnstKind.Numeric:
                        r = (Rational)cnst.Raw;
                        if (r.IsInteger)
                        {
                            intervals.Add(r.Numerator, r.Numerator);
                        }
                        else
                        {
                            elements.Add(table.GetCnstSymbol(r));
                            break;
                        }

                        break;

                    case CnstKind.String:
                        elements.Add(table.GetCnstSymbol((string)cnst.Raw));
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    break;

                case NodeKind.Range:
                    var rng = (Range)e;
                    table.GetCnstSymbol(rng.Lower);
                    table.GetCnstSymbol(rng.Upper);
                    intervals.Add(rng.Lower.Numerator, rng.Upper.Numerator);
                    break;

                case NodeKind.Id:
                    var symbol = Resolve((Id)e, flags, false);
                    if (symbol == null)
                    {
                        result = false;
                    }
                    else if (symbol.Kind == SymbolKind.UserCnstSymb && ((UserCnstSymb)symbol).IsSymbolicConstant)
                    {
                        flags.Add(new Flag(
                                      SeverityKind.Error,
                                      e,
                                      Constants.EnumerationError.ToString(),
                                      Constants.EnumerationError.Code));
                        result = false;
                    }
                    else
                    {
                        elements.Add(symbol);
                    }

                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(result);
        }