Ejemplo n.º 1
0
        public override AstNode Visit(GetAccessorDefinition node)
        {
            // Ignore pure declarations.
            if(node.GetChildren() == null)
                return node;

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

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

            // Restore the scope.
            PopScope();

            return node;
        }
Ejemplo n.º 2
0
        public override AstNode Visit(GetAccessorDefinition node)
        {
            PropertyVariable property = node.GetProperty();

            // Check for property declarations.
            if(node.GetChildren() == null && property.GetAccessor != null)
                return node;

            if(node.GetChildren() != null && property.GetAccessor != null)
                Error(node, "multiples definitions of the get accessor.");

            // Build the property flags.
            MemberFlags flags = node.GetFlags();
            if(flags == MemberFlags.ImplicitVis)
            {
                flags = property.GetFlags();
            }
            else
            {
                // TODO: Check compatibility.
                flags |= property.GetFlags() & ~MemberFlags.VisibilityMask;
            }

            // Get the instance type.
            MemberFlags instanceFlags = MemberFlags.InstanceMask & flags;

            // Abstract properties cannot have a body.
            if((instanceFlags == MemberFlags.Abstract ||
               instanceFlags == MemberFlags.Contract) && node.GetChildren() != null)
                Error(node, "abstract properties cannot have a definition body.");

            // Create the get accesor.
            if(property.GetAccessor == null)
            {
                // Create the argument list.
                List<IChelaType> arguments = new List<IChelaType> ();

                // Add the this argument.
                IChelaType selfType = null;
                if(currentContainer.IsStructure() || currentContainer.IsClass() || currentContainer.IsInterface())
                {
                    Structure building = (Structure) currentContainer;
                    if(instanceFlags != MemberFlags.Static)
                    {
                        // Instance the building.
                        building = building.GetSelfInstance();

                        // Create the self type
                        selfType = ReferenceType.Create(building);
                        arguments.Add(selfType);
                    }
                }

                // Append the indices.
                foreach(IChelaType indexType in property.Indices)
                    arguments.Add(indexType);

                // Create the function type.
                FunctionType functionType = FunctionType.Create(property.GetVariableType(), arguments, false);

                // Create the function.
                Function accessor;
                if(selfType != null)
                    accessor = new Method("get_" + property.GetName(), flags, currentContainer);
                else
                    accessor = new Function("get_" + property.GetName(), flags, currentContainer);

                // Set the arguments.
                accessor.SetFunctionType(functionType);

                // Set the functionposition.
                accessor.Position = node.GetPosition();

                // Store the function in the property.
                property.GetAccessor = accessor;

                // Store the function in his scope.
                if(currentContainer.IsStructure() || currentContainer.IsClass() || currentContainer.IsInterface())
                {
                    Structure building = (Structure)currentContainer;
                    building.AddFunction("get_" + property.GetName(), accessor);
                }
                else if(currentContainer.IsNamespace())
                {
                    Namespace space = (Namespace)currentContainer;
                    space.AddMember(accessor);
                }
                else
                {
                    Error(node, "a property cannot be declared here.");
                }

                // If there's a body, declare the "argument" variables
                if(node.GetChildren() != null)
                {
                    LexicalScope scope = CreateLexicalScope(node, accessor);
                    if(selfType != null)
                    {
                        node.ArgumentVariables.Add(
                            new ArgumentVariable(0, "this", scope, selfType)
                        );
                    }

                    // Add the indices variables.
                    AstNode index = node.GetIndices();
                    List<LocalVariable> indexerVars = new List<LocalVariable> ();
                    while(index != null)
                    {
                        // Create the local
                        LocalVariable local = new LocalVariable(index.GetName(), scope, index.GetNodeType());
                        indexerVars.Add(local);

                        // Process the next.
                        index = index.GetNext();
                    }
                    node.SetIndexerVariables(indexerVars);

                    // Store the scope.
                    node.SetScope(scope);
                }
            }
            else
            {
                // Check for declaration compatibility.
                if(flags != property.GetAccessor.GetFlags())
                    Error(node, "incompatible get accessor declarations.");
            }

            // Set the node function to the accessor.
            node.SetFunction(property.GetAccessor);

            return node;
        }
Ejemplo n.º 3
0
        public override AstNode Visit(GetAccessorDefinition node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Get the function.
            Function function = node.GetFunction();

            // Ignore declarations.
            if(node.GetChildren() == null)
                return builder.EndNode();

            // Store the old function.
            Function oldFunction = currentFunction;
            currentFunction = function;

            // Get and update the lexical scope.
            LexicalScope topScope = (LexicalScope)node.GetScope();
            PushScope(topScope);

            // Create the top basic block.
            BasicBlock topBlock = CreateBasicBlock();
            topBlock.SetName("top");
            builder.SetBlock(topBlock);

            // Prepare returning, required by exception handling.
            PrepareReturning(node, function, topScope);

            // Store the indices in local variables.
            int index = function.IsStatic() ? 0 : 1;
            foreach(LocalVariable indexLocal in node.GetIndexerVariables())
            {
                builder.CreateLoadArg((byte)index++);
                builder.CreateStoreLocal(indexLocal);
            }

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

            // Finish return.
            FinishReturn(node, function);

            // Restore the scope.
            PopScope();

            // Restore the current function.
            currentFunction = oldFunction;

            return builder.EndNode();
        }
Ejemplo n.º 4
0
        public override AstNode Visit(GetAccessorDefinition node)
        {
            // Get the function.
            Function function = node.GetFunction();
            if(node.GetChildren() == null)
                return node;

            // Store the definition node in the function.
            if(function.DefinitionNode != null)
                Error(node, "multiples definition of a function.");
            function.DefinitionNode = node;

            // Store the old function.
            Function oldFunction = currentFunction;
            currentFunction = function;

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

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

            // Restore the scope.
            PopScope();

            // Restore the current function.
            currentFunction = oldFunction;

            return node;
        }