Example #1
0
        /// <summary>
        /// Constructs a new intrinsic type parse tree.
        /// </summary>
        /// <param name="intrinsicType">The intrinsic type.</param>
        /// <param name="span">The location of the parse tree.</param>
        public IntrinsicTypeName(IntrinsicType intrinsicType, Span span) : base(TreeType.IntrinsicType, span)
        {
            if (!Enum.IsDefined(typeof(IntrinsicType), intrinsicType))
            {
                throw new ArgumentOutOfRangeException("intrinsicType");
            }

            _IntrinsicType = intrinsicType;
        }
            public override string GetName(IntrinsicType intrinsicType, ReflectionNameOptions options)
            {
                string name;

                if (this.intrinsicNames.TryGetValue(intrinsicType, out name))
                {
                    return(name);
                }

                return(base.GetName(intrinsicType, options));
            }
Example #3
0
        /// <summary>
        /// Constructs a new parse tree for an intrinsic conversion expression.
        /// </summary>
        /// <param name="intrinsicType">The intrinsic type conversion.</param>
        /// <param name="leftParenthesisLocation">The location of the '('.</param>
        /// <param name="operand">The expression to convert.</param>
        /// <param name="rightParenthesisLocation">The location of the ')'.</param>
        /// <param name="span">The location of the parse tree.</param>
        public IntrinsicCastExpression(IntrinsicType intrinsicType, Location leftParenthesisLocation, Expression operand, Location rightParenthesisLocation, Span span) : base(TreeType.IntrinsicCastExpression, operand, span)
        {
            if (!Enum.IsDefined(typeof(IntrinsicType), intrinsicType))
            {
                throw new ArgumentOutOfRangeException("intrinsicType");
            }

            if (operand == null)
            {
                throw new ArgumentNullException("operand");
            }

            _IntrinsicType            = intrinsicType;
            _LeftParenthesisLocation  = leftParenthesisLocation;
            _RightParenthesisLocation = rightParenthesisLocation;
        }
Example #4
0
        public TypeSymbol ResolveType(ParseNode node, ISymbolTable symbolTable, Symbol contextSymbol)
        {
            if (node is IntrinsicTypeNode)
            {
                IntrinsicType intrinsicType = IntrinsicType.Integer;

                IntrinsicTypeNode intrinsicTypeNode = (IntrinsicTypeNode)node;

                switch (intrinsicTypeNode.Type)
                {
                case TokenType.Object:
                    intrinsicType = IntrinsicType.Object;

                    break;

                case TokenType.Bool:
                    intrinsicType = IntrinsicType.Boolean;

                    break;

                case TokenType.String:
                case TokenType.Char:
                    intrinsicType = IntrinsicType.String;

                    break;

                case TokenType.Int:
                    intrinsicType = IntrinsicType.Integer;

                    break;

                case TokenType.UInt:
                    intrinsicType = IntrinsicType.UnsignedInteger;

                    break;

                case TokenType.Long:
                    intrinsicType = IntrinsicType.Long;

                    break;

                case TokenType.ULong:
                    intrinsicType = IntrinsicType.UnsignedLong;

                    break;

                case TokenType.Short:
                    intrinsicType = IntrinsicType.Short;

                    break;

                case TokenType.UShort:
                    intrinsicType = IntrinsicType.UnsignedShort;

                    break;

                case TokenType.Byte:
                    intrinsicType = IntrinsicType.Byte;

                    break;

                case TokenType.SByte:
                    intrinsicType = IntrinsicType.SignedByte;

                    break;

                case TokenType.Float:
                    intrinsicType = IntrinsicType.Single;

                    break;

                case TokenType.Decimal:
                    intrinsicType = IntrinsicType.Decimal;

                    break;

                case TokenType.Double:
                    intrinsicType = IntrinsicType.Double;

                    break;

                case TokenType.Delegate:
                    intrinsicType = IntrinsicType.Delegate;

                    break;

                case TokenType.Void:
                    intrinsicType = IntrinsicType.Void;

                    break;
                }

                TypeSymbol typeSymbol = ResolveIntrinsicType(intrinsicType);

                if (intrinsicTypeNode.IsNullable)
                {
                    TypeSymbol nullableType = ResolveIntrinsicType(IntrinsicType.Nullable);
                    typeSymbol = CreateGenericTypeSymbol(nullableType, new List <TypeSymbol> {
                        typeSymbol
                    });
                }

                return(typeSymbol);
            }

            if (node is ArrayTypeNode)
            {
                ArrayTypeNode arrayTypeNode = (ArrayTypeNode)node;

                TypeSymbol itemTypeSymbol = ResolveType(arrayTypeNode.BaseType, symbolTable, contextSymbol);
                Debug.Assert(itemTypeSymbol != null);

                return(CreateArrayTypeSymbol(itemTypeSymbol));
            }

            if (node is AtomicNameNode atomicNameNode)
            {
                TypeSymbol typeSymbol = ResolveAtomicNameNodeType(atomicNameNode, symbolTable, contextSymbol);
                if (typeSymbol != null)
                {
                    return(typeSymbol);
                }
            }

            if (node is GenericNameNode)
            {
                GenericNameNode genericNameNode = (GenericNameNode)node;
                string          genericTypeName = genericNameNode.Name + "`" + genericNameNode.TypeArguments.Count;
                TypeSymbol      templateType    =
                    (TypeSymbol)symbolTable.FindSymbol(genericTypeName, contextSymbol, SymbolFilter.Types);

                List <TypeSymbol> typeArguments = new List <TypeSymbol>();

                foreach (ParseNode argNode in genericNameNode.TypeArguments)
                {
                    TypeSymbol argType = ResolveType(argNode, symbolTable, contextSymbol);
                    Debug.Assert(argType != null);
                    typeArguments.Add(argType);
                }

                if (templateType != null)
                {
                    TypeSymbol resolvedSymbol = CreateGenericTypeSymbol(templateType, typeArguments);
                    Debug.Assert(resolvedSymbol != null);

                    return(resolvedSymbol);
                }
            }

            Debug.Assert(node is NameNode);
            NameNode nameNode = (NameNode)node;

            return((TypeSymbol)symbolTable.FindSymbol(nameNode.Name, contextSymbol, SymbolFilter.Types));
        }
