Esempio n. 1
0
 public PseudoScope(PlaceHolderType placeHolder)
     : base(placeHolder.GetModule())
 {
     this.placeHolder = placeHolder;
     this.members = null;
     this.parentScope = null;
     this.chainNamespace = null;
 }
Esempio n. 2
0
 public PseudoScope(Scope parent)
     : base(parent.GetModule())
 {
     this.placeHolder = null;
     this.parentScope = parent;
     this.members = new Dictionary<string, ScopeMember> ();
     this.chainNamespace = null;
 }
Esempio n. 3
0
 internal Namespace(ChelaModule module)
     : base(module)
 {
     this.parentScope = null;
     this.members = new Dictionary<string, ScopeMember> ();
     this.name = string.Empty;
     this.globalInitialization = null;
     this.staticConstructor = null;
 }
Esempio n. 4
0
 public Namespace(Namespace parent)
     : base(parent.GetModule())
 {
     this.parentScope = parent;
     this.members = new Dictionary<string, ScopeMember> ();
     this.globalInitialization = null;
     this.staticConstructor = null;
     this.name = string.Empty;
 }
Esempio n. 5
0
        public ChelaModule()
        {
            this.name = "";
            this.fileName = "";
            this.workDir = "";
            this.globalNamespace = new Namespace(this);
            this.memberTable = new List<ScopeMember> ();
            this.registeredMembers = new Dictionary<ScopeMember, uint> ();
            this.memberNameTable = new Dictionary<string, ScopeMember> ();
            this.registeredStrings = new Dictionary<string, uint> ();
            this.stringTable = new List<string> ();
            this.referencedModules = new List<ChelaModule> ();
            this.nativeLibraries = new List<string> ();
            this.typeMap = new Dictionary<IChelaType, IChelaType> ();
            this.associatedClass = new Dictionary<IChelaType, Structure> ();
            this.associatedPrimitive = new Dictionary<Structure, IChelaType> ();
            this.resources = new List<ResourceData> ();
            this.genericInstances = new List<ScopeMember>();
            this.attributeClass = null;
            this.arrayClass = null;
            this.valueTypeClass = null;
            this.enumClass = null;
            this.typeClass = null;
            this.delegateClass = null;
            this.moduleType = ModuleType.Library;
            this.runtimeModule = null;
            this.debugBuild = false;
            this.mainName = null;
            this.mainFunction = null;
            this.placeHolderId = 0;
            this.writingModule = false;

            // Type tables.
            this.registeredTypes = new Dictionary<IChelaType, uint> (0, new ReferenceEqualityComparer<IChelaType> ());
            this.typeTable = new List<object> ();
            this.anonymousTypeMap = new Dictionary<IChelaType, uint> (0, new ReferenceEqualityComparer<IChelaType> ());
            this.anonymousTypes = new List<object> ();
        }
Esempio n. 6
0
 public void SetNamespace(Namespace nspace)
 {
     this.nspace = nspace;
 }
Esempio n. 7
0
 public NamespaceDefinition(string name, AstNode children, TokenPosition position)
     : base(children, position)
 {
     SetName(name);
     this.nspace = null;
 }
Esempio n. 8
0
 public void SetChainNamespace(Namespace chain)
 {
     this.chainNamespace = chain;
 }
Esempio n. 9
0
        private void CreateStaticConstructor(AstNode node, Namespace space)
        {
            // Check for a previous definition.
            if(space.GetStaticConstructor() != null || space.GetGlobalInitializations() == null)
                return;

            // Get the static initialization fields.
            List<FieldDeclaration> staticInitedField = new List<FieldDeclaration> ();
            bool isUnsafe = false;
            foreach(FieldDeclaration decl in space.GetGlobalInitializations())
            {
                Variable variable = decl.GetVariable();
                if(variable.IsStatic())
                {
                    staticInitedField.Add(decl);
                    if(variable.IsUnsafe())
                        isUnsafe = true;
                }
            }

            // If there aren't field to initialize, don't create the static constructor.
            if(staticInitedField.Count == 0)
                return;

            // Create the static constructor function type.
            FunctionType ctorType = FunctionType.Create(ChelaType.GetVoidType());

            // Create the constructor method.
            MemberFlags flags = MemberFlags.StaticConstructor;
            if(isUnsafe)
                flags |= MemberFlags.Unsafe;
            Function constructor = new Function("<sctor>", flags, space);
            constructor.SetFunctionType(ctorType);

            // Store it.
            space.AddMember(constructor);

            // Create the constructor scope.
            LexicalScope ctorScope = CreateLexicalScope(node, constructor);
            PushScope(ctorScope);

            // Create the top basic block.
            BasicBlock topBlock = new BasicBlock(constructor);
            builder.SetBlock(topBlock);

            // Initialize the static fields.
            GenerateStaticFieldInitializations(null, staticInitedField);

            // Restore the scope.
            PopScope();

            // Return void.
            builder.CreateRetVoid();
        }
Esempio n. 10
0
        public override AstNode Visit(NamespaceDefinition node)
        {
            // Handle nested names.
            string fullname = node.GetName();
            StringBuilder nameBuilder = new StringBuilder();

            int numscopes = 0;

            for(int i = 0; i < fullname.Length; i++)
            {
                char c = fullname[i];
                if(c != '.')
                {
                    nameBuilder.Append(c);
                    if(i+1 < fullname.Length)
                        continue;
                }

                // Expect full name.
                if(c == '.' && i+1 == fullname.Length)
                    Error(node, "expected complete namespace name.");

                // Find an already declared namespace.
                string name = nameBuilder.ToString();
                nameBuilder.Length = 0;
                ScopeMember old = currentContainer.FindMember(name);
                if(old != null)
                {
                    if(!old.IsNamespace())
                        Error(node, "defining namespace collides with another thing.");

                    // Store a reference in the node.
                    node.SetNamespace((Namespace)old);
                }
                else
                {
                    // Cast the current scope.
                    Namespace space = (Namespace)currentContainer;

                    // Create, name and add the new namespace.
                    Namespace newNamespace = new Namespace(space);
                    newNamespace.SetName(name);
                    space.AddMember(newNamespace);

                    // Store a reference in the node.
                    node.SetNamespace(newNamespace);
                }

                // Update the scope.
                PushScope(node.GetNamespace());

                // Increase the number of scopes.
                numscopes++;
            }

            // Visit the children.
            VisitList(node.GetChildren());

            // Restore the scopes.
            for(int i = 0; i < numscopes; i++)
                PopScope();

            return node;
        }
Esempio n. 11
0
        internal override void UpdateParent(Scope parentScope)
        {
            // Store the new parent.
            this.parentScope = (Namespace)parentScope;

            // Update the children.
            foreach(ScopeMember child in members.Values)
                child.UpdateParent(this);
        }
Esempio n. 12
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal namespace and register it.
            Namespace space = new Namespace(module);
            module.RegisterMember(space);

            // Read the name.
            space.name = module.GetString(header.memberName);

            // Skip the namespace elements.
            reader.Skip(header.memberSize);
        }