public static void ValidateTypeNameVariance(this INameReference @this, ComputationContext ctx, VarianceMode typeNamePosition)
 {
     if ([email protected](ctx, @this, typeNamePosition))
     {
         ctx.AddError(ErrorCode.VarianceForbiddenPosition, @this);
     }
 }
Beispiel #2
0
 public static FunctionBuilder CreateDeclaration(
     string name,
     ExpressionReadMode callMode,
     INameReference result)
 {
     return(Create(name, callMode, result, (Block)null));
 }
Beispiel #3
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));
        }
Beispiel #4
0
        public static IExpression CreateForEach(string varName, INameReference varTypeName, IExpression iterable,
                                                IEnumerable <IExpression> body)
        {
            string iter_name = AutoName.Instance.CreateNew("iter");
            VariableDeclaration iter_decl = VariableDeclaration.CreateStatement(iter_name, null,
                                                                                FunctionCall.Create(NameReference.Create(iterable, NameFactory.IterableGetIterator)));

            IExpression condition;

            if (varName == NameFactory.Sink)
            {
                condition = ExpressionFactory.OptionalAssignment(NameFactory.SinkReference(),
                                                                 FunctionCall.Create(NameReference.Create(iter_name, NameFactory.IteratorNext)));
            }
            else
            {
                string elem_name = AutoName.Instance.CreateNew("elem");
                body = VariableDeclaration.CreateStatement(varName, varTypeName,
                                                           NameReference.Create(elem_name))
                       .Concat(body);

                condition = ExpressionFactory.OptionalDeclaration(elem_name, varTypeName,
                                                                  FunctionCall.Create(NameReference.Create(iter_name, NameFactory.IteratorNext)));
            }

            return(create(null, new[] { iter_decl },
                          preCondition: condition,
                          body: body,
                          postStep: null, postCondition: null));
        }
Beispiel #5
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();
        }
Beispiel #6
0
 public static FunctionDefinition CreateAutoGetter(string autoFieldName,
                                                   INameReference typeName, EntityModifier modifier = null)
 {
     return(CreateGetter(typeName,
                         Block.CreateStatement(Return.Create(NameReference.CreateThised(autoFieldName))),
                         EntityModifier.AutoGenerated | modifier));
 }
Beispiel #7
0
        public override void Evaluate(ComputationContext ctx)
        {
            // in theory we would like to write legal code like
            // (*local_int_ptr) = 1
            // but the problem is dereference can be seen as omitting setter (property or special functions) logic
            // so for now we disable it, and see when for the first time it will be needed in practice
            // note: swap function does not count since we already have parallel assignments
            //
            // and one more small thing, without dereference there is no ambiguity here
            // ref = value
            // does it mean (*ref) = value or ref = &value
            if (!ctx.Env.Options.AllowDereference)
            {
                throw new InvalidOperationException();
            }

            if (this.Evaluation == null)
            {
                if (!ctx.Env.Dereferenced(Expr.Evaluation.Components, out IEntityInstance inner_comp))
                {
                    ctx.AddError(ErrorCode.DereferencingValue, this.Expr);
                }

                ctx.Env.Dereferenced(Expr.Evaluation.Aggregate, out IEntityInstance inner_aggr);

                this.typename = inner_comp.NameOf;
                this.typename.AttachTo(this);
                this.typename.Evaluated(ctx, EvaluationCall.AdHocCrossJump);

                this.Evaluation = EvaluationInfo.Create(inner_comp, inner_aggr.Cast <EntityInstance>());
            }
        }
Beispiel #8
0
 public static FunctionBuilder Create(
     string name,
     IEnumerable <TemplateParameter> nameParameters,
     INameReference result,
     Block body)
 {
     return(Create(name, nameParameters, ExpressionReadMode.ReadRequired, result, body));
 }
Beispiel #9
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));
 }
Beispiel #10
0
 public static Property Create(IOptions options, string name,
                               INameReference typeName,
                               IEnumerable <VariableDeclaration> fields,
                               IEnumerable <FunctionDefinition> getters,
                               IEnumerable <FunctionDefinition> setters,
                               EntityModifier modifier = null)
 {
     return(new Property(options, modifier, name, null, typeName, fields, getters, setters));
 }
Beispiel #11
0
 public static FunctionBuilder Create(
     string name,
     string nameParameter,
     VarianceMode variance,
     INameReference result,
     Block body)
 {
     return(Create(name, TemplateParametersBuffer.Create(variance, nameParameter).Values, result, body));
 }
Beispiel #12
0
        public void AddReference(INameReference reference)
        {
            if (reference != null)
            {
                m_referenceTable.Add(reference);

                OuterField?.AddReference(reference);
            }
        }
Beispiel #13
0
 public static FunctionDefinition CreateIndexerGetter(INameReference propertyTypeName,
                                                      IEnumerable <FunctionParameter> parameters, EntityModifier modifier, Block body)
 {
     return(FunctionBuilder.Create(NameFactory.PropertyGetter,
                                   ExpressionReadMode.ReadRequired, propertyTypeName,
                                   body)
            .SetModifier(EntityModifier.Accessor | modifier)
            .Parameters(parameters));
 }
Beispiel #14
0
 public static void ValidateHeapTypeName(this INameReference typeName, ComputationContext ctx, IOwnedNode errorNode = null)
 {
     if (typeName.Evaluation.Components.EnumerateAll()
         .Where(it => !ctx.Env.IsPointerOfType(it) && !ctx.Env.IsReferenceOfType(it))
         .Any(it => it.TargetType.Modifier.HasHeapOnly))
     {
         ctx.AddError(ErrorCode.HeapTypeAsValue, errorNode ?? typeName);
     }
 }
Beispiel #15
0
        public bool IsExactlySame(INameReference other, EntityInstance translationTemplate, bool jokerMatchesAll)
        {
            if (!jokerMatchesAll)
            {
                return(this == other);
            }

            return(hasSymmetricRelation(other, (a, b) => a.IsExactlySame(b, translationTemplate, jokerMatchesAll)));
        }
Beispiel #16
0
 internal static FunctionDefinition CreateGetter(INameReference typeName, Block body, EntityModifier modifier = null)
 {
     return(FunctionDefinition.CreateFunction(EntityModifier.Accessor | modifier, NameDefinition.Create(NameFactory.PropertyGetter),
                                              null,
                                              null,
                                              ExpressionReadMode.ReadRequired,
                                              typeName,
                                              body));
 }
Beispiel #17
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));
 }
Beispiel #18
0
 public static FunctionBuilder Create(
     string name,
     INameReference result,
     Block body)
 {
     return(new FunctionBuilder(name, null, null, ExpressionReadMode.ReadRequired,
                                result,
                                body));
 }
Beispiel #19
0
 public static Property CreateIndexer(IOptions options,
                                      INameReference typeName,
                                      IEnumerable <VariableDeclaration> fields,
                                      IEnumerable <FunctionDefinition> getters,
                                      IEnumerable <FunctionDefinition> setters,
                                      EntityModifier modifier = null)
 {
     return(Create(options, NameFactory.PropertyIndexerName, typeName, fields, getters, setters, modifier));
 }
Beispiel #20
0
 private void AddTypeSigReference(TypeSig typeSig, INameReference<IDnlibDef> reference)
 {
     foreach (ITypeDefOrRef type in typeSig.FindTypeRefs()) {
         TypeDef typeDef = type.ResolveTypeDefThrow();
         if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) {
             service.ReduceRenameMode(typeDef, RenameMode.Letters);
             service.AddReference(typeDef, reference);
         }
     }
 }
Beispiel #21
0
 public static FunctionDefinition CreateSetter(INameReference typeName, Block body, EntityModifier modifier = null)
 {
     return(FunctionDefinition.CreateFunction(EntityModifier.Accessor | modifier | EntityModifier.Mutable,
                                              NameDefinition.Create(NameFactory.PropertySetter),
                                              null,
                                              new[] { FunctionParameter.Create(NameFactory.PropertySetterValueParameter, typeName) },
                                              ExpressionReadMode.OptionalUse,
                                              NameFactory.UnitNameReference(),
                                              body));
 }
Beispiel #22
0
        private ReinterpretType(IExpression lhs, INameReference rhsTypeName)
            : base(ExpressionReadMode.ReadRequired)
        {
            this.Lhs         = lhs;
            this.RhsTypeName = rhsTypeName;

            this.attachPostConstructor();

            this.flow = Later.Create(() => ExecutionFlow.CreatePath(Lhs));
        }
Beispiel #23
0
 private VariableBuilder(ExpressionReadMode readMode,
                         string name,
                         INameReference typeName,
                         IExpression initValue)
 {
     this.name      = name;
     this.readMode  = readMode;
     this.typeName  = typeName;
     this.initValue = initValue;
 }
Beispiel #24
0
        public void AddReference(INameReference reference)
        {
            if (reference != null)
            {
                m_referenceTable.Add(reference);

                if (this.OuterField != null)
                {
                    this.OuterField.AddReference(reference);
                }
            }
        }
Beispiel #25
0
 private void AddTypeSigReference(TypeSig typeSig, INameReference <IDnlibDef> reference)
 {
     foreach (ITypeDefOrRef type in typeSig.FindTypeRefs())
     {
         TypeDef typeDef = type.ResolveTypeDefThrow();
         if (context.Modules.Contains((ModuleDefMD)typeDef.Module))
         {
             service.ReduceRenameMode(typeDef, RenameMode.Letters);
             service.AddReference(typeDef, reference);
         }
     }
 }
Beispiel #26
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));
 }
Beispiel #27
0
        public static FunctionBuilder CreateLambda(INameReference result,
                                                   Block body,
                                                   params FunctionParameter[] parameters)
        {
            FunctionBuilder builder = FunctionBuilder.Create(NameFactory.LambdaInvoke,
                                                             ExpressionReadMode.ReadRequired, result, body);

            if (parameters.Any())
            {
                builder.Parameters(parameters);
            }
            return(builder);
        }
Beispiel #28
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));
 }
Beispiel #29
0
 public static bool TryGetSingleType(this INameReference @this, out NameReference nameReference, out EntityInstance typeInstance)
 {
     nameReference = @this as NameReference;
     if (nameReference == null)
     {
         typeInstance = null;
         return(false);
     }
     else
     {
         typeInstance = nameReference.Evaluation.Components.Cast <EntityInstance>();
         return(true);
     }
 }
Beispiel #30
0
        private FunctionCall(CallMode mode,
                             IExpression callee, IEnumerable <FunctionArgument> arguments, NameReference requestedOutcomeType)
            : base()
        {
            this.mode                     = mode;
            this.callee                   = callee;
            this.UserArguments            = (arguments ?? Enumerable.Empty <FunctionArgument>()).Indexed().StoreReadOnlyList();
            this.RequestedOutcomeTypeName = requestedOutcomeType;

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

            this.attachPostConstructor();

            this.flow = Later.Create(() => ExecutionFlow.CreatePath(UserArguments));
        }
Beispiel #31
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;
 }
        public void AddReference(INameReference reference)
        {
            if (reference != null)
            {
                m_referenceTable.Add(reference);

                if (this.OuterField != null)
                {
                    this.OuterField.AddReference(reference);
                }
            }
        }