Ejemplo n.º 1
0
 public BoundConversionExpression(BoundExpression expression, TypeSymbol type, Conversion conversion)
     : base(BoundNodeKind.ConversionExpression)
 {
     Expression = expression;
     Type = type;
     Conversion = conversion;
 }
Ejemplo n.º 2
0
 public BoundUnaryExpression(SyntaxNode syntax, BoundExpression expression, UnaryOperatorKind operatorKind, TypeSymbol expressionType)
     : base(BoundNodeKind.UnaryExpression, syntax)
 {
     Expression = expression;
     OperatorKind = operatorKind;
     Type = expressionType;
 }
Ejemplo n.º 3
0
 public BinaryOperatorSignature(BinaryOperatorKind kind, TypeSymbol returnType, TypeSymbol leftParameterType, TypeSymbol rightParameterType)
 {
     Kind = kind;
     ReturnType = returnType;
     _leftParameterType = leftParameterType;
     _rightParameterType = rightParameterType;
 }
 public BoundVariableDeclaration(VariableDeclarationStatementSyntax syntax, LocalVariableSymbol variableSymbol, TypeSymbol declaredType, BoundExpression initializerOpt)
     : base(BoundNodeKind.VariableDeclaration, syntax)
 {
     VariableSymbol = variableSymbol;
     DeclaredType = declaredType;
     InitializerOpt = initializerOpt;
 }
 public BoundNumericConstructorInvocationExpression(NumericConstructorInvocationExpressionSyntax syntax, TypeSymbol type, ImmutableArray<BoundExpression> arguments, OverloadResolutionResult<FunctionSymbolSignature> result)
     : base(BoundNodeKind.NumericConstructorInvocationExpression)
 {
     Syntax = syntax;
     Type = type;
     Arguments = arguments;
     Result = result;
 }
Ejemplo n.º 6
0
        internal ParameterSymbol(string name, string documentation, Symbol parent, TypeSymbol valueType, ParameterDirection direction = ParameterDirection.In)
            : base(SymbolKind.Parameter, name, documentation, parent, valueType)
        {
            if (valueType == null)
                throw new ArgumentNullException(nameof(valueType));

            Direction = direction;
        }
 public BoundBinaryExpression(BinaryExpressionSyntax syntax, BinaryOperatorKind operatorKind, BoundExpression left, BoundExpression right, TypeSymbol type)
     : base(BoundNodeKind.BinaryExpression, syntax)
 {
     OperatorKind = operatorKind;
     Left = left;
     Right = right;
     Type = type;
 }
Ejemplo n.º 8
0
 public BoundVariableDeclaration(VariableSymbol variableSymbol, TypeSymbol declaredType, ImmutableArray<BoundVariableQualifier> qualifiers, BoundInitializer initializerOpt)
     : base(BoundNodeKind.VariableDeclaration)
 {
     VariableSymbol = variableSymbol;
     DeclaredType = declaredType;
     Qualifiers = qualifiers;
     InitializerOpt = initializerOpt;
 }
Ejemplo n.º 9
0
 private static IEnumerable<FunctionDeclarationSymbol> Create1(string name, string documentation, TypeSymbol[] types)
 {
     return types.Select(type => new FunctionDeclarationSymbol(
         name, documentation, type,
         f => new []
         {
             new ParameterSymbol("value", "The specified value.", f, type)
         }));
 }
Ejemplo n.º 10
0
        internal ArraySymbol(TypeSymbol valueType, int? dimension)
            : base(SymbolKind.Array, $"{valueType.FullName}[{dimension?.ToString() ?? string.Empty}]", "Array of " + valueType.Name, null)
        {
            foreach (var member in CreateArrayMembers(this, valueType))
                AddMember(member);

            ValueType = valueType;
            Dimension = dimension;
        }
Ejemplo n.º 11
0
        internal static Conversion Classify(TypeSymbol sourceType, TypeSymbol targetType)
        {
            if (sourceType == targetType)
                return Identity;

            throw new NotImplementedException();

            return None;
        }
Ejemplo n.º 12
0
        private static OverloadResolutionResult<UnaryOperatorSignature> ResolveOverloads(UnaryOperatorKind kind, TypeSymbol operandType)
        {
            var builtInSignatures = GetBuiltInSignatures(kind);

            if (TypeBuiltIn(operandType))
                return OverloadResolution.Perform(builtInSignatures, operandType);

            return OverloadResolutionResult<UnaryOperatorSignature>.None;
        }
Ejemplo n.º 13
0
        private static OverloadResolutionResult<BinaryOperatorSignature> ResolveOverloads(BinaryOperatorKind kind, TypeSymbol leftOperandType, TypeSymbol rightOperandType)
        {
            var builtInSignatures = GetBuiltInSignatures(kind);

            if (BothTypesBuiltIn(leftOperandType, rightOperandType))
                return OverloadResolution.Perform(builtInSignatures, leftOperandType, rightOperandType);

            return OverloadResolutionResult<BinaryOperatorSignature>.None;
        }
