SetEntryPoint() 공개 정적인 메소드

public static SetEntryPoint ( CompilerContext context, Method method ) : void
context CompilerContext
method Boo.Lang.Compiler.Ast.Method
리턴 void
예제 #1
0
        private void SetEntryPointIfNecessary(Method entryPoint)
        {
            if (null == entryPoint)
            {
                return;
            }

            if (Parameters.OutputType == CompilerOutputType.Library)
            {
                return;
            }

            ContextAnnotations.SetEntryPoint(Context, entryPoint);
        }
예제 #2
0
        private void DetectEntryPoint(Module module, ClassDefinition moduleClass)
        {
            var entryPoint = module.Globals.IsEmpty
                ? moduleClass.Members[EntryPointMethodName] as Method
                : TransformModuleGlobalsIntoEntryPoint(module, moduleClass);

            if (entryPoint == null)
            {
                return;
            }

            if (Parameters.OutputType == CompilerOutputType.Library)
            {
                return;
            }

            ContextAnnotations.SetEntryPoint(Context, entryPoint);
        }
예제 #3
0
        override public void OnModule(Module node)
        {
            bool            hasModuleClass = true;
            ClassDefinition moduleClass    = FindModuleClass(node);

            if (null == moduleClass)
            {
                moduleClass             = new ClassDefinition();
                moduleClass.IsSynthetic = true;
                hasModuleClass          = false;
            }

            Method entryPoint = moduleClass.Members["Main"] as Method;

            int removed = 0;

            TypeMember[] members = node.Members.ToArray();
            for (int i = 0; i < members.Length; ++i)
            {
                TypeMember member = members[i];
                if (member is TypeDefinition)
                {
                    continue;
                }
                if (member.NodeType == NodeType.Method)
                {
                    if (EntryPointMethodName == member.Name)
                    {
                        entryPoint = (Method)member;
                    }
                    member.Modifiers |= TypeMemberModifiers.Static;
                }
                node.Members.RemoveAt(i - removed);
                moduleClass.Members.Add(member);
                ++removed;
            }

            if (node.Globals.Statements.Count > 0)
            {
                Method method = new Method(node.Globals.LexicalInfo);
                method.IsSynthetic = true;
                method.Parameters.Add(new ParameterDeclaration("argv", new ArrayTypeReference(new SimpleTypeReference("string"))));
                method.ReturnType = CodeBuilder.CreateTypeReference(TypeSystemServices.VoidType);
                method.Body       = node.Globals;
                method.Name       = EntryPointMethodName;
                method.Modifiers  = TypeMemberModifiers.Static | TypeMemberModifiers.Private;
                moduleClass.Members.Add(method);

                node.Globals = null;
                entryPoint   = method;
            }

            if (null != entryPoint)
            {
                ContextAnnotations.SetEntryPoint(Context, entryPoint);
            }

            if (hasModuleClass || _forceModuleClass || (moduleClass.Members.Count > 0))
            {
                if (!hasModuleClass)
                {
                    moduleClass.Name = BuildModuleClassName(node);
                    moduleClass.Attributes.Add(CreateBooModuleAttribute());
                    node.Members.Add(moduleClass);
                }

                moduleClass.Members.Add(AstUtil.CreateConstructor(node, TypeMemberModifiers.Private));
                moduleClass.Modifiers = TypeMemberModifiers.Public |
                                        TypeMemberModifiers.Final |
                                        TypeMemberModifiers.Transient;

                ((ModuleEntity)node.Entity).InitializeModuleClass(moduleClass);
            }
        }