Exemplo n.º 1
0
        private FunctionParameter(ExpressionReadMode readMode, string name, INameReference typeName, Variadic variadic,
                                  IExpression defaultValue, EntityModifier modifier, bool isNameRequired)
        {
            this.UsageMode      = readMode;
            this.Modifier       = modifier ?? EntityModifier.None;
            this.Name           = NameDefinition.Create(name);
            this.IsNameRequired = isNameRequired;
            this.Variadic       = variadic;

            this.ElementTypeName = typeName;
            if (this.IsVariadic)
            {
                this.TypeName = NameFactory.ReferenceNameReference(NameFactory.ISequenceNameReference(this.ElementTypeName,
                                                                                                      mutability: TypeMutability.ForceMutable));
            }
            else
            {
                this.TypeName = this.ElementTypeName;
            }

            this.defaultValue = defaultValue;

            this.instancesCache = new EntityInstanceCache(this, () => GetInstance(TypeMutability.None,
                                                                                  TemplateTranslation.CreateParameterless(this), Lifetime.Timeless));

            this.attachPostConstructor();
        }
Exemplo n.º 2
0
 public static FunctionBuilder CreateDeclaration(
     string name,
     ExpressionReadMode callMode,
     INameReference result)
 {
     return(Create(name, callMode, result, (Block)null));
 }
Exemplo n.º 3
0
        private static Block constructor(ExpressionReadMode readMode, Func <Block, ExpressionReadMode> readModeCalc,
                                         IEnumerable <IExpression> instructions)
        {
            List <IExpression> body = (instructions ?? Enumerable.Empty <IExpression>()).ToList();

            return(new Block(readMode, readModeCalc, body));
        }
Exemplo n.º 4
0
        private VariableDeclaration(EntityModifier modifier, ExpressionReadMode readMode, string name,
                                    INameReference typeName,
                                    IExpression initValue,
                                    IEnumerable <LabelReference> friends = null)
            : base(readMode)
        {
            if (name == null)
            {
                throw new ArgumentNullException();
            }

            this.Modifier     = modifier ?? EntityModifier.None;
            this.Name         = NameDefinition.Create(name);
            this.TypeName     = typeName;
            this.initValue    = initValue;
            this.AccessGrants = (friends ?? Enumerable.Empty <LabelReference>()).StoreReadOnly();

            this.instancesCache = new EntityInstanceCache(this, () => GetInstance(TypeMutability.None,
                                                                                  TemplateTranslation.CreateParameterless(this), Lifetime.Timeless));

            this.closures = new List <TypeDefinition>();

            this.attachPostConstructor();

            this.flow = Later.Create(() => ExecutionFlow.CreatePath(InitValue));
        }
Exemplo n.º 5
0
        protected Literal(string inputValue, NameReference typeName, ExpressionReadMode readMode = ExpressionReadMode.ReadRequired)
            : base(readMode)
        {
            this.typeName   = typeName;
            this.InputValue = inputValue;

            this.attachPostConstructor();
        }
Exemplo n.º 6
0
        private Block(ExpressionReadMode readMode, Func <Block, ExpressionReadMode> readModeCalc, List <IExpression> body)
            : base(readModeCalc == null ? new Option <ExpressionReadMode>(readMode) : new Option <ExpressionReadMode>())
        {
            this.instructions = body;
            this.readModeCalc = readModeCalc;

            this.attachPostConstructor();
        }
Exemplo n.º 7
0
 public static FunctionParameter Create(string name, INameReference typeName, Variadic variadic,
                                        IExpression defaultValue,
                                        bool isNameRequired          = false,
                                        ExpressionReadMode usageMode = ExpressionReadMode.ReadRequired)
 {
     return(new FunctionParameter(usageMode, name, typeName,
                                  variadic, defaultValue, null, isNameRequired: isNameRequired));
 }
Exemplo n.º 8
0
 public static FunctionBuilder Create(
     string name,
     IEnumerable <TemplateParameter> nameParameters,
     ExpressionReadMode callMode,
     INameReference result,
     Block body)
 {
     return(new FunctionBuilder(name, nameParameters, null, callMode, result, body));
 }
Exemplo n.º 9
0
        protected void setReadMode(ExpressionReadMode readMode)
        {
            if (this.isReadModeSet)
            {
                throw new Exception();
            }

            this.readMode = new Option <ExpressionReadMode>(readMode);
        }
Exemplo n.º 10
0
 private VariableBuilder(ExpressionReadMode readMode,
                         string name,
                         INameReference typeName,
                         IExpression initValue)
 {
     this.name      = name;
     this.readMode  = readMode;
     this.typeName  = typeName;
     this.initValue = initValue;
 }
Exemplo n.º 11
0
 public static FunctionBuilder Create(
     string name,
     ExpressionReadMode callMode,
     INameReference result,
     Block body)
 {
     return(new FunctionBuilder(name, null, null, callMode,
                                result,
                                body));
 }