Example #5
0
        public TypeSymbol ResolveIntrinsicToken(Token token)
        {
            if (token == null)
            {
                return(null);
            }

            IntrinsicType intrinsicType = IntrinsicType.Void;

            switch (token.Type)
            {
            case TokenType.Object:
                intrinsicType = IntrinsicType.Object;
                break;

            case TokenType.Bool:
                intrinsicType = IntrinsicType.Boolean;
                break;

            case TokenType.String:
            case TokenType.Char:
                intrinsicType = IntrinsicType.String;
                break;

            case TokenType.Int:
                intrinsicType = IntrinsicType.Integer;
                break;

            case TokenType.UInt:
                intrinsicType = IntrinsicType.UnsignedInteger;
                break;

            case TokenType.Long:
                intrinsicType = IntrinsicType.Long;
                break;

            case TokenType.ULong:
                intrinsicType = IntrinsicType.UnsignedLong;
                break;

            case TokenType.Short:
                intrinsicType = IntrinsicType.Short;
                break;

            case TokenType.UShort:
                intrinsicType = IntrinsicType.UnsignedShort;
                break;

            case TokenType.Byte:
                intrinsicType = IntrinsicType.Byte;
                break;

            case TokenType.SByte:
                intrinsicType = IntrinsicType.SignedByte;
                break;

            case TokenType.Float:
                intrinsicType = IntrinsicType.Single;
                break;

            case TokenType.Decimal:
                intrinsicType = IntrinsicType.Decimal;
                break;

            case TokenType.Double:
                intrinsicType = IntrinsicType.Double;
                break;

            case TokenType.Delegate:
                intrinsicType = IntrinsicType.Delegate;
                break;

            case TokenType.Void:
                intrinsicType = IntrinsicType.Void;
                break;
            }

            return(ResolveIntrinsicType(intrinsicType));
        }
