private bool InitializeInternal(IParameterDeclaration parameterDeclaration)
 {
     if (!parameterDeclaration.IsCSharp3Supported())
     {
         return false;
     }
     var declaredElement = parameterDeclaration.DeclaredElement;
     if (declaredElement == null)
         return false;
     var containingNode = parameterDeclaration.GetContainingNode<IFunctionDeclaration>();
     if (containingNode == null)
         return false;
     ConstructorDeclaration = containingNode as IConstructorDeclaration;
     var constructor = containingNode.DeclaredElement as IConstructor;
     if (constructor == null || constructor.IsStatic)
     {
         return false;
     }
     Constructor = constructor;
     Type = parameterDeclaration.Type;
     ParameterDeclaration = parameterDeclaration;
     Parameter = parameterDeclaration.DeclaredElement;
     SourceFile = parameterDeclaration.GetSourceFile();
     return true;
 }
Exemplo n.º 2
0
        protected override IExpression ConvertAssign(IAssignExpression iae)
        {
            // set index variables on the converted target, using the unconverted lhs indices
            // this code is copied from ModelAnalysisTransform
            IAssignExpression     ae  = (IAssignExpression)base.ConvertAssign(iae);
            IParameterDeclaration ipd = null;
            IVariableDeclaration  ivd = Recognizer.GetVariableDeclaration(ae.Target);

            if (ivd == null)
            {
                ipd = Recognizer.GetParameterDeclaration(ae.Target);
                if (ipd == null)
                {
                    return(ae);
                }
            }
            if (iae.Target is IArrayIndexerExpression)
            {
                // Gather index variables from the left-hand side of the assignment
                object decl            = (ipd == null) ? (object)ivd : ipd;
                VariableInformation vi = VariableInformation.GetVariableInformation(context, decl);
                try
                {
                    List <IVariableDeclaration[]> indVars = new List <IVariableDeclaration[]>();
                    Recognizer.AddIndexers(context, indVars, iae.Target);
                    // Sets the size of this variable at this array depth
                    int depth = Recognizer.GetIndexingDepth(iae.Target);
                    // if this statement is actually a constraint, then we don't need to enforce matching of index variables
                    bool isConstraint = context.InputAttributes.Has <Models.Constraint>(context.FindAncestor <IStatement>());
                    for (int i = 0; i < depth; i++)
                    {
                        vi.SetIndexVariablesAtDepth(i, indVars[i], allowMismatch: isConstraint);
                    }
                }
                catch (Exception ex)
                {
                    Error(ex.Message, ex);
                }
                if (!context.InputAttributes.Has <VariableInformation>(decl))
                {
                    context.InputAttributes.Set(decl, vi);
                }
            }
            return(ae);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Define a given variable in the MSL.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="variable"></param>
 ///
 protected void BuildGiven <T>(Variable <T> variable)
 {
     if (variable.IsBase)
     {
         IParameterDeclaration ipd = (IParameterDeclaration)variable.GetDeclaration();
         modelMethod.Parameters.Add(ipd);
         FinishGivenOrConstant(variable, ipd);
         // must do this after the sizes are built
         observedVars.Add(variable);
     }
     else if (variable.IsArrayElement)
     {
         // do nothing
     }
     else
     {
         throw new NotImplementedException("Unhandled given type: " + variable);
     }
 }
Exemplo n.º 4
0
        private static int FitsOnOneLine(IParameterDeclaration expression, int remainingSpace)
        {
            var space = remainingSpace;

            space -= expression.Name.GetText().Length;
            if (space >= 0 && expression.Type != null)
            {
                space -= 2;
                space  = FitsOnOneLine(expression.Type, space);
            }

            if (space >= 0 && expression.Initializer != null)
            {
                space -= 2;
                space  = FitsOnOneLine(expression.Initializer, space);
            }

            return(space);
        }
Exemplo n.º 5
0
 public override void VisitParameterDeclarationCollection(IParameterDeclarationCollection value)
 {
     if (value.Count > 0)
     {
         _formatter.WriteKeyword("param");
         _formatter.Write("(");
         foreach (object obj in value)
         {
             IParameterDeclaration value2 = (IParameterDeclaration)obj;
             if (value.IndexOf(value2) != 0)
             {
                 _formatter.Write(", ");
             }
             VisitParameterDeclaration(value2);
         }
         _formatter.Write(")");
         _formatter.WriteLine();
         _formatter.WriteLine();
     }
 }
Exemplo n.º 6
0
        protected override IExpression ConvertAssign(IAssignExpression iae)
        {
            IParameterDeclaration ipd = null;
            IVariableDeclaration  ivd = Recognizer.GetVariableDeclaration(iae.Target);

            if (ivd == null)
            {
                ipd = Recognizer.GetParameterDeclaration(iae.Target);
                if (ipd == null)
                {
                    return(base.ConvertAssign(iae));
                }
            }
            IAssignExpression ae = (IAssignExpression)base.ConvertAssign(iae);

            if (ipd == null && !context.InputAttributes.Has <IsInferred>(ivd))
            {
                // assignment to a local variable
                if (ae.Expression is ILiteralExpression)
                {
                    bool isLoopInitializer = (Recognizer.GetAncestorIndexOfLoopBeingInitialized(context) != -1);
                    if (!isLoopInitializer)
                    {
                        Type valueType = ae.Expression.GetExpressionType();
                        if (Quoter.ShouldInlineType(valueType))
                        {
                            // inline all future occurrences of this variable with the rhs expression
                            conditionContext.Add(new ConditionBinding(ae.Target, ae.Expression));
                        }
                    }
                }
            }
            else
            {
                // assignment to a method parameter
            }
            return(ae);
        }
Exemplo n.º 7
0
        private bool ComputeAvailability(out IParameterDeclaration parameterDeclaration,
                                         out ICSharpFunctionDeclaration functionToInsertPrecondition)
        {
            functionToInsertPrecondition = null;

            parameterDeclaration = _provider.GetSelectedParameterDeclaration();

            if (parameterDeclaration == null)
            {
                return(false);
            }

            if (!IsEnum(parameterDeclaration) && !IsNullableEnum(parameterDeclaration))
            {
                return(false);
            }

            if (!ContractFunctionIsWellDefinedAndDidntContainPrecondition(parameterDeclaration.DeclaredName, out functionToInsertPrecondition))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
 private IntroduceAndInitializePrivateAutoPropertyFix(IParameterDeclaration parameterDeclaration)
 {
     Context.Initialize(parameterDeclaration);
 }
        ParameterContractInfo(ContractKind contractKind, [NotNull] IParameterDeclaration declaration, [NotNull] IType type) : base(contractKind, type)
        {
            Debug.Assert(
                contractKind == ContractKind.Requires || contractKind == ContractKind.Ensures || contractKind == ContractKind.RequiresAndEnsures);

            this.declaration = declaration;
        }
Exemplo n.º 10
0
 public virtual void VisitParameterDeclaration(IParameterDeclaration value)
 {
     this.VisitCustomAttributeCollection(value.Attributes);
     this.VisitType(value.ParameterType);
 }
Exemplo n.º 11
0
 private bool AreParameterSignaturesEquivalent(ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.ParameterDeclaration parameter, IParameterDeclaration unmatched)
 {
     if (unmatched.Name != parameter.Name)
     {
         return(false);
     }
     return(this.AreTypesEquivalent(unmatched.ParameterType, parameter.ParameterType));
 }
        /// <summary>
        /// Creates a parameter node.
        /// </summary>
        /// <param name="xmlNode">
        /// The <see cref="XmlNode"/> to create the parameter against.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// <see cref="XmlNode"/>of the created parameter.
        /// </returns>
        private static XmlNode CreateParamNode(XmlNode xmlNode, IParameterDeclaration parameter)
        {
            Param.RequireNotNull(xmlNode, "xmlNode");

            string parameterName = parameter.DeclaredName;

            XmlNode newNode = CreateNode(xmlNode, "param");
            XmlAttribute newAttribute = xmlNode.OwnerDocument.CreateAttribute("name");

            newAttribute.Value = parameterName;

            string innerText = string.Empty;

            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, parameter.GetSolution());
            if (settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation))
            {
                innerText = string.Format("The {0}.", Utils.ConvertTextToSentence(parameterName));
            }

            XmlText innerChildTextNode = xmlNode.OwnerDocument.CreateTextNode(innerText);

            newNode.AppendChild(innerChildTextNode);
            newNode.Attributes.Append(newAttribute);

            return newNode;
        }
