예제 #1
0
        internal override Command Build(CommandGroup parent)
        {
            var cmd = new CommandGroup
            {
                Name             = Name,
                Description      = Description,
                Aliases          = Aliases,
                ExecutionChecks  = ExecutionChecks,
                IsHidden         = IsHidden,
                Parent           = parent,
                Overloads        = new ReadOnlyCollection <CommandOverload>(Overloads.Select(xo => xo.Build()).ToList()),
                Module           = Module,
                CustomAttributes = CustomAttributes
            };

            var cs = new List <Command>();

            foreach (var xc in Children)
            {
                cs.Add(xc.Build(cmd));
            }

            cmd.Children = new ReadOnlyCollection <Command>(cs);
            return(cmd);
        }
        public IEnumerable <string> GetExtensions()
        {
            var nativeExtensions   = NativeSignatures.Select(f => f.Extension);
            var overloadExtensions = Overloads.Select(f => f.Extension);

            return(nativeExtensions.Concat(overloadExtensions).Distinct());
        }
예제 #3
0
        internal virtual Command Build(CommandGroup parent)
        {
            var cmd = new Command
            {
                Name             = Name,
                Description      = Description,
                Aliases          = Aliases,
                ExecutionChecks  = ExecutionChecks,
                IsHidden         = IsHidden,
                Parent           = parent,
                Overloads        = new ReadOnlyCollection <CommandOverload>(Overloads.Select(xo => xo.Build()).ToList()),
                Module           = Module,
                CustomAttributes = CustomAttributes
            };

            return(cmd);
        }
예제 #4
0
        internal override IEnumerable <NameExpression> Walk()
        {
            List <NameExpression> freeVars = new List <NameExpression>();

            foreach (Definition definition in Definitions)
            {
                freeVars.AddRange(definition.Walk());
            }

            DeclaredVariables = new List <Variable>();
            foreach (Definition definition in Definitions)
            {
                if (!(definition is FunctionDefinition))
                {
                    DeclaredVariables.Add(definition.DeclaredVariable);
                }
            }

            List <FunctionDefinition> functions = Definitions
                                                  .Where(statement => statement is FunctionDefinition)
                                                  .Select(statement => statement as FunctionDefinition)
                                                  .ToList();

            Overloads = Compiler.GenerateOverloads(functions);
            DeclaredVariables.AddRange(Overloads.Select(o => o.variable));

            foreach (Variable variable in DeclaredVariables)
            {
                variable.Global = true;
            }

            Compiler.MatchVariables(freeVars, DeclaredVariables);
            return(freeVars);

            // TODO: Walk the imports that refer to actual Redwood modules?
        }
 public static IEnumerable <object[]> GetOverloads() => Overloads.Select(o => new[] { (object)o });
예제 #6
0
        internal override IEnumerable <NameExpression> Walk()
        {
            Type = RedwoodType.Make(this);
            base.Walk();
            DeclaredVariable.KnownType       = RedwoodType.GetForCSharpType(typeof(RedwoodType));
            DeclaredVariable.DefinedConstant = true;
            DeclaredVariable.ConstantValue   = Type;
            List <NameExpression> freeVars     = new List <NameExpression>();
            List <Variable>       declaredVars = new List <Variable>();

            InterfaceImplicitConversionVars = new List <Variable>();
            int maxConstructorArgs = 0;

            This = new Variable
            {
                Name      = "this",
                KnownType = Type
            };
            declaredVars.Add(This);

            if (ParameterFields != null)
            {
                maxConstructorArgs = ParameterFields.Length;
                foreach (ParameterDefinition param in ParameterFields)
                {
                    freeVars.AddRange(param.Walk());
                    declaredVars.Add(param.DeclaredVariable);
                }
            }

            foreach (TypeSyntax interfaceType in Interfaces)
            {
                freeVars.AddRange(interfaceType.Walk());
                // TODO: What if we inherit an implicit, or if we
                // a function that is meant to represent this, or
                // an implicit declared function?
                InterfaceImplicitConversionVars.Add(
                    new Variable
                {
                    Name            = RuntimeUtil.GetNameOfConversionToType(interfaceType.TypeName.Name),
                    Closured        = true,
                    DefinedConstant = true
                }
                    );
            }

            foreach (LetDefinition field in InstanceFields)
            {
                freeVars.AddRange(field.Walk());
                declaredVars.Add(field.DeclaredVariable);
            }

            foreach (FunctionDefinition constructor in Constructors)
            {
                freeVars.AddRange(constructor.Walk());
                maxConstructorArgs = Math.Max(maxConstructorArgs, constructor.Parameters.Length);
            }

            TempArgumentVariables = new List <Variable>();
            for (int i = 0; i < maxConstructorArgs; i++)
            {
                TempArgumentVariables.Add(new Variable
                {
                    Temporary = true
                });
            }

            foreach (FunctionDefinition method in Methods)
            {
                freeVars.AddRange(method.Walk());
                // Closure these variables even though they aren't in the
                // object's map so that they can be directly accessed
                method.DeclaredVariable.Closured = true;
            }
            Overloads = Compiler.GenerateOverloads(Methods.ToList());
            declaredVars.AddRange(Overloads.Select(o => o.variable));

            declaredVars.AddRange(InterfaceImplicitConversionVars);
            MemberVariables = declaredVars;
            // Make sure that all of our variables end up in the closure that
            // makes up our RedwoodObject
            foreach (Variable member in declaredVars)
            {
                member.Closured = true;
            }

            // Treat the class as a closure that can be populated and then
            // updated by all methods.
            Compiler.MatchVariables(freeVars, declaredVars);

            // When it comes to static methods, we don't want to match to
            // our own instance variables.
            foreach (FunctionDefinition method in StaticMethods)
            {
                freeVars.AddRange(method.Walk());
            }
            StaticOverloads = Compiler.GenerateOverloads(StaticMethods.ToList());

            return(freeVars);
        }