Ejemplo n.º 1
0
        private bool DiscoverTypes(string pType, TextSpan pSpan)
        {
            //If a node doesn't exist the type hasn't been declared
            if (!_discoveryGraph.NodeExists(pType))
            {
                CompilerErrors.UndeclaredType(pType, pSpan);
                return(false);
            }

            //If we have been here already we have a circular reference in our types
            //ie Type1 has a field of Type2; Type2 has a field of Type1
            var item = _discoveryGraph.GetNode(pType);

            if (item.Permanent)
            {
                return(true);
            }
            if (item.Temporary)
            {
                CompilerErrors.CircularReference(item.Node, item.Node.Span);
                return(false);
            }

            item.Temporary = true;

            for (int i = 0; i < item.Node.Fields.Count; i++)
            {
                var type = item.Node.Fields[i].TypeNode;
                var nt   = type.Value;
                if (nt.IndexOf('[') > -1)
                {
                    nt = nt.Substring(0, nt.IndexOf('['));
                }

                //Only look through user defined types which should be undefined at this point
                if (!item.Node.TypeParameters.Contains(nt) &&
                    !_unit.IsTypeDefined(type.Namespace, nt) &&
                    !DiscoverTypes(nt, type.Span))
                {
                    return(false);
                }
            }

            item.Permanent = true;

            return(AddType(item.Node));
        }