示例#1
0
        public override bool VisitVariableReferenceExpression(VariableReferenceExpression varRef)
        {
            if (varRef.Identifier.Type == IdentifierType.Local)
            {
                String       name  = varRef.Identifier.Name;
                ISymbolTable table = varRef.SymbolTable;

                // It might be a variable or might be something else.
                // First of all, let's see whether it is a var

                bool isDefinedAsVar = false;

                isDefinedAsVar = varRef.SymbolTable.IsDefined(name);

                if (!isDefinedAsVar)
                {
                    if (table.ScopeType == ScopeType.Block || table.ScopeType == ScopeType.Compound)
                    {
                        isDefinedAsVar = table.IsDefinedInParent(name);
                    }
                }

                if (!isDefinedAsVar)
                {
                    // Ok, this might be two things now:
                    // an undeclared variable, a type ref or a member access... Let's check the type graph

                    TypeDefinition typeDef = varRef.SymbolTable.CurrentTypeDefinition;

                    System.Diagnostics.Debug.Assert(typeDef != null);

                    if (typeDef.HasInstanceMember(name) || typeDef.HasStaticMember(name))
                    {
                        // Wow! Finally

                        // TODO: Replace node by MemberAccess or method invocation, depending on the case
                    }
                    else
                    {
                        NamespaceGraph nsGraph = table.TypeGraphView.GetNamespace(name);

                        if (nsGraph == null)
                        {
                            TypeDefinition typedef = table.TypeGraphView.GetType(name);

                            if (typedef == null)
                            {
                                errorReport.Error("TODOFILENAME", varRef.Position, "'{0}' undeclared identifier", name);
                            }
                        }
                    }
                }
            }

            return(base.VisitVariableReferenceExpression(varRef));
        }
示例#2
0
        public override bool VisitSourceUnit(SourceUnit unit)
        {
            NamespaceGraph nsGraph = unit.SymbolTable.TypeGraphView.DefineNamespace("Castle.Rook.Code");

            unit.SymbolTable.CurrentNamespace = nsGraph;

            TypeDefinitionStatement typeDef = new TypeDefinitionStatement(unit.SymbolTable, AccessLevel.Private, String.Format("Global{0}", globalClassesCount++));

            unit.SymbolTable.CurrentTypeDefinition = typeDef.SymbolTable.CurrentNamespace.AddTransientType(typeDef);

            return(base.VisitSourceUnit(unit));
        }
示例#3
0
        public void AddingAssembly()
        {
            TypeGraphSpace graph = new TypeGraphSpace();

            graph.AddAssemblyReference("mscorlib");
            graph.AddAssemblyReference("System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            NamespaceGraph ng = graph.GetNamespace("System");

            Assert.IsNotNull(ng);
            Assert.AreEqual("System", ng.Name);

            ng = graph.GetNamespace("System::Collections::Specialized");
            Assert.IsNotNull(ng);
            Assert.AreEqual("Specialized", ng.Name);

            ng = graph.GetNamespace("System::Diagnostics");
            Assert.IsNotNull(ng);
            Assert.AreEqual("Diagnostics", ng.Name);
        }