Example #1
0
 public Parameter(
     string name,
     TypeSymbol[] types,
     ArgumentKind argumentKind       = ArgumentKind.Expression,
     IReadOnlyList <object> values   = null,
     IReadOnlyList <string> examples = null,
     bool isCaseSensitive            = false,
     string defaultValueIndicator    = null,
     int minOccurring        = 1,
     int maxOccurring        = 1,
     Expression defaultValue = null,
     string description      = null)
     : this(
         name,
         ParameterTypeKind.Declared,
         types,
         argumentKind,
         values,
         examples,
         isCaseSensitive,
         defaultValueIndicator,
         minOccurring,
         maxOccurring,
         defaultValue,
         description)
 {
 }
Example #2
0
        internal IArgumentOperation CreateArgumentOperation(ArgumentKind kind, IParameterSymbol parameter, BoundExpression expression)
        {
            // put argument syntax to argument operation

            if (expression.Syntax?.Parent is ArgumentSyntax argument)
            {
                // if argument syntax doesn't exist, this operation is implicit
                return(new CSharpLazyArgumentOperation(this,
                                                       expression,
                                                       kind,
                                                       s_boxedIdentityConversion,
                                                       s_boxedIdentityConversion,
                                                       parameter,
                                                       semanticModel: _semanticModel,
                                                       syntax: argument,
                                                       isImplicit: expression.WasCompilerGenerated));
            }
            else
            {
                // We have to create the argument child eagerly here, as we need to use its syntax for this node, but the BoundExpression
                // syntax may not be the correct syntax in certain scenarios (such as query clauses that need to be skipped).
                IOperation value = Create(expression);
                return(new ArgumentOperation(
                           value,
                           kind,
                           parameter,
                           s_boxedIdentityConversion,
                           s_boxedIdentityConversion,
                           _semanticModel,
                           value.Syntax,
                           isImplicit: true));
            }
        }
