예제 #1
0
 internal override void MergeSymbolDefinition(UserSymbol s)
 {
     foreach (var def in s.Definitions)
     {
         definitions.Add((AST <UnnDecl>)def);
     }
 }
예제 #2
0
        internal override bool IsCompatibleDefinition(UserSymbol s)
        {
            UserCnstSymb us = s as UserCnstSymb;

            return(us != null &&
                   us.UserCnstKind == UserCnstKind &&
                   us.IsAutoGen == IsAutoGen);
        }
예제 #3
0
 /// <summary>
 /// Returns true if the declaration of symbols s does not trivially conflict with other definitions.
 /// </summary>
 internal virtual bool IsCompatibleDefinition(UserSymbol s)
 {
     Contract.Requires(CanonicalForm == null);
     Contract.Requires(s != null);
     Contract.Requires(s.Name == Name);
     Contract.Requires(s.Namespace == Namespace);
     throw new NotImplementedException();
 }
예제 #4
0
        internal override bool IsCompatibleDefinition(UserSymbol s)
        {
            var uss = s as UnnSortSymb;

            if (uss == null)
            {
                return(false);
            }

            return(uss.Sort == Sort);
        }
예제 #5
0
 /// <summary>
 /// If there are multiple compatible definitions of the symbol, then this function merges
 /// those definitions into this symbol.
 /// </summary>
 /// <param name="s"></param>
 internal virtual void MergeSymbolDefinition(UserSymbol s)
 {
     Contract.Requires(CanonicalForm == null);
     Contract.Requires(s != null);
     Contract.Requires(s.Name == Name);
     Contract.Requires(s.Namespace == Namespace);
     Contract.Requires(s.Kind == Kind);
     Contract.Requires(s.Arity == Arity);
     Contract.Requires(s.IsAutoGen == IsAutoGen);
     throw new NotImplementedException();
 }
