protected override void VisitMethodCallSyntax(MethodCallSyntax pNode)
        {
            base.VisitMethodCallSyntax(pNode);

            //We only care about methods that aren't in the current module
            if (_module != null || Namespace != null)
            {
                System.Diagnostics.Debug.Assert(_module != null || _unit.HasReference(Namespace));

                //Get the referenced module
                var mod = Namespace == null ? _module : _unit.GetReference(Namespace);

                //Find the method
                foreach (var m in mod.Module.Methods)
                {
                    if (IsCalledMethod(m, pNode))
                    {
                        var rn = new ReferencedNode(m, mod.Cache);
                        if (!MethodNodes.Contains(rn))
                        {
                            MethodNodes.Add(rn);

                            //Get any type/methods that this method references
                            var mrv = new ModuleReferenceVisitor(mod.Cache, _context, mod);
                            mrv.MethodNodes.Add(rn);

                            mrv.Visit(m);
                            MethodNodes.AddRange(mrv.MethodNodes);
                            TypeNodes.AddRange(mrv.TypeNodes);
                        }
                    }
                }
            }
        }
        protected override void VisitModuleSyntax(ModuleSyntax pNode)
        {
            //////
            ////// Discover enums
            ////// Add enums first since they can't reference anything, but things can reference enums
            //////
            foreach (var e in pNode.Enums)
            {
                _unit.AddType(e);
            }

            //Build our list for discovering types
            for (int i = 0; i < pNode.Structs.Count; i++)
            {
                var s = pNode.Structs[i];
                if (s.DefinitionType == DefinitionTypes.Implement)
                {
                    var applies = SyntaxHelper.GetFullTypeName(s.AppliesTo);
                    if (!_implements.ContainsKey(applies))
                    {
                        _implements.Add(applies, new List <TypeDefinitionSyntax>());
                    }
                    _implements[applies].Add(s);
                }
                else
                {
                    _discoveryGraph.AddNode(s);
                }
            }

            /////
            ///// Discover all other types
            /////
            var nodes = _discoveryGraph.GetNodes();

            for (int i = 0; i < nodes.Count; i++)
            {
                var t = SyntaxHelper.GetFullTypeName(nodes[i].Node.DeclaredType);
                if (!nodes[i].Permanent &&
                    !nodes[i].Temporary &&
                    DiscoverTypes(t, nodes[i].Node.Span))
                {
                    //If we discover a type go back to the beginning to see if any that were dependent
                    //on this can now be typed
                    i = -1;
                }
            }

            foreach (var i in _implements)
            {
                foreach (var s in i.Value)
                {
                    //Validate that the namespace and type exist
                    var applyName = SyntaxHelper.GetFullTypeName(s.AppliesTo);
                    var name      = SyntaxHelper.GetFullTypeName(s.DeclaredType);

                    //Mark any traits for types
                    if (ValidateType(s.AppliesTo.Namespace, applyName, s) &&
                        ValidateType(s.DeclaredType.Namespace, name, s))
                    {
                        var result = _unit.FromString(s.DeclaredType, out SmallType traitType);
                        System.Diagnostics.Debug.Assert(result == Compiler.FindResult.Found);

                        result = _unit.FromString(s.AppliesTo, out SmallType applyType);
                        System.Diagnostics.Debug.Assert(result == Compiler.FindResult.Found);

                        applyType.AddTrait(traitType);

                        TypeDefinitionSyntax trait;
                        if (s.DeclaredType.Namespace == null)
                        {
                            trait = _discoveryGraph.GetNode(name).Node;
                        }
                        else
                        {
                            //TODO clean this up
                            trait = _unit.GetReference(s.DeclaredType.Namespace.Value).Module.Structs.SingleOrDefault((pt) => pt.DeclaredType.Value == s.DeclaredType.Value);
                        }
                        ValidateImplementation(trait, s);
                    }
                }
            }

            //
            // Add all methods to the MethodCache
            //
            for (int j = 0; j < pNode.Methods.Count; j++)
            {
                AddMethodToCache(null, pNode.Methods[j], out MethodDefinition m);
            }

            //
            // Add struct methods to MethodCache
            //
            foreach (var s in pNode.Structs)
            {
                var result = _unit.FromString(s.GetApplicableType(), out SmallType type);

                //This can occur if we are specifying an undeclared type
                //or a type imported from another module
                // - The namespace might not be specified
                // - The type might not be exported
                switch (result)
                {
                case Compiler.FindResult.IncorrectScope:
                    CompilerErrors.TypeNotInScope(s.GetApplicableType().ToString(), s.Span);
                    break;

                case Compiler.FindResult.NotFound:
                    CompilerErrors.UndeclaredType(s.GetApplicableType().ToString(), s.Span);
                    break;
                }

                //Add each method to the cache and set type constructors if necessary
                for (int j = 0; j < s.Methods.Count; j++)
                {
                    if (AddMethodToCache(type, s.Methods[j], out MethodDefinition m) &&
                        s.Methods[j].Annotation.Value == KeyAnnotations.Constructor)
                    {
                        type.SetConstructor(m);
                    }
                }

                if (!type.HasDefinedConstructor())
                {
                    type.SetDefaultConstructor();
                }
            }
        }