Exemplo n.º 13
0
 private string FormatParameter(IParameterDeclaration parameter)
 {
     return(TypeNameFormatter.FormatTypeForCSharp(parameter.ParameterType, true) + " " + parameter.Name);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Declares a type with a specific name.
        /// </summary>
        /// <param name="name">The name of the declared type.</param>
        /// <returns>A type declaration.</returns>
        private ITypeDeclaration CreateTypeDeclaration(string name)
        {
            ITypeDeclaration td = builder.TypeDecl();

            td.Visibility = TypeVisibility.Public;
            td.Namespace  = "TestNameSpace";
            td.Interface  = false;
            td.Name       = name;

            // Derive from an interface
            td.Interfaces.Add((ITypeReference)builder.TypeRef(typeof(ICloneable)));

            // Add some methods
            IParameterDeclaration parm1 = builder.Param("val", typeof(int));
            IMethodDeclaration    meth1 = builder.MethodDecl(MethodVisibility.Public, "MyMethod", typeof(int), td, parm1);
            IMethodDeclaration    meth2 = builder.MethodDecl(MethodVisibility.Public, "Clone", typeof(object), td);
            IMethodDeclaration    meth3 = builder.MethodDecl(MethodVisibility.Public, "ThrowMethod", typeof(void), td);
            IBlockStatement       im1bs = builder.BlockStmt();
            IBlockStatement       im2bs = builder.BlockStmt();
            IBlockStatement       im3bs = builder.BlockStmt();

            im1bs.Statements.Add(builder.Return(builder.ParamRef(parm1)));
            meth1.Body = im1bs;
            im2bs.Statements.Add(builder.Return(builder.LiteralExpr(null)));
            meth2.Body = im2bs;
            im3bs.Statements.Add(builder.ThrowStmt(builder.NewObject(typeof(InferCompilerException))));
            meth3.Body = im3bs;
            td.Methods.Add(meth1);
            td.Methods.Add(meth2);
            td.Methods.Add(meth3);

            IGenericParameter         gp1 = builder.GenericTypeParam("T1");
            IGenericParameter         gp2 = builder.GenericTypeParam("T2");
            IList <IGenericParameter> gps = new List <IGenericParameter>();

            gps.Add(gp1);
            gps.Add(gp2);
            IParameterDeclaration gparm1 = builder.Param("parm1", gp1);
            IParameterDeclaration gparm2 = builder.Param("parm2", gp2);
            IMethodDeclaration    meth4  = builder.GenericMethodDecl(
                MethodVisibility.Public, "MyGenericMethod", gp1, td, gps, gparm1, gparm2);
            IBlockStatement im4bs = builder.BlockStmt();

            im4bs.Statements.Add(builder.Return(builder.ParamRef(gparm1)));
            meth4.Body = im4bs;
            td.Methods.Add(meth4);

            // Add some properties
            IPropertyDeclaration prop1 = builder.PropDecl("MyIntProperty", typeof(int), td, MethodVisibility.Public);
            IPropertyDeclaration prop2 = builder.PropDecl("MyObjProperty", typeof(object), td, MethodVisibility.Public);
            IBlockStatement      ip1bs = builder.BlockStmt();
            IBlockStatement      ip2bs = builder.BlockStmt();

            ip1bs.Statements.Add(builder.Return(builder.LiteralExpr(1)));
            ((IMethodDeclaration)prop1.GetMethod).Body = ip1bs;
            ip2bs.Statements.Add(builder.Return(builder.LiteralExpr(null)));
            ((IMethodDeclaration)prop2.GetMethod).Body = ip2bs;
            td.Properties.Add(prop1);
            td.Properties.Add(prop2);

            // Add an event
            IEventDeclaration event1 = builder.EventDecl("MyEvent", (ITypeReference)builder.TypeRef(typeof(Action <object>)), td);

            td.Events.Add(event1);

            // Build a wrapper function that allows clients to fire the event
            IMethodDeclaration fireEventMethod = builder.FireEventDecl(MethodVisibility.Public, "MyEventWrapper", event1);

            td.Methods.Add(fireEventMethod);

            return(td);
        }
            private ILiteralExpression GetDefaultParameterValue(IParameterDeclaration value)
            {
                ICustomAttribute customAttribute = this.GetCustomAttribute(value, "System.Runtime.InteropServices", "DefaultParameterValueAttribute", "System");
                if ((customAttribute != null) && (customAttribute.Arguments.Count == 1))
                {
                    return customAttribute.Arguments[0] as ILiteralExpression;
                }

                return null;
            }
Exemplo n.º 16
0
 private bool CheckParameterDecl(IParameterDeclaration o, IParameterDeclaration n)
 {
     return CheckParameterDecl(o, n, _errorCollector);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Adds a method parameter to this method
 /// </summary>
 /// <param name="parameter">The parameter to add</param>
 public void AddMethodParameter(IParameterDeclaration parameter)
 {
     parameter.ParentScope = this;
     _parameters.Add(parameter);
 }
 public void Initialize(IParameterDeclaration parameterDeclaration)
 {
     IsValid = InitializeInternal(parameterDeclaration);
 }
 public ParameterizedTestTypeMismatchHighlighting(IExpression argumentExpression, IParameterDeclaration parameterDeclaration) :
     base(argumentExpression, string.Format(Message, parameterDeclaration.Type))
 {
     ArgumentExpression   = argumentExpression;
     ParameterDeclaration = parameterDeclaration;
 }
 private IntroduceAndInitializePrivateAutoPropertyFix(IParameterDeclaration parameterDeclaration)
 {
     Context.Initialize(parameterDeclaration);
 }
 public DllImportInt32ForIntPtrHighlighting(IParameterDeclaration parameterDeclaration)
 {
     ParameterDeclaration = parameterDeclaration;
 }
Exemplo n.º 22
0
 private static void WriteParameterDeclaration(IParameterDeclaration parameterDeclaration, IAssembly assembly, IFormattedCodeWriter writer)
 {
     WriteTypeReference(parameterDeclaration.ParameterType, assembly, writer);
     writer.Write(' ');
     writer.Write(parameterDeclaration.Name);
 }
Exemplo n.º 23
0
 private IntroduceAndInitializeAutoPropertyFix(IParameterDeclaration parameterDeclaration)
 {
     Context  = new AutoPropertyInitializationContext();
     Language = CSharpLanguage.Instance;
     Context.Initialize(parameterDeclaration);
 }
 public void Initialize(IParameterDeclaration parameterDeclaration) => IsValid = InitializeInternal(parameterDeclaration);
Exemplo n.º 25
0
 public virtual IParameterDeclaration TransformParameterDeclaration(IParameterDeclaration value)
 {
     this.InsituTransformCustomAttributeCollection(value.Attributes);
     return value;
 }
Exemplo n.º 26
0
        public virtual IParameterDeclarationCollection TransformParameterDeclarationCollection(IParameterDeclarationCollection parameters)
        {
            IParameterDeclaration[] array = new IParameterDeclaration[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                array[i] = this.TransformParameterDeclaration(parameters[i]);
            }

            IParameterDeclarationCollection target = new ParameterDeclarationCollection();
            target.AddRange(array);
            return target;
        }
Exemplo n.º 27
0
 private bool CheckParameterDecl(IParameterDeclaration o, IParameterDeclaration n)
 {
     return(CheckParameterDecl(o, n, _errorCollector));
 }
Exemplo n.º 28
0
 protected override IParameterDeclaration ConvertMethodParameter(IParameterDeclaration ipd, int index)
 {
     ProcessConstant(ipd);
     return(base.ConvertMethodParameter(ipd, index));
 }
Exemplo n.º 29
0
 public virtual void VisitParameterDeclaration(IParameterDeclaration value)
 {
     VisitCustomAttributeCollection(value.Attributes);
     VisitType(value.ParameterType);
 }
        /// <summary>
        /// Creates a parameter node.
        /// </summary>
        /// <param name="xmlNode">
        /// The <see cref="XmlNode"/> to create the parameter against.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// <see cref="XmlNode"/>of the created parameter.
        /// </returns>
        private static XmlNode CreateParamNode(XmlNode xmlNode, IParameterDeclaration parameter)
        {
            Param.RequireNotNull(xmlNode, "xmlNode");

            string parameterName = parameter.DeclaredName;

            XmlNode newNode = CreateNode(xmlNode, "param");
            XmlAttribute newAttribute = xmlNode.OwnerDocument.CreateAttribute("name");

            newAttribute.Value = parameterName;

            string innerText = string.Empty;

            if (StyleCopOptions.Instance.InsertTextIntoDocumentation)
            {
                innerText = string.Format("The {0}.", Utils.ConvertTextToSentence(parameterName));
            }

            XmlText innerChildTextNode = xmlNode.OwnerDocument.CreateTextNode(innerText);

            newNode.AppendChild(innerChildTextNode);
            newNode.Attributes.Append(newAttribute);

            return newNode;
        }
Exemplo n.º 31
0
        /// <inheritdoc />
        public override void VisitParameterDeclaration(IParameterDeclaration node)
        {
            RegisterLocalSymbolDefinition(node);

            base.VisitParameterDeclaration(node);
        }
Exemplo n.º 32
0
 private bool CheckParameterDecl(IParameterDeclaration o, IParameterDeclaration n, Action<string,string> errorHander)
 {
     if (!o.Attributes.Compare( n.Attributes,CheckCustomAttribute) ||
         //!CheckExp(o.DefaultValue, n.DefaultValue) ||
         o.Name != n.Name ||
         o.ParameterType.ToString() != n.ParameterType.ToString())
     {
         errorHander(o.Name, "Parameter decl");
         return false;
     }
     return true;
 }
            private void WriteParameterDeclaration(IParameterDeclaration value, IFormatter formatter, ILanguageWriterConfiguration configuration)
            {
                if ((configuration != null) && (configuration["ShowCustomAttributes"] == "true") && (value.Attributes.Count != 0))
                {
                    this.WriteCustomAttributeList(value, formatter);
                    formatter.Write(" ");
                }

                IType parameterType = value.ParameterType;

                IReferenceType referenceType = parameterType as IReferenceType;
                if (referenceType != null)
                {
                }

                if ((value.Name != null) && value.Name.Length > 0)
                {
                    formatter.Write(value.Name);
                }
                else
                {
                    formatter.Write("A");
                }
            }
Exemplo n.º 34
0
        protected override IExpression ConvertAssign(IAssignExpression iae)
        {
            IParameterDeclaration ipd = null;
            IVariableDeclaration  ivd = Recognizer.GetVariableDeclaration(iae.Target);
            object decl = ivd;

            if (ivd == null)
            {
                ipd = Recognizer.GetParameterDeclaration(iae.Target);
                if (ipd == null)
                {
                    return(base.ConvertAssign(iae));
                }
                decl = ipd;
            }
            if (iae.Target is IArrayIndexerExpression)
            {
                // Gather index variables from the left-hand side of the assignment
                VariableInformation vi = VariableInformation.GetVariableInformation(context, decl);
                try
                {
                    List <IVariableDeclaration[]> indVars = new List <IVariableDeclaration[]>();
                    Recognizer.AddIndexers(context, indVars, iae.Target);
                    int depth = Recognizer.GetIndexingDepth(iae.Target);
                    // if this statement is actually a constraint, then we don't need to enforce matching of index variables
                    bool isConstraint = context.InputAttributes.Has <Models.Constraint>(context.FindAncestor <IStatement>());
                    for (int i = 0; i < depth; i++)
                    {
                        vi.SetIndexVariablesAtDepth(i, indVars[i], allowMismatch: isConstraint);
                    }
                }
                catch (Exception ex)
                {
                    Error(ex.Message, ex);
                }
            }
            IAssignExpression ae = (IAssignExpression)base.ConvertAssign(iae);

            if (ipd == null)
            {
                // assignment to a local variable
                if (ae.Expression is IMethodInvokeExpression)
                {
                    IMethodInvokeExpression imie = (IMethodInvokeExpression)ae.Expression;
                    // this unfortunately duplicates some of the work done by SetStoch and IsStoch.
                    FactorManager.FactorInfo info = CodeRecognizer.GetFactorInfo(context, imie);
                    if (info != null && info.IsDeterministicFactor && !context.InputAttributes.Has <DerivedVariable>(ivd))
                    {
                        context.InputAttributes.Set(ivd, new DerivedVariable());
                    }
                }
                if (ae.Expression is ILiteralExpression)
                {
                    bool isLoopInitializer = (Recognizer.GetAncestorIndexOfLoopBeingInitialized(context) != -1);
                    if (!isLoopInitializer)
                    {
                        Type valueType = ae.Expression.GetExpressionType();
                        if (Quoter.ShouldInlineType(valueType))
                        {
                            // inline all future occurrences of this variable with the rhs expression
                            conditionContext.Add(new ConditionBinding(ae.Target, ae.Expression));
                        }
                    }
                }
            }
            else
            {
                // assignment to a method parameter
                IStatement ist = context.FindAncestor <IStatement>();
                if (!context.InputAttributes.Has <Models.Constraint>(ist))
                {
                    // mark this statement as a constraint
                    context.OutputAttributes.Set(ist, new Models.Constraint());
                }
            }
            // a FactorAlgorithm attribute on a variable turns into an Algorithm attribute on its right hand side.
            var attr = context.InputAttributes.Get <FactorAlgorithm>(decl);

            if (attr != null)
            {
                context.OutputAttributes.Set(ae.Expression, new Algorithm(attr.algorithm));
            }
            context.InputAttributes.CopyObjectAttributesTo <GivePriorityTo>(decl, context.OutputAttributes, ae.Expression);
            return(ae);
        }
 public DllImportIncorrectParameterMarshalHighlighting(IParameterDeclaration parameterDeclaration, ICSharpExpression parameterExpression, UnmanagedType unmanagedType)
 {
     ParameterDeclaration = parameterDeclaration;
     ParameterExpression = parameterExpression;
     UnmanagedType = unmanagedType;
 }