예제 #1
0
 public PseudoScope(PlaceHolderType placeHolder)
     : base(placeHolder.GetModule())
 {
     this.placeHolder = placeHolder;
     this.members = null;
     this.parentScope = null;
     this.chainNamespace = null;
 }
예제 #2
0
 public PseudoScope(Scope parent)
     : base(parent.GetModule())
 {
     this.placeHolder = null;
     this.parentScope = parent;
     this.members = new Dictionary<string, ScopeMember> ();
     this.chainNamespace = null;
 }
예제 #3
0
파일: Namespace.cs 프로젝트: ronsaldo/chela
 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;
 }
예제 #4
0
파일: Namespace.cs 프로젝트: ronsaldo/chela
 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;
 }
예제 #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> ();
        }
예제 #6
0
 public void SetNamespace(Namespace nspace)
 {
     this.nspace = nspace;
 }
예제 #7
0
 public NamespaceDefinition(string name, AstNode children, TokenPosition position)
     : base(children, position)
 {
     SetName(name);
     this.nspace = null;
 }
예제 #8
0
 public void SetChainNamespace(Namespace chain)
 {
     this.chainNamespace = chain;
 }
예제 #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();
        }
예제 #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;
        }
예제 #11
0
파일: Namespace.cs 프로젝트: ronsaldo/chela
        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);
        }
예제 #12
0
파일: Namespace.cs 프로젝트: ronsaldo/chela
        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);
        }