Ejemplo n.º 14
0
        internal static bool HasExplicitConversionTo(this TypeSymbol left, TypeSymbol right)
        {
            if (left.Equals(right))
                return true;

            if (left.IsIntrinsicNumericType() && right.Kind == SymbolKind.Struct)
                return true;

            return left.HasImplicitConversionTo(right);
        }
Ejemplo n.º 15
0
        internal InvocableSymbol(SymbolKind kind, string name, string documentation, Symbol parent, TypeSymbol returnType, Func<InvocableSymbol, IEnumerable<ParameterSymbol>> lazyParameters = null)
            : base(kind, name, documentation, parent)
        {
            if (returnType == null)
                throw new ArgumentNullException(nameof(returnType));

            _parameters = new List<ParameterSymbol>();

            if (lazyParameters != null)
                foreach (var parameter in lazyParameters(this))
                    AddParameter(parameter);

            ReturnType = returnType;
        }
Ejemplo n.º 16
0
        internal static Conversion Classify(TypeSymbol sourceType, TypeSymbol targetType, ParameterDirection direction)
        {
            if (sourceType.Equals(targetType))
                return Identity;

            // First, make sure we have a conversion from argument to parameter.
            switch (direction)
            {
                case ParameterDirection.In:
                    if (!sourceType.HasImplicitConversionTo(targetType))
                        return sourceType.HasExplicitConversionTo(targetType) ? Explicit : None;
                    break;
                case ParameterDirection.Out:
                    if (!targetType.HasImplicitConversionTo(sourceType))
                        return None;
                    break;
                case ParameterDirection.Inout:
                    if (!sourceType.HasImplicitConversionTo(targetType) || !targetType.HasImplicitConversionTo(sourceType))
                        return None;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            var conversionType = ConversionTypes.None;

            var numericTargetType = targetType as IntrinsicNumericTypeSymbol;
            var numericSourceType = sourceType as IntrinsicNumericTypeSymbol;
            if (numericTargetType != null && numericSourceType != null)
            {
                conversionType |= ClassifyTypeConversion(numericSourceType, numericTargetType);
                conversionType |= ClassifyDimensionConversion(numericSourceType, numericTargetType);
            }

            // TODO: Non-numeric implicit conversions.

            return new Conversion(true, false, false, conversionType);
        }
Ejemplo n.º 17
0
        internal static int Compare(TypeSymbol xType, Conversion xConversion, TypeSymbol yType, Conversion yConversion)
        {
            if (xConversion.IsIdentity && !yConversion.IsIdentity ||
                xConversion.IsImplicit && yConversion.IsExplicit)
                return -1;

            if (!xConversion.IsIdentity && yConversion.IsIdentity ||
                xConversion.IsExplicit && yConversion.IsImplicit)
                return 1;

            var xTypeToYType = Classify(xType, yType);
            var yTypeToXType = Classify(yType, xType);

            if (xTypeToYType.IsImplicit && yTypeToXType.IsExplicit)
                return -1;

            if (xTypeToYType.IsExplicit && yTypeToXType.IsImplicit)
                return 1;

            //var xKnown = xType.GetKnownType();
            //var yKnown = yType.GetKnownType();

            //if (xKnown != null && yKnown != null)
            //{
            //    var x = xKnown.Value;
            //    var y = yKnown.Value;

            //    if (x.IsSignedNumericType() && y.IsUnsignedNumericType())
            //        return -1;

            //    if (x.IsUnsignedNumericType() && y.IsSignedNumericType())
            //        return 1;
            //}

            return 0;
        }
Ejemplo n.º 18
0
        private static IEnumerable<FunctionSymbol> Create1(
            string name, string documentation, TypeSymbol[] types, 
            string parameterName, string parameterDocumentation, 
            params TypeSymbol[] overrideReturnTypes)
        {
            if (overrideReturnTypes.Length == 0)
                overrideReturnTypes = null;
            else if (overrideReturnTypes.Length == 1)
                overrideReturnTypes = Enumerable.Repeat(overrideReturnTypes[0], types.Length).ToArray();

            return types.Select((type, i) => new FunctionSymbol(
                name, documentation, null, overrideReturnTypes?[i] ?? type,
                f => new []
                {
                    new ParameterSymbol(parameterName ?? "value", parameterDocumentation ?? "The specified value.", f, type)
                }));
        }
Ejemplo n.º 19
0
 private static FunctionSymbol Create0(string name, string documentation, TypeSymbol returnType)
 {
     return new FunctionSymbol(
         name, documentation, null, returnType,
         f => new ParameterSymbol[0]);
 }
Ejemplo n.º 20
0
 public static void ReportImplicitTruncation(this ICollection<Diagnostic> diagnostics, TextSpan span, TypeSymbol sourceType, TypeSymbol destinationType)
 {
     diagnostics.Report(span, DiagnosticId.ImplicitTruncation, sourceType.Name, destinationType.Name);
 }
Ejemplo n.º 21
0
 public static void ReportAmbiguousUnaryOperator(this ICollection<Diagnostic> diagnostics, SyntaxToken operatorToken, TypeSymbol type)
 {
     var operatorName = operatorToken.Text;
     var typeName = type.ToDisplayName();
     diagnostics.Report(operatorToken.Span, DiagnosticId.AmbiguousUnaryOperator, operatorName, typeName);
 }
Ejemplo n.º 22
0
 public static void ReportAmbiguousBinaryOperator(this ICollection<Diagnostic> diagnostics, SyntaxToken operatorToken, TypeSymbol leftType, TypeSymbol rightType)
 {
     var operatorName = operatorToken.Text;
     var leftTypeName = leftType.ToDisplayName();
     var rightTypeName = rightType.ToDisplayName();
     diagnostics.Report(operatorToken.Span, DiagnosticId.AmbiguousBinaryOperator, operatorName, leftTypeName, rightTypeName);
 }
Ejemplo n.º 23
0
 public static void ReportCannotConvert(this ICollection<Diagnostic> diagnostics, TextSpan span, TypeSymbol sourceType, TypeSymbol targetType)
 {
     var sourceTypeName = sourceType.ToDisplayName();
     var targetTypeName = targetType.ToDisplayName();
     diagnostics.Report(span, DiagnosticId.CannotConvert, sourceTypeName, targetTypeName);
 }
Ejemplo n.º 24
0
 public static void ReportUndeclaredIndexer(this ICollection<Diagnostic> diagnostics, ElementAccessExpressionSyntax node, TypeSymbol declaringType, IEnumerable<TypeSymbol> argumentTypes)
 {
     var declaringTypeName = declaringType.ToDisplayName();
     var argumentTypeNames = string.Join(@", ", argumentTypes.Select(t => t.ToDisplayName()));
     diagnostics.Report(node.GetTextSpanRoot(), DiagnosticId.UndeclaredIndexer, declaringTypeName, argumentTypeNames);
 }
Ejemplo n.º 25
0
 public static void ReportUndeclaredMethod(this ICollection<Diagnostic> diagnostics, MethodInvocationExpressionSyntax node, TypeSymbol declaringType, IEnumerable<TypeSymbol> argumentTypes)
 {
     var name = node.Name.ValueText;
     var declaringTypeName = declaringType.ToDisplayName();
     var argumentTypeNames = string.Join(@", ", argumentTypes.Select(t => t.ToDisplayName()));
     diagnostics.Report(node.GetTextSpanRoot(), DiagnosticId.UndeclaredMethod, declaringTypeName, name, argumentTypeNames);
 }
 public SourceFunctionDefinitionSymbol(FunctionDefinitionSyntax syntax, TypeSymbol returnType, Func<FunctionSymbol, IEnumerable<ParameterSymbol>> lazyParameters)
     : base(syntax.Name.GetName(), string.Empty, returnType, lazyParameters)
 {
     Syntax = syntax;
 }
Ejemplo n.º 27
0
 public bool IsSymbol(TypeSymbol symbol, string symbolName)
 {
     return (((ISymbolTable)this).FindSymbol(symbolName, null) == symbol);
 }
Ejemplo n.º 28
0
 private static IEnumerable<FunctionSymbol> Create4(
     string name, string documentation, TypeSymbol[] types,
     string parameterName1, string parameterDocumentation1,
     string parameterName2, string parameterDocumentation2,
     string parameterName3, string parameterDocumentation3,
     string parameterName4, string parameterDocumentation4,
     TypeSymbol overrideReturnType = null,
     ParameterDirection overrideParameterDirection4 = ParameterDirection.In)
 {
     return types.Select(type => new FunctionSymbol(
         name, documentation, null, overrideReturnType ?? type,
         f => new[]
         {
             new ParameterSymbol(parameterName1, parameterDocumentation1, f, type),
             new ParameterSymbol(parameterName2, parameterDocumentation2, f, type),
             new ParameterSymbol(parameterName3, parameterDocumentation3, f, type),
             new ParameterSymbol(parameterName4, parameterDocumentation4, f, type, overrideParameterDirection4)
         }));
 }
 public MethodDeclarationSymbol(string name, string documentation, TypeSymbol parent, TypeSymbol returnType, Func<MethodSymbol, IEnumerable<ParameterSymbol>> lazyParameters)
     : base(SymbolKind.MethodDeclaration, name, documentation, parent, returnType, lazyParameters)
 {
     
 }
Ejemplo n.º 30
0
 public static void ReportUndeclaredField(this ICollection<Diagnostic> diagnostics, FieldAccessExpressionSyntax node, TypeSymbol type)
 {
     var typeName = type.ToDisplayName();
     var propertyName = node.Name.ValueText;
     diagnostics.Report(node.GetTextSpanSafe(), DiagnosticId.UndeclaredField, typeName, propertyName);
 }