Example #6
0
        /// <summary>
        ///     This maps C# intrinsic types (managed types that have an equivalent
        ///     C# keyword)
        /// </summary>
        public TypeSymbol ResolveIntrinsicType(IntrinsicType type)
        {
            string mappedTypeName  = null;
            string mappedNamespace = null;

            switch (type)
            {
            case IntrinsicType.Object:
                mappedTypeName = "Object";

                break;

            case IntrinsicType.Boolean:
                mappedTypeName = "Boolean";

                break;

            case IntrinsicType.String:
                mappedTypeName = "String";

                break;

            case IntrinsicType.Integer:
                mappedTypeName = "Int32";

                break;

            case IntrinsicType.UnsignedInteger:
                mappedTypeName = "UInt32";

                break;

            case IntrinsicType.Long:
                mappedTypeName = "Int64";

                break;

            case IntrinsicType.UnsignedLong:
                mappedTypeName = "UInt64";

                break;

            case IntrinsicType.Short:
                mappedTypeName = "Int16";

                break;

            case IntrinsicType.UnsignedShort:
                mappedTypeName = "UInt16";

                break;

            case IntrinsicType.Byte:
                mappedTypeName = "Byte";

                break;

            case IntrinsicType.SignedByte:
                mappedTypeName = "SByte";

                break;

            case IntrinsicType.Single:
                mappedTypeName = "Single";

                break;

            case IntrinsicType.Date:
                mappedTypeName = "Date";

                break;

            case IntrinsicType.Decimal:
                mappedTypeName = "Decimal";

                break;

            case IntrinsicType.Double:
                mappedTypeName = "Double";

                break;

            case IntrinsicType.Delegate:
                mappedTypeName = "Delegate";

                break;

            case IntrinsicType.Function:
                mappedTypeName = "Function";

                break;

            case IntrinsicType.Void:
                mappedTypeName = "Void";

                break;

            case IntrinsicType.Array:
                mappedTypeName = "Array";
                break;

            case IntrinsicType.GenericList:
                mappedTypeName  = "List`1";
                mappedNamespace = "System.Collections.Generic";
                break;

            case IntrinsicType.GenericDictionary:
                mappedTypeName  = "Dictionary`2";
                mappedNamespace = "System.Collections.Generic";
                break;

            case IntrinsicType.IDictionary:
                mappedTypeName  = "IDictionary";
                mappedNamespace = "System.Collections";
                break;

            case IntrinsicType.GenericIDictionary:
                mappedTypeName  = "IDictionary`2";
                mappedNamespace = "System.Collections.Generic";
                break;

            case IntrinsicType.GenericIReadOnlyDictionary:
                mappedTypeName  = "IReadOnlyDictionary`2";
                mappedNamespace = "System.Collections.Generic";
                break;

            case IntrinsicType.Type:
                mappedTypeName  = "Type";
                mappedNamespace = "System";

                break;

            case IntrinsicType.MemberInfo:
                mappedTypeName  = "MemberInfo";
                mappedNamespace = "System.Reflection";

                break;

            case IntrinsicType.Enumerator:
                mappedTypeName  = "IEnumerator";
                mappedNamespace = "System.Collections";

                break;

            case IntrinsicType.Enum:
                mappedTypeName = "Enum";

                break;

            case IntrinsicType.Exception:
                mappedTypeName = "Exception";

                break;

            case IntrinsicType.Script:
                mappedTypeName = "Script";

                break;

            case IntrinsicType.Number:
                mappedTypeName = "Number";

                break;

            case IntrinsicType.Arguments:
                mappedTypeName = "Arguments";

                break;

            case IntrinsicType.Nullable:
                mappedTypeName = "Nullable`1";

                break;

            default:
                Debug.Fail("Unmapped intrinsic type " + type);

                break;
            }

            NamespaceSymbol ns = SystemNamespace;

            if (mappedNamespace != null)
            {
                ns = GetNamespace(mappedNamespace);
                Debug.Assert(ns != null);
            }

            if (mappedTypeName != null)
            {
                TypeSymbol typeSymbol =
                    (TypeSymbol)((ISymbolTable)ns).FindSymbol(mappedTypeName, null, SymbolFilter.Types);
                Debug.Assert(typeSymbol != null);

                return(typeSymbol);
            }

            return(null);
        }