Exemplo n.º 12
0
        private static IExpression create(ExpressionReadMode readMode, IExpression lhs, IExpression rhsValue, bool isPostInitialization)
        {
            if (lhs is FunctionCall call && call.IsIndexer)
            {
                if (readMode != ExpressionReadMode.CannotBeRead)
                {
                    throw new NotImplementedException();
                }

                return(call.ConvertIndexerIntoSetter(rhsValue));
            }
Exemplo n.º 13
0
 public static FunctionBuilder CreateDeclaration(
     string name,
     string nameParameter,
     VarianceMode variance,
     ExpressionReadMode callMode,
     INameReference result)
 {
     return(new FunctionBuilder(name, TemplateParametersBuffer.Create(variance, nameParameter).Values,
                                null, callMode,
                                result,
                                (Block)null));
 }
Exemplo n.º 14
0
 public static FunctionDefinition CreateFunction(
     EntityModifier modifier,
     NameDefinition name,
     IEnumerable <TemplateConstraint> constraints,
     IEnumerable <FunctionParameter> parameters,
     ExpressionReadMode callMode,
     INameReference result,
     Block body)
 {
     return(new FunctionDefinition(modifier,
                                   name,
                                   (NameDefinition)null,
                                   constraints, parameters, callMode, result, constructorChainCall: null, body: body, includes: null, friends: null));
 }
Exemplo n.º 15
0
 private FunctionBuilder(
     string name,
     IEnumerable <TemplateParameter> nameParameters,
     IEnumerable <FunctionParameter> parameters,
     ExpressionReadMode callMode,
     INameReference result,
     Block body)
 {
     this.name           = name;
     this.nameParameters = (nameParameters ?? Enumerable.Empty <TemplateParameter>()).StoreReadOnly();
     this.parameters     = parameters;
     this.callMode       = callMode;
     this.result         = result;
     this.body           = body;
 }
Exemplo n.º 16
0
        private FunctionDefinition(EntityModifier modifier,
                                   NameDefinition name,
                                   NameDefinition label,
                                   IEnumerable <TemplateConstraint> constraints,
                                   IEnumerable <FunctionParameter> parameters,
                                   ExpressionReadMode callMode,
                                   INameReference result,
                                   FunctionCall constructorChainCall,
                                   Block body,
                                   IEnumerable <NameReference> includes,
                                   IEnumerable <LabelReference> friends)
            : base(modifier | (body == null ? EntityModifier.Abstract : EntityModifier.None), name, constraints, includes)
        {
            parameters = parameters ?? Enumerable.Empty <FunctionParameter>();

            this.Label        = label ?? NameDefinition.Create(name.Name);
            this.AccessGrants = (friends ?? Enumerable.Empty <LabelReference>()).StoreReadOnly();
            this.Parameters   = parameters.Indexed().StoreReadOnlyList();
            setResultParameter(result);
            this.IsResultTypeNameInfered = result == null;
            if (this.IsResultTypeNameInfered)
            {
                this.resultTypeCandidates = new List <IEntityInstance>();
            }
            this.UserBody = body;
            this.CallMode = callMode;

            // attaching zero-constructor call to the body of the function will be done when attaching entire function to a type
            if (constructorChainCall != null)
            {
                this.UserBody.SetConstructorChainCall(constructorChainCall);
            }

            if (this.IsLambdaInvoker)
            {
                this.LambdaTrap = new LambdaTrap();
            }

            this.attachPostConstructor();

            this.flow = Later.Create(() => ExecutionFlow.CreatePath(UserBody));
            this.constructionCompleted = true;

            if (!IsValidMutableName(this.Name.Name, this.Modifier))
            {
                throw new ArgumentException($"Mutable function has to be marked with name as well {this.Name}");
            }
        }
Exemplo n.º 17
0
 public static FunctionParameter Create(string name, INameReference typeName, EntityModifier modifier,
                                        ExpressionReadMode usageMode = ExpressionReadMode.ReadRequired)
 {
     return(new FunctionParameter(usageMode, name, typeName,
                                  Variadic.None, null, modifier, isNameRequired: false));
 }
Exemplo n.º 18
0
 public static Block Create(ExpressionReadMode readMode, IEnumerable <IExpression> body)
 {
     return(constructor(readMode, null, body));
 }
Exemplo n.º 19
0
 public static VariableDeclaration Create(ExpressionReadMode readMode, string name, INameReference typeName,
                                          IExpression initValue, EntityModifier modifier, IEnumerable <LabelReference> friends)
 {
     return(new VariableDeclaration(modifier, readMode, name, typeName, initValue, friends));
 }
Exemplo n.º 20
0
 protected Expression(ExpressionReadMode readMode) : this(new Option <ExpressionReadMode>(readMode))
 {
 }
Exemplo n.º 21
0
 public static NameReference Create(IExpression prefix, BrowseMode browse, string name, ExpressionReadMode readMode,
                                    params INameReference[] arguments)
 {
     return(new NameReference(TypeMutability.None, prefix, browse, null, name,
                              arguments.Select(it => new TemplateArgument(it)), readMode, isRoot: false));
 }