GetNamespace() 공개 정적인 메소드

public static GetNamespace ( String name, VsaEngine engine ) : Namespace
name String
engine Microsoft.JScript.Vsa.VsaEngine
리턴 Namespace
예제 #1
0
        internal static void GetNamespace(string name, bool create)
        {
            int pos = name.IndexOf('.');

            Namespace ns;
            string    first;

            if (pos >= 0)
            {
                first = name.Substring(0, pos);
            }
            else
            {
                first = name;
            }

            ns = (Namespace)namespaces [first];
            if (ns == null)
            {
                if (!create)
                {
                    throw new Exception("unknown case");
                }

                ns = new Namespace(first);
                namespaces.Add(first, ns);
            }

            if (pos >= 0)
            {
                Namespace.GetNamespace(name.Substring(pos + 1), create);
            }
        }
예제 #2
0
        internal override WrappedNamespace EvaluateAsWrappedNamespace(bool giveErrorIfNameInUse)
        {
            WrappedNamespace root = this.rootObject.EvaluateAsWrappedNamespace(giveErrorIfNameInUse);
            String           name = this.name;

            root.AddFieldOrUseExistingField(name, Namespace.GetNamespace(root.ToString() + "." + name, this.Engine), FieldAttributes.Literal);
            return(new WrappedNamespace(root.ToString() + "." + name, this.Engine));
        }
예제 #3
0
        public static void JScriptPackage(string rootName, VsaEngine engine)
        {
            GlobalScope globalScope = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();

            if (globalScope.GetLocalField(rootName) == null)
            {
                FieldInfo info = globalScope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Literal | FieldAttributes.Public);
            }
        }
예제 #4
0
        internal void AddOwnName()
        {
            String root = this.name;
            int    i    = root.IndexOf('.');

            if (i > 0)
            {
                root = root.Substring(0, i);
            }
            base.AddNewField(root, Namespace.GetNamespace(root, this.engine), FieldAttributes.Literal | FieldAttributes.Public);
        }
예제 #5
0
        internal void AddOwnName()
        {
            string name  = this.name;
            int    index = name.IndexOf('.');

            if (index > 0)
            {
                name = name.Substring(0, index);
            }
            base.AddNewField(name, Namespace.GetNamespace(name, base.engine), FieldAttributes.Literal | FieldAttributes.Public);
        }
예제 #6
0
        public static void JScriptImport(string name, VsaEngine engine)
        {
            int         index       = name.IndexOf('.');
            string      str         = (index > 0) ? name.Substring(0, index) : name;
            GlobalScope globalScope = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();

            if (globalScope.GetLocalField(str) == null)
            {
                FieldInfo info = globalScope.AddNewField(str, Namespace.GetNamespace(str, engine), FieldAttributes.Literal | FieldAttributes.Public);
            }
            engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
        }
예제 #7
0
        public static void JScriptImport(String name, VsaEngine engine)
        {
            int         dotPos   = name.IndexOf('.');
            String      rootName = dotPos > 0 ? name.Substring(0, dotPos) : name;
            GlobalScope scope    = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();
            FieldInfo   field    = scope.GetLocalField(rootName);

            if (field == null)
            {
                field = scope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Public | FieldAttributes.Literal);
            }
            engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
        }
예제 #8
0
        /// <summary>
        ///   Computes the namespaces that we import from the assemblies we reference.
        /// </summary>
        public static void ComputeNamespaces()
        {
            MethodInfo assembly_get_namespaces = typeof(Assembly).GetMethod("GetNamespaces", BindingFlags.Instance | BindingFlags.NonPublic);

            Hashtable cache = null;

            //
            // First add the assembly namespaces
            //
            if (assembly_get_namespaces != null)
            {
                int count = assemblies.Length;

                for (int i = 0; i < count; i++)
                {
                    Assembly  a          = assemblies [i];
                    string [] namespaces = (string [])assembly_get_namespaces.Invoke(a, null);
                    foreach (string ns in namespaces)
                    {
                        if (ns == "")
                        {
                            continue;
                        }
                        Namespace.GetNamespace(ns, true);
                    }
                }
            }
            else
            {
                cache = new Hashtable();
                cache.Add("", null);
                foreach (Assembly a in assemblies)
                {
                    foreach (Type t in a.GetExportedTypes())
                    {
                        string ns = t.Namespace;
                        if (ns == null || cache.Contains(ns))
                        {
                            continue;
                        }
                        Namespace.GetNamespace(ns, true);
                        cache.Add(ns, null);
                    }
                }
            }
        }