예제 #6
0
        internal override bool IsCompatibleDefinition(UserSymbol s)
        {
            AST <ConDecl> sDecl = s.Definitions.First <AST <Node> >() as AST <ConDecl>;

            if (s.Kind != Kind ||
                s.IsAutoGen != IsAutoGen ||
                sDecl == null ||
                sDecl.Node.IsNew != IsNew ||
                sDecl.Node.IsSub != IsSub ||
                sDecl.Node.Fields.Count != arity)
            {
                return(false);
            }

            bool isEmpty1, isEmpty2;

            using (var it1 = definitions.First <AST <ConDecl> >().Node.Fields.GetEnumerator())
            {
                using (var it2 = sDecl.Node.Fields.GetEnumerator())
                {
                    while (it1.MoveNext() & it2.MoveNext())
                    {
                        if (it1.Current.IsAny != it2.Current.IsAny)
                        {
                            return(false);
                        }

                        isEmpty1 = string.IsNullOrEmpty(it1.Current.Name);
                        isEmpty2 = string.IsNullOrEmpty(it2.Current.Name);
                        if (isEmpty1 != isEmpty2 || (!isEmpty1 && string.CompareOrdinal(it1.Current.Name, it2.Current.Name) != 0))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
예제 #7
0
 internal override bool IsCompatibleDefinition(UserSymbol s)
 {
     return(s.Kind == Kind && s.IsAutoGen == IsAutoGen);
 }
예제 #8
0
 internal UserSortSymb(UserSymbol dataSymbol)
 {
     Contract.Assert(dataSymbol != null);
     DataSymbol = dataSymbol;
 }
예제 #9
0
        internal bool TryAddSymbol(
            UserSymbol symbol,
            Func <int> idGetter,
            List <Flag> flags,
            SizeExpr sizeExpr = null)
        {
            Contract.Requires(symbol != null && symbol.Namespace == this && idGetter != null);
            UserSymbol existingSym;

            if (!symbols.TryFindValue(symbol.Name, out existingSym))
            {
                if (!symbol.IsAutoGen && !API.ASTQueries.ASTSchema.Instance.IsId(symbol.Name, false, false, false, false))
                {
                    var ast  = symbol.Definitions.First <AST <Node> >();
                    var flag = new Flag(
                        SeverityKind.Error,
                        ast.Node,
                        Constants.BadId.ToString(symbol.Name, "symbol"),
                        Constants.BadId.Code,
                        ast.Root.NodeKind == NodeKind.Program ? ((Program)ast.Root).Name : null);
                    flags.Add(flag);
                    return(false);
                }

                symbol.Id = idGetter();
                symbols.Add(symbol.Name, symbol);
                if (symbol.Kind == SymbolKind.ConSymb)
                {
                    var conSymb = ((ConSymb)symbol);
                    var usrSort = new UserSortSymb(symbol);
                    usrSort.Id         = idGetter();
                    conSymb.SortSymbol = usrSort;
                    if (sizeExpr != null)
                    {
                        usrSort.Size = sizeExpr;
                    }
                }
                else if (symbol.Kind == SymbolKind.MapSymb)
                {
                    var mapSymb = ((MapSymb)symbol);
                    var usrSort = new UserSortSymb(symbol);
                    usrSort.Id         = idGetter();
                    mapSymb.SortSymbol = usrSort;
                    if (sizeExpr != null)
                    {
                        usrSort.Size = sizeExpr;
                    }
                }

                return(true);
            }

            if (!existingSym.IsCompatibleDefinition(symbol))
            {
                var ast1 = symbol.Definitions.First <AST <Node> >();
                var ast2 = existingSym.Definitions.First <AST <Node> >();

                var flag = new Flag(
                    SeverityKind.Error,
                    ast1.Node,
                    MessageHelpers.MkDupErrMsg(string.Format("symbol {0}", symbol.Name), ast1, ast2, SymbolTable.Env.Parameters),
                    Constants.DuplicateDefs.Code,
                    ast1.Root.NodeKind == NodeKind.Program ? ((Program)ast1.Root).Name : null);
                flags.Add(flag);
                return(false);
            }

            existingSym.MergeSymbolDefinition(symbol);
            return(true);
        }
예제 #10
0
 public bool TryGetSymbol(string name, out UserSymbol symbol)
 {
     return(symbols.TryFindValue(name, out symbol));
 }
예제 #11
0
 internal override void MergeSymbolDefinition(UserSymbol s)
 {
 }
예제 #12
0
        internal override bool IsCompatibleDefinition(UserSymbol s)
        {
            var           myDecl = definitions.First <AST <MapDecl> >().Node;
            AST <MapDecl> sDecl  = s.Definitions.First <AST <Node> >() as AST <MapDecl>;

            if (s.Kind != Kind ||
                s.IsAutoGen != IsAutoGen ||
                sDecl == null ||
                sDecl.Node.Dom.Count != myDecl.Dom.Count ||
                sDecl.Node.Cod.Count != myDecl.Cod.Count ||
                sDecl.Node.MapKind != myDecl.MapKind ||
                sDecl.Node.IsPartial != myDecl.IsPartial)
            {
                return(false);
            }

            bool isEmpty1, isEmpty2;

            using (var it1 = myDecl.Dom.GetEnumerator())
            {
                using (var it2 = sDecl.Node.Dom.GetEnumerator())
                {
                    while (it1.MoveNext() & it2.MoveNext())
                    {
                        if (it1.Current.IsAny != it2.Current.IsAny)
                        {
                            return(false);
                        }

                        isEmpty1 = string.IsNullOrEmpty(it1.Current.Name);
                        isEmpty2 = string.IsNullOrEmpty(it2.Current.Name);
                        if (isEmpty1 != isEmpty2 || (!isEmpty1 && string.CompareOrdinal(it1.Current.Name, it2.Current.Name) != 0))
                        {
                            return(false);
                        }
                    }
                }
            }

            using (var it1 = myDecl.Cod.GetEnumerator())
            {
                using (var it2 = sDecl.Node.Cod.GetEnumerator())
                {
                    while (it1.MoveNext() & it2.MoveNext())
                    {
                        if (it1.Current.IsAny != it2.Current.IsAny)
                        {
                            return(false);
                        }

                        isEmpty1 = string.IsNullOrEmpty(it1.Current.Name);
                        isEmpty2 = string.IsNullOrEmpty(it2.Current.Name);
                        if (isEmpty1 != isEmpty2 || (!isEmpty1 && string.CompareOrdinal(it1.Current.Name, it2.Current.Name) != 0))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }