public bool Verification(out string message)
        {
            message   = "";
            isCorrect = propertiesSystem.VerificationParametersWithEnter(TypeParameter.GetDependences(), out List <string> messages);
            string postfix = string.Format("Проверьте правильность полей: {0}", string.Join(',', messages));

            if (!Value.HasValue)
            {
                message   = String.Format("Не удалось расчитать значение параметра {0}. {1}", Designation, postfix);
                isCorrect = false;
            }
            else
            {
                if (Value.Value <= 0)
                {
                    message   = String.Format("Значение параметра {0} должно быть > 0. {1}", Designation, postfix);
                    isCorrect = false;
                }
                else if (StaticData.ConditionsForParameterForAnalysis.TryGetValue(this.TypeParameter, out Condition condition))
                {
                    if (!condition.InvokeComparison(Value.Value))
                    {
                        message   = String.Format("Значение параметра {0} должно быть {1}. {2}", Designation, condition.ErrorMessage, postfix);
                        isCorrect = false;
                    }
                }
            }
            return(isCorrect);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the list of type parameters for a generic code element.
        /// </summary>
        /// <param name="genericElement">Generic code element.</param>
        private void WriteTypeParameters(IGenericElement genericElement)
        {
            if (genericElement.TypeParameters.Count > 0)
            {
                Writer.Write(CSharpSymbol.BeginGeneric);

                for (int parameterIndex = 0; parameterIndex < genericElement.TypeParameters.Count; parameterIndex++)
                {
                    TypeParameter typeParameter = genericElement.TypeParameters[parameterIndex];
                    if (typeParameter.IsIn)
                    {
                        Writer.Write("in ");
                    }
                    else if (typeParameter.IsOut)
                    {
                        Writer.Write("out ");
                    }
                    Writer.Write(typeParameter.Name);
                    if (parameterIndex < genericElement.TypeParameters.Count - 1)
                    {
                        Writer.Write(CSharpSymbol.AliasSeparator);
                        Writer.Write(' ');
                    }
                }

                Writer.Write(CSharpSymbol.EndGeneric);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes the type parameter constraints.
        /// </summary>
        /// <param name="typeParameter">The type parameter.</param>
        private void WriteTypeParameterConstraints(TypeParameter typeParameter)
        {
            if (typeParameter.Constraints.Count > 0)
            {
                Writer.Write(' ');
                Writer.Write(VBKeyword.As);
                Writer.Write(' ');

                if (typeParameter.Constraints.Count > 1)
                {
                    Writer.Write(VBSymbol.BeginTypeConstraintList);
                }

                for (int constraintIndex = 0; constraintIndex < typeParameter.Constraints.Count;
                     constraintIndex++)
                {
                    string constraint = typeParameter.Constraints[constraintIndex];
                    Writer.Write(constraint);

                    if (constraintIndex < typeParameter.Constraints.Count - 1)
                    {
                        Writer.Write(VBSymbol.AliasSeparator);
                        Writer.Write(' ');
                    }
                }

                if (typeParameter.Constraints.Count > 1)
                {
                    Writer.Write(VBSymbol.EndTypeConstraintList);
                }
            }
        }
Ejemplo n.º 4
0
        public static ParameterBase[] GetParameters(ParsingData parser, ParameterDefineNode[] defineNodes)
        {
            ParameterBase[] parameters = new ParameterBase[defineNodes.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                EnumData    enumData = null;
                DefinedType type     = null;
                if (defineNodes[i].Type != null)
                {
                    enumData = EnumData.GetEnum(defineNodes[i].Type);
                    type     = parser.GetDefinedType(defineNodes[i].Type, null);

                    if (enumData == null && type == null)
                    {
                        throw SyntaxErrorException.NonexistentType(defineNodes[i].Type, defineNodes[i].Location);
                    }
                }

                if (enumData != null)
                {
                    parameters[i] = new EnumParameter(defineNodes[i].VariableName, enumData.Type);
                }

                else if (type != null)
                {
                    parameters[i] = new TypeParameter(defineNodes[i].VariableName, type);
                }

                else
                {
                    parameters[i] = new Parameter(defineNodes[i].VariableName, Elements.ValueType.Any, null);
                }
            }
            return(parameters);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes the type parameters.
        /// </summary>
        /// <param name="genericElement">The generic element.</param>
        private void WriteTypeParameters(IGenericElement genericElement)
        {
            if (genericElement.TypeParameters.Count > 0)
            {
                Writer.Write(VBSymbol.BeginParameterList);

                Writer.Write(VBKeyword.Of);
                Writer.Write(' ');

                for (int parameterIndex = 0; parameterIndex < genericElement.TypeParameters.Count; parameterIndex++)
                {
                    TypeParameter typeParameter = genericElement.TypeParameters[parameterIndex];
                    Writer.Write(typeParameter.Name);

                    WriteTypeParameterConstraints(typeParameter);

                    if (parameterIndex < genericElement.TypeParameters.Count - 1)
                    {
                        Writer.Write(VBSymbol.AliasSeparator);
                        Writer.Write(' ');
                    }
                }

                Writer.Write(VBSymbol.EndParameterList);
            }
        }
Ejemplo n.º 6
0
 public Argument(string name, string defaultValue, bool hasDefaultValue, TypeParameter type)
 {
     Name            = name;
     DefaultValue    = defaultValue;
     HasDefaultValue = hasDefaultValue;
     Type            = type;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Function Declartion
 /// </summary>
 public FunctionDeclaration VisitFunctionDeclaration()
 {
     Labels.Clear();
     if (TokenType == TokenType.Identifier)
     {
         ReadVariableName(out string name);
         MoveNext();
         NodeList <TypeParameter> parameterList;
         //return type
         TypeParameter[] parameters = new TypeParameter[0];
         if (TokenType == TokenType.LeftParenthesis)
         {
             parameters = VisitFunctionParameters().ToArray();
         }
         parameterList = new NodeList <TypeParameter>(parameters);
         //todo throw if other
         MoveNextIf(TokenType.RightParenthesis);
         TypeSyntax returnType = null;
         if (TokenType == TokenType.Colon)
         {
             MoveNext();
             returnType = VisitType();
         }
         //todo abstract, virtual functions
         //To avoid block function
         BlockStatement body = VisitBlock();
         return(new FunctionDeclaration(name, parameterList, returnType, body));
     }
     throw new System.Exception($"Syntax error at line {Source.LineInfo}");
 }
Ejemplo n.º 8
0
        private TypeParameter getTypeParameter(string prepType, int paramId)
        {
            switch (prepType)
            {
            case "Линейная нормализация 1 (к float)":
                return(TypeParameter.Real);

            case "Нелинейная нормализация 2 (к float)":
                return(TypeParameter.Real);

            case "нормализация 3 (к int)":
                return(TypeParameter.Int);

            case "бинаризация":
                return(TypeParameter.Int);

            case "без предобработки":
                models.Parameter param = ((models.Parameter)services.DatabaseManager.SharedManager.entityById(paramId, typeof(models.Parameter)));
                TypeParameter    type  = param.Type;
                return(type);

            default:
                return(TypeParameter.Real);
            }
        }
Ejemplo n.º 9
0
			public override object VisitMethodDeclaration (ICSharpCode.NRefactory.Ast.MethodDeclaration methodDeclaration, object data)
			{
				DomMethod method = new DomMethod ();
				method.Name = methodDeclaration.Name;
				method.Documentation = RetrieveDocumentation (methodDeclaration.StartLocation.Line);
				method.Location = ConvertLocation (methodDeclaration.StartLocation);
				method.BodyRegion = ConvertRegion (methodDeclaration.EndLocation, methodDeclaration.Body != null ? methodDeclaration.Body.EndLocation : new ICSharpCode.NRefactory.Location (-1, -1));
				method.Modifiers = ConvertModifiers (methodDeclaration.Modifier);
				if (methodDeclaration.IsExtensionMethod)
					method.MethodModifier |= MethodModifier.IsExtension;
				method.ReturnType = ConvertReturnType (methodDeclaration.TypeReference);
				AddAttributes (method, methodDeclaration.Attributes);
				method.Add (ConvertParameterList (method, methodDeclaration.Parameters));
				AddExplicitInterfaces (method, methodDeclaration.InterfaceImplementations);

				if (methodDeclaration.Templates != null && methodDeclaration.Templates.Count > 0) {
					foreach (ICSharpCode.NRefactory.Ast.TemplateDefinition template in methodDeclaration.Templates) {
						TypeParameter parameter = ConvertTemplateDefinition (template);
						method.AddTypeParameter (parameter);
					}
				}
				method.DeclaringType = typeStack.Peek ();
				typeStack.Peek ().Add (method);
				return null;
			}
Ejemplo n.º 10
0
 public Argument(string name, string defaultValue, bool hasDefaultValue, TypeParameter type)
 {
     Name = name;
     DefaultValue = defaultValue;
     HasDefaultValue = hasDefaultValue;
     Type = type;
 }
Ejemplo n.º 11
0
        public static TypeParameter ReadTypeParameter(BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable)
        {
            string        name = ReadString(reader, nameTable);
            TypeParameter tp   = new TypeParameter(name);

            // Flags
            tp.TypeParameterModifier = (TypeParameterModifier)reader.ReadByte();

            // Variance

            tp.Variance = (TypeParameterVariance)reader.ReadByte();

            // Constraints

            uint count = ReadUInt(reader, 1000);

            while (count-- > 0)
            {
                tp.AddConstraint(ReadReturnType(reader, nameTable, objectTable));
            }

            // Attributes

            count = ReadUInt(reader, 1000);
            while (count-- > 0)
            {
                tp.AddAttribute(ReadAttribute(reader, nameTable, objectTable));
            }

            return(tp);
        }
Ejemplo n.º 12
0
        protected override async Task <TypeParameter> AssignUpsertedReferences(TypeParameter record)
        {
            record.Identifier = await _identifiers.UpsertAsync(record.Identifier);

            record.IdentifierId = record.Identifier?.IdentifierId ?? record.IdentifierId;
            return(record);
        }
Ejemplo n.º 13
0
        public List <TypeParameter> ParseVariantTypeParameterList(
            BufferedTokenStream tokenStream,
            CSharpParser.Variant_type_parameterContext[] variantTypeParameters,
            CSharpParser.Type_parameter_constraints_clauseContext[] constraintsClauses)
        {
            var typeParamList = new List <TypeParameter>();

            var typeParamDict = new Dictionary <string, TypeParameter>();

            if (variantTypeParameters != null)
            {
                foreach (var variantTypeParameter in variantTypeParameters)
                {
                    var typeParam = variantTypeParameter.identifier().GetText();

                    var typeParameter = new TypeParameter()
                    {
                        TypeParam          = typeParam,
                        VarianceAnnotation = variantTypeParameter?.variance_annotation()?.GetText()
                    };

                    typeParamDict.Add(typeParam, typeParameter);
                    typeParamList.Add(typeParameter);
                }
            }

            if (constraintsClauses != null)
            {
                foreach (var constraintClause in constraintsClauses)
                {
                    var identifier    = constraintClause.identifier().GetText();
                    var typeParameter = typeParamDict[identifier];
                    var constraints   = constraintClause.type_parameter_constraints();

                    var primaryConstraint = constraints?.primary_constraint()?.GetText();
                    if (primaryConstraint != null)
                    {
                        typeParameter.Constraints.Add(primaryConstraint);
                    }

                    var secondaryConstraints = constraints?.secondary_constraints()?.secondary_constraint();
                    if (secondaryConstraints != null)
                    {
                        foreach (var secondaryConstraint in secondaryConstraints)
                        {
                            typeParameter.Constraints.Add(secondaryConstraint.GetText());
                        }
                    }

                    var constructorConstraint = constraints?.constructor_constraint()?.GetText();
                    if (constructorConstraint != null)
                    {
                        typeParameter.Constraints.Add(constructorConstraint);
                    }
                }
            }

            return(typeParamList);
        }
Ejemplo n.º 14
0
 public ArchiveParameter(models.Parameter par)
 {
     this.ID       = par.ID;
     this.Name     = par.Name;
     this.Index    = par.Index;
     this.Type     = par.Type;
     this.Comment  = par.Comment;
     this.IsOutput = par.IsOutput;
 }
 public Parameter(archive.ArchiveParameter par)
 {
     this.nameTable = "Parameter";
     this.Name      = par.Name;
     this.Index     = par.Index;
     this.Type      = par.Type;
     this.Comment   = par.Comment;
     this.IsOutput  = par.IsOutput;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Appends the specified parameter to the list of type parameters.
 ///
 /// <param name="p">a type parameter</param>
 /// </summary>
 public void add_type_parameter(TypeParameter p)
 {
     if (type_parameters == null)
     {
         type_parameters = new List <TypeParameter>();
     }
     type_parameters.Add(p);
     scope.add(p.name, p);
 }
Ejemplo n.º 17
0
 private TypeParamNode ToTypeParamNode(TypeParameter tp, DocComment dc)
 {
     Console.WriteLine("Type parameter: " + tp.Name);
     return(new TypeParamNode {
         Name = tp.Name,
         UserDoc = dc == null || dc.TypeParamTags == null ? null : dc.TypeParamTags[tp.Name],
         Token = ToTokenNode(tp.tok),
     });
 }
        public List <TypeParameter> GetTypeParameterList()
        {
            var typeParameter  = new TypeParameter(GetSymbolAtom(), PrimitiveType.NumberType, DefaultLineInfo);
            var typeParameter2 = new TypeParameter(GetSymbolAtom(), PrimitiveType.StringType, DefaultLineInfo);

            return(new List <TypeParameter> {
                typeParameter, typeParameter2
            });
        }
Ejemplo n.º 19
0
        private void btn_Enter_Click(object sender, EventArgs e)
        {
            DateTime newtime   = t_NewTime.Value;
            int      partition = GetSelectedPartition();

            if (_mCardInfo != null)
            {
                _mCardInfo.CardTime      = newtime;
                _mCardInfo.CardPartition = partition;
                TypeParameter typeparameter = new TypeParameter()
                {
                    Lock     = _mCardInfo.CardLock,
                    Distance = _mCardInfo.CardDistance
                };

                FunctionByteParameter functionbyteparameter = new FunctionByteParameter()
                {
                    Loss                = _mCardInfo.CardReportLoss,
                    Synchronous         = _mCardInfo.Synchronous,
                    RegistrationType    = (CardType)_mCardInfo.CardType,
                    ViceCardCount       = _mCardInfo.ViceCardCount,
                    ParkingRestrictions = _mCardInfo.ParkingRestrictions,
                    InOutState          = _mCardInfo.InOutState
                };

                DistanceParameterContent distancecontent = new DistanceParameterContent()
                {
                    CardNumber = _mCardInfo.CardNumber,
                    Type       = typeparameter,
                    Function   = functionbyteparameter,
                    Count      = ++_mCardInfo.CardCount
                };
                SingleCardData singlecarddata = new SingleCardData()
                {
                    Time      = _mCardInfo.CardTime,
                    Partition = _mCardInfo.CardPartition
                };
                byte[] by = DataCombination.CombinationDistanceCard(distancecontent, singlecarddata);
                if (_mPort.IsOpen)
                {
                    _mPort.Write(by);
                }
            }
            else
            {
                DelayParamValue param = new DelayParamValue()
                {
                    DelayTime = newtime,
                    Partition = partition
                };
                this.Tag = param;
                Close();
            }
        }
Ejemplo n.º 20
0
        public override DataType infer_type_argument(TypeParameter type_param, DataType value_type)
        {
            var array_type = value_type as ArrayType;

            if (array_type != null)
            {
                return(element_type.infer_type_argument(type_param, array_type.element_type));
            }

            return(null);
        }
Ejemplo n.º 21
0
        public void CreateTest()
        {
            TypeParameter typeParameter = new TypeParameter();

            //
            // Verify default values.
            //
            Assert.AreEqual(string.Empty, typeParameter.Name, "Unexpected default value for name.");
            Assert.IsNotNull(typeParameter.Constraints, "Constraints collection should be instantiated.");
            Assert.AreEqual(0, typeParameter.Constraints.Count, "Constraints collection should be empty.");
        }
Ejemplo n.º 22
0
        public override DataType infer_type_argument(TypeParameter type_param, DataType value_type)
        {
            if (type_parameter == type_param)
            {
                var ret = value_type.copy();
                ret.value_owned = true;
                return(ret);
            }

            return(null);
        }
Ejemplo n.º 23
0
        public override DataType infer_type_argument(TypeParameter type_param, DataType value_type)
        {
            var pointer_type = value_type as PointerType;

            if (pointer_type != null)
            {
                return(base_type.infer_type_argument(type_param, pointer_type.base_type));
            }

            return(null);
        }
Ejemplo n.º 24
0
        public List <List <Object> > getListValues(int selectionId)
        {
            Selection     selection      = ((Selection)dms.services.DatabaseManager.SharedManager.entityById(selectionId, typeof(Selection)));
            int           taskTemplateId = selection.ID;
            List <Entity> parameters     = dms.models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                       .addCondition("TaskTemplateID", "=", taskTemplateId.ToString()), typeof(dms.models.Parameter));
            List <Entity> selectionRows = SelectionRow.where (new Query("SelectionRow").addTypeQuery(TypeQuery.select)
                                                              .addCondition("SelectionID", "=", selectionId.ToString()), typeof(SelectionRow));

            List <List <Object> > values = new List <List <Object> >();

            int stepRow = 0;

            foreach (Entity selRow in selectionRows)
            {
                int selectionRowId = selRow.ID;
                int stepParam      = 0;
                foreach (Entity param in parameters)
                {
                    TypeParameter type = ((dms.models.Parameter)param).Type;

                    int           paramId = param.ID;
                    List <Entity> value   = ValueParameter.where (new Query("ValueParameter").addTypeQuery(TypeQuery.select)
                                                                  .addCondition("ParameterID", "=", paramId.ToString()).
                                                                  addCondition("SelectionRowID", "=", selectionRowId.ToString()), typeof(ValueParameter));

                    switch (type)
                    {
                    case TypeParameter.Real:
                        values[stepRow][stepParam] = Convert.ToDouble((((ValueParameter)value[0]).Value).Replace(".", ","));
                        break;

                    case TypeParameter.Int:
                        values[stepRow][stepParam] = Convert.ToInt32(((ValueParameter)value[0]).Value);
                        break;

                    case TypeParameter.Enum:
                        values[stepRow][stepParam] = ((ValueParameter)value[0]).Value;
                        break;

                    default:
                        break;
                    }

                    stepParam++;
                }
                stepRow++;
            }

            return(values);
        }
Ejemplo n.º 25
0
			TypeParameter ConvertTemplateDefinition (ICSharpCode.NRefactory.Ast.TemplateDefinition template)
			{
				TypeParameter parameter = new TypeParameter (template.Name);
				foreach (ICSharpCode.NRefactory.Ast.TypeReference typeRef in template.Bases) {
					if (typeRef.Type == "constraint: struct")
						parameter.ValueTypeRequired = true; else if (typeRef.Type == "constraint: class")
						parameter.ClassRequired = true; else if (typeRef.Type == "constraint: new")
						parameter.ConstructorRequired = true; else {
						DomReturnType rt = ConvertReturnType (typeRef);
						parameter.AddConstraint (rt);
					}
				}
				return parameter;
			}
Ejemplo n.º 26
0
        internal static KotlinTypeParameter FromProtobuf(TypeParameter vp, JvmNameResolver resolver)
        {
            if (vp is null)
            {
                return(null);
            }

            return(new KotlinTypeParameter {
                Id = vp.Id,
                Name = resolver.GetString(vp.Name),
                Reified = vp.Reified,
                Variance = (KotlinVariance)vp.variance,
                UpperBounds = vp.UpperBounds?.Select(ub => KotlinType.FromProtobuf(ub, resolver)).ToList(),
                UpperBoundsIds = vp.UpperBoundIds
            });
        }
Ejemplo n.º 27
0
 internal virtual TypeParameter[] TypeParameters()
 {
     if (TypeParametersConflict == null)
     {
         return(TypeParameter.NoParameters);
     }
     else
     {
         TypeParameter[] result = new TypeParameter[TypeParametersConflict.size()];
         int             i      = 0;
         foreach (KeyValuePair <string, TypeReference.Bound> entry in TypeParametersConflict.entrySet())
         {
             result[i++] = new TypeParameter(entry.Key, entry.Value);
         }
         return(result);
     }
 }
Ejemplo n.º 28
0
        public void CloneTest()
        {
            TypeParameter typeParameter = new TypeParameter();

            typeParameter.Name = "T";
            typeParameter.AddConstraint("IDisposable");
            typeParameter.AddConstraint("new()");

            TypeParameter clone = typeParameter.Clone() as TypeParameter;

            Assert.IsNotNull(clone, "Clone should return a TypeParameter instance.");

            Assert.AreEqual(typeParameter.Name, clone.Name, "Name property was not copied correctly.");
            Assert.AreEqual(typeParameter.Constraints.Count, clone.Constraints.Count, "Constraints property was not copied correctly.");
            Assert.AreEqual(typeParameter.Constraints[0], clone.Constraints[0], "Constraints property was not copied correctly.");
            Assert.AreEqual(typeParameter.Constraints[1], clone.Constraints[1], "Constraints property was not copied correctly.");
        }
Ejemplo n.º 29
0
        public static TypeParameter ReadTypeParameter(BinaryReader reader, INameDecoder nameTable)
        {
            string        name = ReadString(reader, nameTable);
            TypeParameter tp   = new TypeParameter(name);

            // Flags

            byte f = reader.ReadByte();

            if ((f & 1) != 0)
            {
                tp.ClassRequired = true;
            }
            if ((f & 2) != 0)
            {
                tp.ValueTypeRequired = true;
            }
            if ((f & 4) != 0)
            {
                tp.ConstructorRequired = true;
            }

            // Variance

            tp.Variance = (TypeParameterVariance)reader.ReadByte();

            // Constraints

            uint count = ReadUInt(reader, 1000);

            while (count-- > 0)
            {
                tp.AddConstraint(ReadReturnType(reader, nameTable));
            }

            // Attributes

            count = ReadUInt(reader, 1000);
            while (count-- > 0)
            {
                tp.AddAttribute(ReadAttribute(reader, nameTable));
            }

            return(tp);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Search for the type parameter in this formal type and match it in
        /// value_type.
        /// </summary>
        public virtual DataType infer_type_argument(TypeParameter type_param, DataType value_type)
        {
            var value_type_arg_it = value_type.get_type_arguments().GetEnumerator();

            foreach (var formal_type_arg in this.get_type_arguments())
            {
                if (value_type_arg_it.MoveNext())
                {
                    var inferred_type = formal_type_arg.infer_type_argument(type_param, value_type_arg_it.Current);
                    if (inferred_type != null)
                    {
                        return(inferred_type);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 31
0
 public ConstructorDeclaration VisitConstructorDeclaration()
 {
     if (TokenType == TokenType.LeftParenthesis)
     {
         NodeList <TypeParameter> parameterList;
         //return type
         TypeParameter[] parameters = new TypeParameter[0];
         if (TokenType == TokenType.LeftParenthesis)
         {
             parameters = VisitFunctionParameters().ToArray();
         }
         parameterList = new NodeList <TypeParameter>(parameters);
         //todo throw if other
         MoveNextIf(TokenType.RightParenthesis);
         //todo abstract, virtual functions
         //To avoid block function
         BlockStatement body = VisitBlock();
         return(new ConstructorDeclaration(parameterList, body));
     }
     throw new System.Exception("Syntax error at " + Source.LineInfo);
 }
Ejemplo n.º 32
0
void case_388()
#line 3218 "cs-parser.jay"
{
  	  	if (GetTokenName (yyToken) == "type")
			report.Error (81, GetLocation (yyVals[0+yyTop]), "Type parameter declaration must be an identifier not a type");
		else
			Error_SyntaxError (yyToken);
			
  	  	yyVal = new TypeParameter (MemberName.Null, null, null);
  	  }
Ejemplo n.º 33
0
		public override IType CreateInstantiatedParameterType (ITypeParameterMember typeParameterMember, TypeParameter tp)
		{
			return decorated.CreateInstantiatedParameterType (typeParameterMember, tp);
		}
Ejemplo n.º 34
0
void case_379()
#line 3532 "ps-parser.jay"
{
		var lt = (Tokenizer.LocatedToken)yyVals[0+yyTop];
		yyVal = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)yyVals[-2+yyTop], (Variance) yyVals[-1+yyTop]);
  	  }
Ejemplo n.º 35
0
void case_387()
#line 3210 "cs-parser.jay"
{
		var lt = (LocatedToken)yyVals[0+yyTop];
		var variance = (VarianceDecl) yyVals[-1+yyTop];
		yyVal = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)yyVals[-2+yyTop], variance);
		if (variance != null)
			lbag.AddLocation (yyVal, savedLocation);
  	  }
Ejemplo n.º 36
0
void case_362()
#line 2978 "cs-parser.jay"
{
		var lt = (Tokenizer.LocatedToken)yyVals[0+yyTop];
		var variance = (Variance) yyVals[-1+yyTop];
		yyVal = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)yyVals[-2+yyTop], variance);
		if (variance != Variance.None)
			lbag.AddLocation (yyVal, savedLocation);
  	  }
Ejemplo n.º 37
0
 public void VisitParameter(TypeParameter t)
 {
 }
Ejemplo n.º 38
0
 public TypeParameter CloneTypeParam(TypeParameter tp) {
   return new TypeParameter(Tok(tp.tok), tp.Name, tp.EqualitySupport, tp);
 }
Ejemplo n.º 39
0
		public DynamicSiteClass (TypeContainer parent, MemberBase host, TypeParameter[] tparams)
			: base (parent, MakeMemberName (host, "DynamicSite", parent.DynamicSitesCounter, tparams, Location.Null), tparams, Modifiers.STATIC)
		{
			parent.DynamicSitesCounter++;
		}
Ejemplo n.º 40
0
        public DynamicSiteClass(TypeContainer parent, MemberBase host, TypeParameter[] tparams)
            : base(parent, MakeMemberName (host, "DynamicSite", parent.DynamicSitesCounter, tparams, Location.Null), tparams, Modifiers.STATIC)
        {
            if (tparams != null) {
                mutator = new TypeParameterMutator (tparams, CurrentTypeParameters);
            }

            parent.DynamicSitesCounter++;
        }
Ejemplo n.º 41
0
		public virtual IType CreateInstantiatedParameterType (ITypeParameterMember typeParameterMember, TypeParameter tp)
		{
			return new InstantiatedParameterType (this, typeParameterMember, tp);
		}
		public static TypeParameter ReadTypeParameter (BinaryReader reader, INameDecoder nameTable)
		{
			string name = ReadString (reader, nameTable);
			TypeParameter tp = new TypeParameter (name);
			
			// Flags
			
			byte f = reader.ReadByte ();
			if ((f & 1) != 0)
				tp.ClassRequired = true;
			if ((f & 2) != 0)
				tp.ValueTypeRequired = true;
			if ((f & 4) != 0)
				tp.ConstructorRequired = true;

			// Variance 

			tp.Variance = (TypeParameterVariance)reader.ReadByte ();

			// Constraints
			
			uint count = ReadUInt (reader, 1000);
			while (count-- > 0)
				tp.AddConstraint (ReadReturnType (reader, nameTable));

			// Attributes
			
			count = ReadUInt (reader, 1000);
			while (count-- > 0)
				tp.AddAttribute (ReadAttribute (reader, nameTable));

			return tp;
		}
Ejemplo n.º 43
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public Comparison()
 {
     Parameter = TypeParameter.GetCurrentHeal;
     Operator = TypeOperator.LowerEqual;
     Value = 100;
 }
Ejemplo n.º 44
0
 private TypeNode ParseTypeSignature(MemoryCursor/*!*/ sigReader, ref bool pinned, ref bool isTypeArgument)
 {
     TypeNode elementType;
     ElementType tok = (ElementType)sigReader.ReadCompressedInt();
     if (tok == ElementType.Pinned)
     {
         pinned = true;
         tok = (ElementType)sigReader.ReadCompressedInt();
     }
     switch (tok)
     {
         case ElementType.Boolean: return CoreSystemTypes.Boolean;
         case ElementType.Char: return CoreSystemTypes.Char;
         case ElementType.Double: return CoreSystemTypes.Double;
         case ElementType.Int16: return CoreSystemTypes.Int16;
         case ElementType.Int32: return CoreSystemTypes.Int32;
         case ElementType.Int64: return CoreSystemTypes.Int64;
         case ElementType.Int8: return CoreSystemTypes.Int8;
         case ElementType.IntPtr: return CoreSystemTypes.IntPtr;
         case ElementType.BoxedEnum:
         case ElementType.Object: return CoreSystemTypes.Object;
         case ElementType.Single: return CoreSystemTypes.Single;
         case ElementType.String: return CoreSystemTypes.String;
         case ElementType.DynamicallyTypedReference: return CoreSystemTypes.DynamicallyTypedReference;
         case ElementType.UInt16: return CoreSystemTypes.UInt16;
         case ElementType.UInt32: return CoreSystemTypes.UInt32;
         case ElementType.UInt64: return CoreSystemTypes.UInt64;
         case ElementType.UInt8: return CoreSystemTypes.UInt8;
         case ElementType.UIntPtr: return CoreSystemTypes.UIntPtr;
         case ElementType.Void: return CoreSystemTypes.Void;
         case ElementType.Pointer:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             if (elementType == null) return null;
             return elementType.GetPointerType();
         case ElementType.Reference:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             return elementType.GetReferenceType();
         case ElementType.FunctionPointer:
             return this.ParseFunctionPointer(sigReader);
         case ElementType.OptionalModifier:
         case ElementType.RequiredModifier:
             TypeNode modifier = this.DecodeAndGetTypeDefOrRefOrSpec(sigReader.ReadCompressedInt());
             if (modifier == null) modifier = CoreSystemTypes.Object;
             TypeNode modified = this.ParseTypeSignature(sigReader, ref pinned);
             if (modified == null) modified = CoreSystemTypes.Object;
             if (modified == null || modified == null) return null;
             if (tok == ElementType.RequiredModifier)
                 return RequiredModifier.For(modifier, modified);
             else
                 return OptionalModifier.For(modifier, modified);
         case ElementType.Class:
             return this.DecodeAndGetTypeDefOrRefOrSpec(sigReader.ReadCompressedInt());
         case ElementType.ValueType:
             return this.DecodeAndGetTypeDefOrRefOrSpec(sigReader.ReadCompressedInt(), true);
         case ElementType.TypeParameter:
             TypeNode tPar = null;
             int pnum = sigReader.ReadCompressedInt();
             if (this.currentTypeParameters != null && this.currentTypeParameters.Count > pnum)
                 tPar = this.currentTypeParameters[pnum];
             if (tPar == null)
             {
                 HandleError(this.module, String.Format(CultureInfo.CurrentCulture,
                     ExceptionStrings.BadTypeParameterInPositionForType, pnum, this.currentType == null ? "" : this.currentType.FullName));
                 tPar = new TypeParameter();
                 tPar.Name = Identifier.For("Bad type parameter in position " + pnum);
                 tPar.DeclaringModule = this.module;
             }
             isTypeArgument = true;
             return tPar;
         case ElementType.MethodParameter:
             TypeNode mTPar = null;
             pnum = sigReader.ReadCompressedInt();
             if (this.currentMethodTypeParameters != null && this.currentMethodTypeParameters.Count > pnum)
                 mTPar = this.currentMethodTypeParameters[pnum];
             if (mTPar == null)
             {
                 HandleError(this.module, String.Format(CultureInfo.CurrentCulture,
                     ExceptionStrings.BadMethodTypeParameterInPosition, pnum));
                 mTPar = new MethodTypeParameter();
                 mTPar.Name = Identifier.For("Bad method type parameter in position " + pnum);
             }
             isTypeArgument = true;
             return mTPar;
         case ElementType.GenericTypeInstance:
             TypeNodeList savedCurrentTypeParameters = this.currentTypeParameters;
             TypeNode template = this.ParseTypeSignature(sigReader, ref pinned);
             this.currentTypeParameters = savedCurrentTypeParameters;
             if (template == null || template.ConsolidatedTemplateParameters == null) return template; //Likely a dummy type
             if (CoreSystemTypes.Initialized)
             {
                 if (this.currentTypeParameters == null || this.currentTypeParameters.Count == 0)
                     this.currentTypeParameters = template.ConsolidatedTemplateParameters;
                 TypeNodeList genArgs = this.ParseTypeList(sigReader);
                 if (this.module == null) return null;
                 TypeNode genInst = template.GetGenericTemplateInstance(this.module, genArgs);
                 this.currentTypeParameters = savedCurrentTypeParameters;
                 return genInst;
             }
             InterfaceExpression ifaceExpr = new InterfaceExpression(null);
             ifaceExpr.Template = template;
             ifaceExpr.Namespace = template.Namespace;
             ifaceExpr.Name = template.Name;
             ifaceExpr.TemplateArguments = this.ParseTypeList(sigReader);
             this.currentTypeParameters = savedCurrentTypeParameters;
             return ifaceExpr;
         case ElementType.SzArray:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             if (elementType == null) return null;
             return elementType.GetArrayType(1);
         case ElementType.Array:
             elementType = this.ParseTypeSignature(sigReader, ref pinned);
             if (elementType == null) elementType = CoreSystemTypes.Object;
             if (elementType == null) return null;
             int rank = sigReader.ReadCompressedInt();
             int numSizes = sigReader.ReadCompressedInt();
             int[] sizes = new int[numSizes];
             for (int i = 0; i < numSizes; i++) sizes[i] = sigReader.ReadCompressedInt();
             int numLoBounds = sigReader.ReadCompressedInt();
             int[] loBounds = new int[numLoBounds];
             for (int i = 0; i < numLoBounds; i++) loBounds[i] = sigReader.ReadCompressedInt();
             return elementType.GetArrayType(rank, numSizes, numLoBounds, sizes, loBounds);
         case ElementType.Sentinel: return null;
         case ElementType.Type: return CoreSystemTypes.Type;
         case ElementType.Enum: return this.GetTypeFromSerializedName(ReadSerString(sigReader));
     }
     throw new InvalidMetadataException(ExceptionStrings.MalformedSignature);
 }
Ejemplo n.º 45
0
        private TypeNode/*!*/ ConstructCorrectTypeNodeSubclass(int i, Identifier/*!*/ namesp, int firstInterfaceIndex, int lastInterfaceIndex,
          TypeFlags flags, InterfaceList interfaces, int baseTypeCodedIndex, bool isSystemEnum)
        {
            TypeNode result;
            TypeNode.TypeAttributeProvider attributeProvider = new TypeNode.TypeAttributeProvider(this.GetTypeAttributes);
            TypeNode.NestedTypeProvider nestedTypeProvider = new TypeNode.NestedTypeProvider(this.GetNestedTypes);
            TypeNode.TypeMemberProvider memberProvider = new TypeNode.TypeMemberProvider(this.GetTypeMembers);
            bool isTemplateParameter = false;

            if ((flags & TypeFlags.Interface) != 0)
            {
                if (isTemplateParameter)
                    result = new TypeParameter(interfaces, nestedTypeProvider, attributeProvider, memberProvider, i);
                else
                    result = new Interface(interfaces, nestedTypeProvider, attributeProvider, memberProvider, i);
            }
            else if (isTemplateParameter)
            {
                result = new ClassParameter(nestedTypeProvider, attributeProvider, memberProvider, i);
            }
            else
            {
                result = null;
                TypeNode baseClass = this.GetTypeIfNotGenericInstance(baseTypeCodedIndex);
                if (baseClass != null)
                {
                    if (baseClass == CoreSystemTypes.MulticastDelegate) //TODO: handle single cast delegates
                        result = new DelegateNode(nestedTypeProvider, attributeProvider, memberProvider, i);
                    else if (baseClass == CoreSystemTypes.Enum)
                        result = new EnumNode(nestedTypeProvider, attributeProvider, memberProvider, i);
                    else if (baseClass == CoreSystemTypes.ValueType &&
                      !(isSystemEnum && (flags & TypeFlags.Sealed) == 0))
                    {
                        result = new Struct(nestedTypeProvider, attributeProvider, memberProvider, i);
                    }
                }

                if(result == null)
                    result = new Class(nestedTypeProvider, attributeProvider, memberProvider, i);
            }

            result.Flags = flags;
            result.Interfaces = interfaces;
            return result;
        }
Ejemplo n.º 46
0
        private TypeNodeList/*!*/ ParseTypeList(MemoryCursor/*!*/ sigReader)
        {
            int n = sigReader.ReadCompressedInt();
            TypeNodeList result = new TypeNodeList();

            for(int i = 0; i < n; i++)
            {
                TypeNode t = this.ParseTypeSignature(sigReader);

                if(t == null || t == Struct.Dummy)
                {
                    // Can happen when dealing with a primitive type that implements an interface that references the primitive type.
                    // For example, System.String implements IComparable<System.String>.
                    if(this.currentType != null && !CoreSystemTypes.Initialized)
                        t = this.currentType;
                    else
                    {
                        Debug.Assert(false);
                        t = new TypeParameter();
                        t.Name = Identifier.For("Bad type parameter in position " + i);
                        t.DeclaringModule = this.module;
                    }
                }

                result.Add(t);
            }

            return result;
        }
			AstType ConvertToType (TypeParameter spec)
			{
				AstType result;
				result = new SimpleType () { IdentifierToken = Identifier.Create (spec.Name, Convert (spec.Location)) };
				return result;
			}
Ejemplo n.º 48
0
 string EqualitySupportSuffix(TypeParameter.EqualitySupportValue es) {
   if (es == TypeParameter.EqualitySupportValue.Required ||
     (es == TypeParameter.EqualitySupportValue.InferredRequired && DafnyOptions.O.DafnyPrintResolvedFile != null)) {
     return "(==)";
   } else {
     return "";
   }
 }
Ejemplo n.º 49
0
		//
		// Creates a proxy base method call inside this container for hoisted base member calls
		//
		public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
		{
			Method proxy_method;

			//
			// One proxy per base method is enough
			//
			if (hoisted_base_call_proxies == null) {
				hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
				proxy_method = null;
			} else {
				hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
			}

			if (proxy_method == null) {
				string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);

				MemberName member_name;
				TypeArguments targs = null;
				TypeSpec return_type = method.ReturnType;
				var local_param_types = method.Parameters.Types;

				if (method.IsGeneric) {
					//
					// Copy all base generic method type parameters info
					//
					var hoisted_tparams = method.GenericDefinition.TypeParameters;
					var tparams = new TypeParameters ();

					targs = new TypeArguments ();
					targs.Arguments = new TypeSpec[hoisted_tparams.Length];
					for (int i = 0; i < hoisted_tparams.Length; ++i) {
						var tp = hoisted_tparams[i];
						var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null);
						tparams.Add (local_tp);

						targs.Add (new SimpleName (tp.Name, Location));
						targs.Arguments[i] = local_tp.Type;
					}

					member_name = new MemberName (name, tparams, Location);

					//
					// Mutate any method type parameters from original
					// to newly created hoisted version
					//
					var mutator = new TypeParameterMutator (hoisted_tparams, tparams);
					return_type = mutator.Mutate (return_type);
					local_param_types = mutator.Mutate (local_param_types);
				} else {
					member_name = new MemberName (name);
				}

				var base_parameters = new Parameter[method.Parameters.Count];
				for (int i = 0; i < base_parameters.Length; ++i) {
					var base_param = method.Parameters.FixedParameters[i];
					base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location),
						base_param.Name, base_param.ModFlags, null, Location);
					base_parameters[i].Resolve (this, i);
				}

				var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
				if (method.Parameters.HasArglist) {
					cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
					cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
				}

				// Compiler generated proxy
				proxy_method = new Method (this, new TypeExpression (return_type, Location),
					Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
					member_name, cloned_params, null);

				var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) {
					IsCompilerGenerated = true
				};

				var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
				mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
				if (targs != null)
					mg.SetTypeArguments (rc, targs);

				// Get all the method parameters and pass them as arguments
				var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
				Statement statement;
				if (method.ReturnType.Kind == MemberKind.Void)
					statement = new StatementExpression (real_base_call);
				else
					statement = new Return (real_base_call, Location);

				block.AddStatement (statement);
				proxy_method.Block = block;

				members.Add (proxy_method);
				proxy_method.Define ();
				proxy_method.PrepareEmit ();

				hoisted_base_call_proxies.Add (method, proxy_method);
			}

			return proxy_method.Spec;
		}
Ejemplo n.º 50
0
		public static TypeParameter ReadTypeParameter (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable)
		{
			string name = ReadString (reader, nameTable);
			TypeParameter tp = new TypeParameter (name);
			
			// Flags
			tp.TypeParameterModifier = (TypeParameterModifier)reader.ReadByte ();
			
			// Variance 

			tp.Variance = (TypeParameterVariance)reader.ReadByte ();
			
			// Constraints
			
			uint count = ReadUInt (reader, 1000);
			while (count-- > 0)
				tp.AddConstraint (ReadReturnType (reader, nameTable, objectTable));

			// Attributes
			
			count = ReadUInt (reader, 1000);
			while (count-- > 0)
				tp.AddAttribute (ReadAttribute (reader, nameTable, objectTable));

			return tp;
		}