예제 #9
0
 internal override AST PartiallyEvaluate()
 {
     this.BindName(null);
     if (this.members == null || this.members.Length == 0)
     {
         //if this rootObject is a constant and its value is a namespace, turn this node also into a namespace constant
         if (this.rootObject is ConstantWrapper)
         {
             Object val = this.rootObject.Evaluate();
             if (val is Namespace)
             {
                 return(new ConstantWrapper(Namespace.GetNamespace(((Namespace)val).Name + "." + this.name, this.Engine), this.context));
             }
         }
         this.HandleNoSuchMemberError();
         return(this);
     }
     this.ResolveRHValue();
     if (this.member is FieldInfo && ((FieldInfo)this.member).IsLiteral)
     {
         Object val = this.member is JSVariableField ? ((JSVariableField)this.member).value : TypeReferences.GetConstantValue((FieldInfo)this.member);
         if (val is AST)
         {
             AST pval = ((AST)val).PartiallyEvaluate();
             if (pval is ConstantWrapper)
             {
                 return(pval);
             }
             val = null;
         }
         if (!(val is FunctionObject) && (!(val is ClassScope) || ((ClassScope)val).owner.IsStatic))
         {
             return(new ConstantWrapper(val, this.context));
         }
     }
     else if (this.member is Type)
     {
         return(new ConstantWrapper(this.member, this.context));
     }
     return(this);
 }
예제 #10
0
        internal override WrappedNamespace EvaluateAsWrappedNamespace(bool giveErrorIfNameInUse)
        {
            Namespace   ns    = Namespace.GetNamespace(this.name, this.Engine);
            GlobalScope scope = ((IActivationObject)Globals.ScopeStack.Peek()).GetGlobalScope();
            FieldInfo   field = giveErrorIfNameInUse ? scope.GetLocalField(this.name) : scope.GetField(this.name, BindingFlags.Public | BindingFlags.Static);

            if (field != null)
            {
                if (giveErrorIfNameInUse && (!field.IsLiteral || !(field.GetValue(null) is Namespace)))
                {
                    this.context.HandleError(JSError.DuplicateName, true);
                }
            }
            else
            {
                field = scope.AddNewField(this.name, ns, FieldAttributes.Literal | FieldAttributes.Public);
                ((JSVariableField)field).type            = new TypeExpression(new ConstantWrapper(Typeob.Namespace, this.context));
                ((JSVariableField)field).originalContext = this.context;
            }
            return(new WrappedNamespace(this.name, this.Engine));
        }
예제 #11
0
        internal override WrappedNamespace EvaluateAsWrappedNamespace(bool giveErrorIfNameInUse)
        {
            Namespace   namespace2  = Namespace.GetNamespace(base.name, base.Engine);
            GlobalScope globalScope = ((IActivationObject)base.Globals.ScopeStack.Peek()).GetGlobalScope();
            FieldInfo   info        = giveErrorIfNameInUse ? globalScope.GetLocalField(base.name) : globalScope.GetField(base.name, BindingFlags.Public | BindingFlags.Static);

            if (info != null)
            {
                if (giveErrorIfNameInUse && (!info.IsLiteral || !(info.GetValue(null) is Namespace)))
                {
                    base.context.HandleError(JSError.DuplicateName, true);
                }
            }
            else
            {
                info = globalScope.AddNewField(base.name, namespace2, FieldAttributes.Literal | FieldAttributes.Public);
                ((JSVariableField)info).type            = new TypeExpression(new ConstantWrapper(Typeob.Namespace, base.context));
                ((JSVariableField)info).originalContext = base.context;
            }
            return(new WrappedNamespace(base.name, base.Engine));
        }
예제 #12
0
 internal override AST PartiallyEvaluate()
 {
     this.BindName(null);
     if ((base.members == null) || (base.members.Length == 0))
     {
         if (this.rootObject is ConstantWrapper)
         {
             object obj2 = this.rootObject.Evaluate();
             if (obj2 is Namespace)
             {
                 return(new ConstantWrapper(Namespace.GetNamespace(((Namespace)obj2).Name + "." + base.name, base.Engine), base.context));
             }
         }
         this.HandleNoSuchMemberError();
         return(this);
     }
     base.ResolveRHValue();
     if ((base.member is FieldInfo) && ((FieldInfo)base.member).IsLiteral)
     {
         object obj3 = (base.member is JSVariableField) ? ((JSVariableField)base.member).value : TypeReferences.GetConstantValue((FieldInfo)base.member);
         if (obj3 is AST)
         {
             AST ast = ((AST)obj3).PartiallyEvaluate();
             if (ast is ConstantWrapper)
             {
                 return(ast);
             }
             obj3 = null;
         }
         if (!(obj3 is FunctionObject) && (!(obj3 is ClassScope) || ((ClassScope)obj3).owner.IsStatic))
         {
             return(new ConstantWrapper(obj3, base.context));
         }
     }
     else if (base.member is Type)
     {
         return(new ConstantWrapper(base.member, base.context));
     }
     return(this);
 }