public static MethodNode Parse(ContextNode context, IAbstractSyntaxTree lexerNode)
        {
            Contract.Requires(lexerNode.Type == Lexer.TokenType.Function);
            var method = FunctionDeclarationNode.ParseAsFunctor(context, lexerNode);

            return(new MethodNode(method.MethodReference, null, context, method.SequencePoint));
        }
        public static FunctionDeclarationNode ParseAsFunctor(ContextNode context, IAbstractSyntaxTree function)
        {
            Contract.Requires(function.Type == Lexer.TokenType.Function);
            var instance = new FunctionDeclarationNode(context, Modifiers.NoInstance | Modifiers.Private, context.GetClass().NewFunctionName(), function);

            context.GetClass().AddLambda(instance);
            instance.Emit();
            return(instance);
        }
        private void ParseDeclaration(IAbstractSyntaxTree lexerNode)
        {
            var declaration = DeclarationInfo.Parse(Parser, lexerNode);

            if (declaration.Initializer != null && declaration.Initializer.IsFunctionDeclaration() && !declaration.Modifiers.HasFlag(Modifiers.Mutable))
            {
                //method
                var method = FunctionDeclarationNode.ParseAsMethod(this, declaration);
                declaredMethods.Add(method);
            }
            else
            {
                //field
                var field = new FieldDeclarationNode(this, declaration, Parser.GetSequencePoint(lexerNode));
                fields.Add(field);
            }
        }
        public FieldDeclarationNode(ClassNode parent, DeclarationInfo declaration, SequencePoint point)
            : base(parent.Parser, parent, point)
        {
            this.IsStatic      = true;
            this.initializer   = declaration.Initializer;
            this.Name          = declaration.SymbolName.GetSingleSymbolOrThrow();
            this.TypeReference = TypeNode.Parse(this, declaration.Type);
            this.modifiers     = declaration.Modifiers;
            this.field         = new Lazy <FieldDefinition>(() => new FieldDefinition(Name, GetAttributes(), TypeReference));

            if (TypeReference.IsAuto() && declaration.Initializer != null && declaration.Initializer.IsFunctionDeclaration())
            {
                TypeReference = FunctionDeclarationNode.ParseFunctorType(parent, declaration.Initializer);
            }

            if (!TypeReference.IsAuto())
            {
                DeclareField();
            }
        }
        public static FunctionDeclarationNode ParseAsMethod(ClassNode parent, DeclarationInfo declaration)
        {
            var instance = new FunctionDeclarationNode(parent, declaration.Modifiers, declaration.SymbolName.GetSingleSymbolOrThrow(), declaration.Initializer.Children[0]);

            return(instance);
        }
 public void AddLambda(FunctionDeclarationNode lambda)
 {
     lambdas.Add(lambda);
 }