Example #3
0
        private static bool TryCheckForExtensions(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (IsDataLoader(parameter))
            {
                argumentKind = ArgumentKind.DataLoader;
                return(true);
            }

#pragma warning disable CS0612
            if (IsState(parameter) ||
                IsGlobalState(parameter) ||
                IsScopedState(parameter) ||
                IsLocalState(parameter))
            {
                argumentKind = ArgumentKind.CustomContext;
                return(true);
            }
#pragma warning restore CS0612

            if (IsService(parameter))
            {
                argumentKind = ArgumentKind.Service;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
Example #4
0
        private static bool TryCheckForResolverArguments(
            this ParameterInfo parameter,
            Type sourceType,
            out ArgumentKind argumentKind)
        {
            if (parameter.ParameterType == typeof(IResolverContext))
            {
                argumentKind = ArgumentKind.Context;
                return(true);
            }

            if (parameter.ParameterType == typeof(CancellationToken))
            {
                argumentKind = ArgumentKind.CancellationToken;
                return(true);
            }

            if (sourceType == null)
            {
                argumentKind = default(ArgumentKind);
                return(false);
            }

            if (parameter.ParameterType == sourceType ||
                IsParent(parameter, sourceType))
            {
                argumentKind = ArgumentKind.Source;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
Example #5
0
        private static bool TryCheckForSchemaTypes(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (IsSchema(parameter))
            {
                argumentKind = ArgumentKind.Schema;
                return(true);
            }

            if (parameter.ParameterType == typeof(ObjectType))
            {
                argumentKind = ArgumentKind.ObjectType;
                return(true);
            }

            if (IsOutputField(parameter))
            {
                argumentKind = ArgumentKind.Field;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
Example #6
0
        private static bool TryCheckForQueryTypes(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (parameter.ParameterType == typeof(DocumentNode))
            {
                argumentKind = ArgumentKind.QueryDocument;
                return(true);
            }

            if (parameter.ParameterType == typeof(OperationDefinitionNode))
            {
                argumentKind = ArgumentKind.OperationDefinition;
                return(true);
            }

            if (parameter.ParameterType == typeof(FieldNode))
            {
                argumentKind = ArgumentKind.FieldSelection;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
Example #7
0
        private static bool TryCheckForExtensions(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (IsDataLoader(parameter))
            {
                argumentKind = ArgumentKind.DataLoader;
                return(true);
            }

            if (IsState(parameter))
            {
                argumentKind = ArgumentKind.CustomContext;
                return(true);
            }

            if (IsService(parameter))
            {
                argumentKind = ArgumentKind.Service;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
Example #8
0
        public void ParseAnArgument(string src, ArgumentKind kind, double value)
        {
            var parser   = new Parser(src);
            var shouldBe = new Argument(kind, value, new Span(0, src.Length));

            var got = parser.ParseArgument();

            Assert.Equal(shouldBe, got);
        }
Example #9
0
        private readonly ReadOnlySpan <char> myRaw;      // 4/8 bytes + 4 byte + 4 bytes padding

        // private GCodeFieldSpan(
        //   char word, ReadOnlySpan<char> raw, ArgumentKind kind)
        // {
        //   myWord = (byte) word;
        //   myRaw = raw;
        //   myKind = kind;
        //   myPayload1 = 0;
        //   myPayload2 = 0;
        // }

        private GCodeFieldSpan(
            char word, ReadOnlySpan <char> raw, ArgumentKind kind, int payload1, int payload2)
        {
            myWord     = (byte)word;
            myRaw      = raw;
            myKind     = kind;
            myPayload1 = payload1;
            myPayload2 = payload2;
        }
Example #10
0
 public ArgumentRule(ArgumentKind kind, string name, string prefix = "", string postfix = "", ArgumentFlags flags = ArgumentFlags.None)
 {
     Kind    = kind;
     Name    = name;
     Prefix  = prefix;
     Postfix = postfix;
     Flags   = flags;
     Repeat  = ArgumentRepeat.Ignore;
 }
Example #11
0
 internal ArgumentDescriptor(
     string name, string variableName,
     ArgumentKind kind,
     Type type)
 {
     Name         = name;
     VariableName = variableName;
     Kind         = kind;
     Type         = type;
 }
        internal IArgumentOperation CreateArgumentOperation(
            ArgumentKind kind,
            IParameterSymbol?parameter,
            BoundExpression expression
            )
        {
            // put argument syntax to argument operation
            IOperation value = Create(expression);

            (SyntaxNode syntax, bool isImplicit) = expression.Syntax
                                                   is { Parent : ArgumentSyntax parent }
Example #13
0
        internal IArgument CreateArgumentOperation(ArgumentKind kind, IParameterSymbol parameter, BoundExpression expression)
        {
            var value = Create(expression);

            return(new CSharpArgument(kind,
                                      parameter,
                                      value,
                                      semanticModel: _semanticModel,
                                      syntax: value.Syntax,
                                      type: value.Type,
                                      constantValue: default,
Example #14
0
        private static bool TryCheckForSubscription(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (IsEventMessage(parameter))
            {
                argumentKind = ArgumentKind.EventMessage;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
        private static bool TryCheckForSubscription(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (typeof(IEventMessage).IsAssignableFrom(parameter.ParameterType))
            {
                argumentKind = ArgumentKind.EventMessage;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
        public void InitializeKind(Type moduleType, string methodName, ArgumentKind kind)
        {
            // Arrange
            var ctor      = NewArgumentModelConstructor();
            var command   = new CommandModel();
            var parameter = GetFirstParameter(moduleType, methodName);

            // Act
            var argument = ctor.Create(parameter, command);

            // Assert
            Assert.Equal(kind, argument.Kind);
        }
 internal ArgumentSourceCodeGeneratorTestBase(
     ArgumentSourceCodeGenerator generator,
     Type argumentType,
     ArgumentKind validArgumentKind,
     ArgumentKind invalidArgumentKind)
 {
     _generator = generator
                  ?? throw new ArgumentNullException(nameof(generator));
     _argumentType = argumentType
                     ?? throw new ArgumentNullException(nameof(argumentType));
     _validArgumentKind   = validArgumentKind;
     _invalidArgumentKind = invalidArgumentKind;
 }
        internal IArgumentOperation CreateArgumentOperation(ArgumentKind kind, IParameterSymbol parameter, BoundExpression expression)
        {
            var value = Create(expression);

            // put argument syntax to argument operation
            var argument = value.Syntax?.Parent as ArgumentSyntax;

            // if argument syntax doesn't exist, this operation is implicit
            return(new CSharpArgument(kind,
                                      parameter,
                                      value,
                                      semanticModel: _semanticModel,
                                      syntax: argument ?? value.Syntax,
                                      constantValue: default,
        private ResolverDescriptor CreateDescriptor(ArgumentKind argumentKind)
        {
            Type sourceType = typeof(GeneratorTestDummy);

            var fieldMember = new FieldMember(
                "Foo", "bar",
                GetMethod <GeneratorTestDummyResolver>("GetFoo", 1));

            var argumentDescriptor = new ArgumentDescriptor(
                "a", "b", argumentKind,
                typeof(GeneratorTestDummy));

            return(new ResolverDescriptor(sourceType, fieldMember));
        }
        internal ArgumentDescriptor(
            NameString name,
            string variableName,
            ArgumentKind kind,
            Type type,
            ParameterInfo parameter)
        {
            Name         = name;
            VariableName = variableName;

            Kind      = kind;
            Type      = type;
            Parameter = parameter;
        }
Example #21
0
 private static void AddCompositeInstructions(Dictionary <int, ArgumentKind[]> dic2)
 {
     foreach (var pair in CompositeInstructions.ExpandedInstructions)
     {
         Instruction instruction       = (Instruction)pair.Key;
         var         instructions      = pair.Value;
         int         numberOfArguments = ((Instruction)instruction).GetNumberOfWords();
         if (numberOfArguments > 0)
         {
             var argumentKinds = new ArgumentKind[numberOfArguments];
             GetArgumentKinds(instructions, argumentKinds, dic2);
             dic2.Set((int)instruction, argumentKinds);
         }
     }
 }
Example #22
0
        public int IndexOf(ArgumentKind kind)
        {
            if (_infos == null)
            {
                return((kind == ArgumentKind.Simple && _argumentCount > 0) ? 0 : -1);
            }

            for (int i = 0; i < _infos.Length; i++)
            {
                if (_infos[i].Kind == kind)
                {
                    return(i);
                }
            }
            return(-1);
        }
Example #23
0
        /// <summary>
        /// Gets the number of positional arguments the user provided at the call site.
        /// </summary>
        public int GetProvidedPositionalArgumentCount()
        {
            int result = _argumentCount;

            if (_infos != null)
            {
                for (int i = 0; i < _infos.Length; i++)
                {
                    ArgumentKind kind = _infos[i].Kind;

                    if (kind == ArgumentKind.Dictionary || kind == ArgumentKind.List || kind == ArgumentKind.Named)
                    {
                        result--;
                    }
                }
            }

            return(result);
        }
Example #24
0
        private Parameter(
            string name,
            ParameterTypeKind typeKind,
            TypeSymbol[] types,
            ArgumentKind argumentKind,
            IEnumerable <object> values,
            IEnumerable <string> examples,
            bool isCaseSensitive,
            string defaultValueIndicator,
            int minOccurring,
            int maxOccurring,
            Expression defaultValue,
            string description)
        {
            if (typeKind == ParameterTypeKind.Declared)
            {
                if (types == null)
                {
                    throw new ArgumentNullException(nameof(types));
                }
                else if (types.Length == 0)
                {
                    throw new ArgumentException("Must have at least one declared type.", nameof(types));
                }
            }

            this.Name          = name;
            this.TypeKind      = typeKind;
            this.DeclaredTypes = types.ToReadOnly();
            this.ArgumentKind  = argumentKind;
            this.Values        = values != null?values.ToReadOnly() : NoValues;

            this.Examples = examples != null?examples.ToReadOnly() : NoExamples;

            this.IsCaseSensitive       = isCaseSensitive;
            this.MinOccurring          = defaultValue != null ? 0 : minOccurring;
            this.MaxOccurring          = defaultValue != null ? 1 : maxOccurring;
            this.DefaultValueIndicator = defaultValueIndicator;
            this.DefaultValue          = defaultValue;
            this.Description           = description ?? "";
        }
Example #25
0
        private static bool TryCheckForDirectives(
            this ParameterInfo parameter,
            out ArgumentKind argumentKind)
        {
            if (parameter.ParameterType == typeof(IDirectiveContext))
            {
                argumentKind = ArgumentKind.Context;
                return(true);
            }

            if (parameter.ParameterType == typeof(IDirective))
            {
                argumentKind = ArgumentKind.Directive;
                return(true);
            }

            if (parameter.IsDirective())
            {
                argumentKind = ArgumentKind.DirectiveObject;
                return(true);
            }

            if (parameter.IsDirectiveArgument())
            {
                argumentKind = ArgumentKind.DirectiveArgument;
                return(true);
            }

            if (parameter.IsResolverResult())
            {
                argumentKind = ArgumentKind.ResolverResult;
                return(true);
            }

            argumentKind = default(ArgumentKind);
            return(false);
        }
Example #26
0
 public InvocationArgument(ArgumentKind kind, Expression expression)
 {
     Kind       = kind;
     Expression = expression;
 }
Example #27
0
 public Argument(ArgumentKind kind, IParameterSymbol parameter, IExpression value)
     : base(parameter, value)
 {
     this.ArgumentKind = kind;
 }
Example #28
0
 internal BaseArgumentOperation(ArgumentKind argumentKind, IParameterSymbol parameter, IConvertibleConversion inConversion, IConvertibleConversion outConversion, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional <object> constantValue, bool isImplicit) :
     this(argumentKind, parameter, semanticModel, syntax, type, constantValue, isImplicit)
 {
     InConversionConvertibleOpt  = inConversion;
     OutConversionConvertibleOpt = outConversion;
 }
Example #29
0
 public LazyCSharpArgument(ArgumentKind argumentKind, IParameterSymbol parameter, Lazy <IOperation> value, SemanticModel semanticModel, SyntaxNode syntax, Optional <object> constantValue, bool isImplicit) :
     base(argumentKind, parameter, semanticModel, syntax, constantValue, isImplicit)
 {
     _lazyValue = value ?? throw new ArgumentNullException(nameof(value));
 }
Example #30
0
 public BaseCSharpArgument(ArgumentKind argumentKind, IParameterSymbol parameter, SemanticModel semanticModel, SyntaxNode syntax, Optional <object> constantValue, bool isImplicit) :
     base(argumentKind, parameter, semanticModel, syntax, constantValue, isImplicit)
 {
 }
Example #31
0
 public ArgumentOperation(IOperation value, ArgumentKind argumentKind, IParameterSymbol parameter, IConvertibleConversion inConversionOpt, IConvertibleConversion outConversionOpt, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
     base(argumentKind, parameter, inConversionOpt, outConversionOpt, semanticModel, syntax, type: null, constantValue: default, isImplicit)
 {
     Value = SetParentOperation(value, this);
 }
Example #32
0
 public Argument(ArgumentKind kind, IParameterSymbol parameter, IExpression value)
 {
     this.Value = value;
     this.Kind = kind;
     this.Parameter = parameter;
 }