Example #7
0
        /// <summary>
        /// This maps C# intrinsic types (managed types that have an equivalent
        /// C# keyword)
        /// </summary>
        public TypeSymbol ResolveIntrinsicType(IntrinsicType type)
        {
            string mappedTypeName = null;
            string mappedNamespace = null;

            switch (type) {
                case IntrinsicType.Object:
                    mappedTypeName = "Object";
                    break;
                case IntrinsicType.Boolean:
                    mappedTypeName = "Boolean";
                    break;
                case IntrinsicType.String:
                    mappedTypeName = "String";
                    break;
                case IntrinsicType.Integer:
                    mappedTypeName = "Int32";
                    break;
                case IntrinsicType.UnsignedInteger:
                    mappedTypeName = "UInt32";
                    break;
                case IntrinsicType.Long:
                    mappedTypeName = "Int64";
                    break;
                case IntrinsicType.UnsignedLong:
                    mappedTypeName = "UInt64";
                    break;
                case IntrinsicType.Short:
                    mappedTypeName = "Int16";
                    break;
                case IntrinsicType.UnsignedShort:
                    mappedTypeName = "UInt16";
                    break;
                case IntrinsicType.Byte:
                    mappedTypeName = "Byte";
                    break;
                case IntrinsicType.SignedByte:
                    mappedTypeName = "SByte";
                    break;
                case IntrinsicType.Single:
                    mappedTypeName = "Single";
                    break;
                case IntrinsicType.Date:
                    mappedTypeName = "Date";
                    break;
                case IntrinsicType.Decimal:
                    mappedTypeName = "Decimal";
                    break;
                case IntrinsicType.Double:
                    mappedTypeName = "Double";
                    break;
                case IntrinsicType.Delegate:
                    mappedTypeName = "Delegate";
                    break;
                case IntrinsicType.Function:
                    mappedTypeName = "Function";
                    break;
                case IntrinsicType.Void:
                    mappedTypeName = "Void";
                    break;
                case IntrinsicType.Array:
                    mappedTypeName = "Array";
                    break;
                case IntrinsicType.Dictionary:
                    mappedTypeName = "Dictionary";
                    mappedNamespace = "System.Collections";
                    break;
                case IntrinsicType.GenericList:
                    mappedTypeName = "List`1";
                    mappedNamespace = "System.Collections.Generic";
                    break;
                case IntrinsicType.GenericDictionary:
                    mappedTypeName = "Dictionary`2";
                    mappedNamespace = "System.Collections.Generic";
                    break;
                case IntrinsicType.Type:
                    mappedTypeName = "Type";
                    break;
                case IntrinsicType.IEnumerator:
                    mappedTypeName = "IEnumerator";
                    mappedNamespace = "System.Collections";
                    break;
                case IntrinsicType.Enum:
                    mappedTypeName = "Enum";
                    break;
                case IntrinsicType.Exception:
                    mappedTypeName = "Exception";
                    break;
                case IntrinsicType.Script:
                    mappedTypeName = "Script";
                    break;
                case IntrinsicType.Number:
                    mappedTypeName = "Number";
                    break;
                case IntrinsicType.Arguments:
                    mappedTypeName = "Arguments";
                    break;
                case IntrinsicType.Nullable:
                    mappedTypeName = "Nullable`1";
                    break;
                default:
                    Debug.Fail("Unmapped intrinsic type " + type);
                    break;
            }

            NamespaceSymbol ns = _systemNamespace;
            if (mappedNamespace != null) {
                ns = GetNamespace(mappedNamespace);
                Debug.Assert(ns != null);
            }

            if (mappedTypeName != null) {
                TypeSymbol typeSymbol = (TypeSymbol)((ISymbolTable)ns).FindSymbol(mappedTypeName, null, SymbolFilter.Types);
                Debug.Assert(typeSymbol != null);

                return typeSymbol;
            }

            return null;
        }
            public override string GetName( IntrinsicType intrinsicType, ReflectionNameOptions options )
            {
                string name;
                if ( this.intrinsicNames.TryGetValue( intrinsicType, out name ) )
                    return name;

                return base.GetName( intrinsicType, options );
            }
Example #9
0
 public IntrinsicInfo(X86Instruction inst, IntrinsicType type)
 {
     Inst = inst;
     Type = type;
 }
Example #10
0
        public static IntrinsicType GetIntrinsicType(TokenType type)
        {
            IntrinsicType Result = IntrinsicType.None;

            switch (type)
            {
            case TokenType.Boolean:
                Result = IntrinsicType.Boolean;
                break;

            case TokenType.SByte:
                Result = IntrinsicType.SByte;
                break;

            case TokenType.Byte:
                Result = IntrinsicType.Byte;
                break;

            case TokenType.Short:
                Result = IntrinsicType.Short;
                break;

            case TokenType.UShort:
                Result = IntrinsicType.UShort;
                break;

            case TokenType.Integer:
                Result = IntrinsicType.Integer;
                break;

            case TokenType.UInteger:
                Result = IntrinsicType.UInteger;
                break;

            case TokenType.Long:
                Result = IntrinsicType.Long;
                break;

            case TokenType.ULong:
                Result = IntrinsicType.ULong;
                break;

            case TokenType.Decimal:
                Result = IntrinsicType.Decimal;
                break;

            case TokenType.Single:
                Result = IntrinsicType.Single;
                break;

            case TokenType.Double:
                Result = IntrinsicType.Double;
                break;

            case TokenType.Date:
                Result = IntrinsicType.Date;
                break;

            case TokenType.Char:
                Result = IntrinsicType.Char;
                break;

            case TokenType.String:
                Result = IntrinsicType.String;
                break;

            case TokenType.Object:
                Result = IntrinsicType.Object;
                break;

            case TokenType.Variant:
                //TODO: Do not allow Variant in VB .NET
                Result = IntrinsicType.Variant;
                break;

            case TokenType.Currency:
                //TODO: Do not allow Currency in VB .NET
                Result = IntrinsicType.Currency;
                break;

            default:
                Result = IntrinsicType.None;
                break;
            }

            return(Result);
        }
 public IntrinsicTypeReference(IntrinsicType type)
 {
     _type = type;
 }
Example #12
0
 public Intrinsic(IntrinsicType type, InterfaceMethod interfaceMethod)
 {
     this.Type            = type;
     this.InterfaceMethod = interfaceMethod;
 }