private static bool ResolveCallClass(IPrecursorExpression node, IFeatureInstance selectedPrecursor, List <IExpressionType> mergedArgumentList, TypeArgumentStyles argumentStyle, IErrorList errorList, ref ResolvedExpression resolvedExpression, out ISealableList <IParameter> selectedParameterList, out ISealableList <IParameter> selectedResultList, out List <IExpressionType> resolvedArgumentList)
        {
            selectedParameterList = null;
            selectedResultList    = null;
            resolvedArgumentList  = null;

            IList <IArgument> ArgumentList = node.ArgumentList;

            if (ArgumentList.Count > 0)
            {
                errorList.AddError(new ErrorInvalidExpression(node));
                return(false);
            }
            else
            {
                ICompiledFeature OperatorFeature  = selectedPrecursor.Feature;
                ITypeName        OperatorTypeName = OperatorFeature.ResolvedEffectiveTypeName.Item;
                ICompiledType    OperatorType     = OperatorFeature.ResolvedEffectiveType.Item;
                IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >();

                resolvedExpression.ResolvedResult    = new ResultType(OperatorTypeName, OperatorType, string.Empty);
                resolvedExpression.ResolvedException = new ResultException();
                selectedParameterList = new SealableList <IParameter>();
                selectedResultList    = new SealableList <IParameter>();
                resolvedArgumentList  = new List <IExpressionType>();
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// This constructor creates a type from a ITypeName.
        /// </summary>
        public PSTypeName(ITypeName typeName)
        {
            if (typeName == null)
            {
                throw PSTraceSource.NewArgumentNullException("typeName");
            }

            _type = typeName.GetReflectionType();
            if (_type != null)
            {
                Name = _type.FullName;
            }
            else
            {
                var t = typeName as TypeName;
                if (t != null && t._typeDefinitionAst != null)
                {
                    TypeDefinitionAst = t._typeDefinitionAst;
                    Name = TypeDefinitionAst.Name;
                }
                else
                {
                    _type = null;
                    Name  = typeName.FullName;
                }
            }
        }
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IIndexerType node, object data)
        {
            IClassType BaseType = ((Tuple <IClassType, ISealableList <IParameter> >)data).Item1;
            ISealableList <IParameter> ParameterTable = ((Tuple <IClassType, ISealableList <IParameter> >)data).Item2;

            IClass      EmbeddingClass = node.EmbeddingClass;
            IObjectType BaseTypeItem   = (IObjectType)node.BaseType;
            IObjectType EntityTypeItem = (IObjectType)node.EntityType;

            Debug.Assert(node.ParameterTable.Count == 0);
            node.ParameterTable.AddRange(ParameterTable);
            node.ParameterTable.Seal();

            ITypeName BaseTypeName = BaseTypeItem.ResolvedTypeName.Item;

            ITypeName     EntityTypeName = EntityTypeItem.ResolvedTypeName.Item;
            ICompiledType EntityType     = EntityTypeItem.ResolvedType.Item;

#if COVERAGE
            string TypeString = node.ToString();
            Debug.Assert(!node.IsReference);
            Debug.Assert(node.IsValue);
#endif

            IndexerType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType, EntityTypeName, EntityType, node.IndexerKind, node.IndexParameterList, node.ParameterEnd, node.GetRequireList, node.GetEnsureList, node.GetExceptionIdentifierList, node.SetRequireList, node.SetEnsureList, node.SetExceptionIdentifierList, out ITypeName ResolvedTypeName, out ICompiledType ResolvedType);

            node.ResolvedTypeName.Item = ResolvedTypeName;
            node.ResolvedType.Item     = ResolvedType;
        }
示例#4
0
        internal static Type Lookup(ITypeName typeName, TypeResolutionState typeResolutionState)
        {
            Type result;

            s_cache.TryGetValue(Tuple.Create(typeName, typeResolutionState), out result);
            return(result);
        }
示例#5
0
        /// <summary>
        ///     Formats and appends a type name together with its generic types to the context.
        /// </summary>
        /// <param name="typeName">The type name to append.</param>
        /// <returns>The context after appending.</returns>
        public SSTPrintingContext Type(ITypeName typeName)
        {
            if (typeName.IsDelegateType)
            {
                return(Type(typeName.AsDelegateTypeName.DelegateType));
            }

            if (typeName.IsTypeParameter)
            {
                var tpn = typeName.AsTypeParameterName;
                if (tpn.IsBound)
                {
                    return(Type(tpn.TypeParameterType));
                }
                return(TypeNameOnly(tpn));
            }

            _seenNamespaces.Add(typeName.Namespace);

            TypeNameOnly(typeName);

            if (typeName.HasTypeParameters)
            {
                TypeParameters(typeName.TypeParameters);
            }

            return(this);
        }
        private static ITypeName ToAnonymousName(ITypeName type)
        {
            if (type.IsUnknown)
            {
                return(type);
            }
            if (type.IsPredefined)
            {
                return(type);
            }
            if (type.IsDelegateType)
            {
                return(ToAnonymousType_Delegate(type.AsDelegateTypeName));
            }
            if (type.IsArray)
            {
                return(ToAnonymousType_Array(type.AsArrayTypeName));
            }
            if (type.IsTypeParameter)
            {
                return(ToAnonymousType_TypeParameter(type.AsTypeParameterName));
            }

            if (!"TypeName".Equals(type.GetType().Name))
            {
                Asserts.Fail <ITypeName>("unknown type implementation");
            }

            return(ToAnonymousType_Regular(type));
        }
示例#7
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IEntityDeclaration node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IName  EntityName     = (IName)node.EntityName;
            string ValidText      = EntityName.ValidText.Item;
            IClass EmbeddingClass = node.EmbeddingClass;

            IObjectType   FieldType     = (IObjectType)node.EntityType;
            ITypeName     ValidTypeName = FieldType.ResolvedTypeName.Item;
            ICompiledType ValidType     = FieldType.ResolvedType.Item;

            IScopeAttributeFeature NewEntity;

            if (node.DefaultValue.IsAssigned)
            {
                Success = ScopeAttributeFeature.Create(node, ValidText, FieldType.ResolvedTypeName.Item, FieldType.ResolvedType.Item, (IExpression)node.DefaultValue.Item, ErrorList, out NewEntity);
            }
            else
            {
                NewEntity = ScopeAttributeFeature.Create(node, ValidText, FieldType.ResolvedTypeName.Item, FieldType.ResolvedType.Item);
            }

            if (Success)
            {
                data = NewEntity;
            }

            return(Success);
        }
示例#8
0
        internal static Type ResolveTypeName(ITypeName typeName)
        {
            Type reflectionType = typeName.GetReflectionType();

            if (reflectionType != null)
            {
                return(reflectionType);
            }
            GenericTypeName name = typeName as GenericTypeName;

            if (name != null)
            {
                Type   genericType   = name.GetGenericType(ResolveTypeName(name.TypeName));
                Type[] typeArguments = (from arg in name.GenericArguments select ResolveTypeName(arg)).ToArray <Type>();
                try
                {
                    if ((genericType != null) && genericType.ContainsGenericParameters)
                    {
                        genericType.MakeGenericType(typeArguments);
                    }
                }
                catch (Exception exception)
                {
                    CommandProcessorBase.CheckForSevereException(exception);
                    throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFoundWithMessage", ParserStrings.TypeNotFoundWithMessage, new object[] { typeName.FullName, exception.Message });
                }
            }
            ArrayTypeName name2 = typeName as ArrayTypeName;

            if (name2 != null)
            {
                ResolveTypeName(name2.ElementType);
            }
            throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFound", ParserStrings.TypeNotFound, new object[] { typeName.FullName });
        }
示例#9
0
        internal TypeBuilder?GetRegisteredType(ITypeName name)
        {
            TypeBuilder?result = null;

            name_cache.TryGetValue(name, out result);
            return(result);
        }
示例#10
0
        private bool DispatchTypeName(ITypeName type, int genericArgumentCount, bool isAttribute)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();
            var typeName = type as TypeName;

            if (typeName != null)
            {
                return(VisitTypeName(typeName, genericArgumentCount, isAttribute));
            }
            else
            {
                var arrayTypeName = type as ArrayTypeName;
                if (arrayTypeName != null)
                {
                    return(VisitArrayTypeName(arrayTypeName));
                }
                else
                {
                    var genericTypeName = type as GenericTypeName;
                    if (genericTypeName != null)
                    {
                        return(VisitGenericTypeName(genericTypeName));
                    }
                }
            }

            return(false);
        }
示例#11
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(ITypedef node, object data)
        {
            IObjectType DefinedTypeItem = (IObjectType)node.DefinedType;

            ITypeName     DefinedTypeName = DefinedTypeItem.ResolvedTypeName.Item;
            ICompiledType DefinedType     = DefinedTypeItem.ResolvedType.Item;

            node.ResolvedDefinedTypeName.Item = DefinedTypeName;
            node.ResolvedDefinedType.Item     = DefinedType;

            if (!DefinedType.OriginatingTypedef.IsAssigned)
            {
                DefinedType.OriginatingTypedef.Item = node;
            }

            IName  EntityName     = (IName)node.EntityName;
            IClass EmbeddingClass = node.EmbeddingClass;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            bool IsFound = FeatureName.TableContain(EmbeddingClass.LocalTypedefTable, ValidText, out IFeatureName Key, out ITypedefType ResolvedTypedefType);

            Debug.Assert(IsFound && ResolvedTypedefType != null);

            ResolvedTypedefType.ReferencedTypeName.Item = DefinedTypeName;
            ResolvedTypedefType.ReferencedType.Item     = DefinedType;

#if COVERAGE
            string TypeString = ResolvedTypedefType.ToString();
#endif
        }
示例#12
0
        /// <summary>
        /// Creates a function type with resolved arguments.
        /// </summary>
        /// <param name="baseTypeName">The type name of the resolved base type.</param>
        /// <param name="baseType">The base type.</param>
        /// <param name="resolvedBaseType">The resolved base type.</param>
        /// <param name="entityTypeName">The type name of the resolved result type.</param>
        /// <param name="entityType">The type of the resolved result type.</param>
        /// <param name="propertyKind">The type of the property.</param>
        /// <param name="getEnsureList">The list of ensure assertions for the getter.</param>
        /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param>
        /// <param name="setRequireList">The list of require assertions for the setter.</param>
        /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static void BuildType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
        {
            IPropertyType ResolvedPropertyType = new PropertyType(baseTypeName, baseType, resolvedBaseType, entityTypeName, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList);

            resolvedTypeName = new TypeName(ResolvedPropertyType.TypeFriendlyName);
            resolvedType     = ResolvedPropertyType;
        }
示例#13
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IClass node, object data)
        {
            ISealableDictionary <string, IImportedClass> ResolvedImportedClassTable = node.ImportedClassTable;

            foreach (KeyValuePair <string, IImportedClass> Entry in ResolvedImportedClassTable)
            {
                ITypeName  ImportedClassTypeName = Entry.Value.ResolvedClassTypeName.Item;
                IClassType ImportedClassType     = Entry.Value.ResolvedClassType.Item;

                node.ResolvedImportedClassTable.Add(ImportedClassTypeName, ImportedClassType);
                node.TypeTable.Add(ImportedClassTypeName, ImportedClassType);
            }

            node.ResolvedImportedClassTable.Seal();

            Dictionary <Guid, Tuple <ITypeName, IClassType> > ImportedLanguageTypeTable = node.ImportedLanguageTypeTable;

            Debug.Assert(ImportedLanguageTypeTable.Count == 0);

            foreach (KeyValuePair <ITypeName, IClassType> Item in node.ResolvedImportedClassTable)
            {
                IClass BaseClass     = Item.Value.BaseClass;
                Guid   BaseClassGuid = BaseClass.ClassGuid;

                if (LanguageClasses.GuidToName.ContainsKey(BaseClassGuid))
                {
                    Debug.Assert(!ImportedLanguageTypeTable.ContainsKey(BaseClassGuid));
                    Tuple <ITypeName, IClassType> ImportedLanguageEntry = new Tuple <ITypeName, IClassType>(Item.Key, Item.Value);
                    ImportedLanguageTypeTable.Add(BaseClassGuid, ImportedLanguageEntry);
                }
            }
        }
        private static string AnonymizedFullName(this ITypeName type, bool anonymize)
        {
            var sb = new StringBuilder();

            if (type.IsNestedType)
            {
                Asserts.NotNull(type.DeclaringType);
                var dt = anonymize ? type.DeclaringType.AnonymizedFullName(true) : type.DeclaringType.Identifier;
                sb.Append(dt).Append('+');
            }
            else
            {
                var ns = type.Namespace;
                if (!ns.IsGlobalNamespace)
                {
                    sb.Append(anonymize ? ns.ToAnonymousName().Identifier : ns.Identifier).Append(".");
                }
            }

            sb.Append(anonymize ? type.Name.ToHash() : type.Name);
            if (type.HasTypeParameters)
            {
                sb.Append("`{0}".FormatEx(type.TypeParameters.Count));
            }

            return(sb.ToString());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FormalGenericType"/> class.
 /// </summary>
 /// <param name="formalGeneric">The generic from which this instance is issued.</param>
 /// <param name="resolvedTypeName">The associated unique type name.</param>
 public FormalGenericType(IGeneric formalGeneric, ITypeName resolvedTypeName)
 {
     FormalGeneric    = formalGeneric;
     ResolvedTypeName = resolvedTypeName;
     DiscreteTable.Seal();
     NumberKind = NumberKinds.NotChecked;
 }
示例#16
0
文件: TypeOps.cs 项目: nickchal/pash
 internal static Type ResolveTypeName(ITypeName typeName)
 {
     Type reflectionType = typeName.GetReflectionType();
     if (reflectionType != null)
     {
         return reflectionType;
     }
     GenericTypeName name = typeName as GenericTypeName;
     if (name != null)
     {
         Type genericType = name.GetGenericType(ResolveTypeName(name.TypeName));
         Type[] typeArguments = (from arg in name.GenericArguments select ResolveTypeName(arg)).ToArray<Type>();
         try
         {
             if ((genericType != null) && genericType.ContainsGenericParameters)
             {
                 genericType.MakeGenericType(typeArguments);
             }
         }
         catch (Exception exception)
         {
             CommandProcessorBase.CheckForSevereException(exception);
             throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFoundWithMessage", ParserStrings.TypeNotFoundWithMessage, new object[] { typeName.FullName, exception.Message });
         }
     }
     ArrayTypeName name2 = typeName as ArrayTypeName;
     if (name2 != null)
     {
         ResolveTypeName(name2.ElementType);
     }
     throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFound", ParserStrings.TypeNotFound, new object[] { typeName.FullName });
 }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IndexerType"/> class.
        /// </summary>
        /// <param name="baseTypeName">The type name of the resolved base type.</param>
        /// <param name="baseType">The type of the resolved base type.</param>
        /// <param name="entityTypeName">The type name of the resolved result type.</param>
        /// <param name="entityType">The type of the resolved result type.</param>
        /// <param name="indexerKind">Type of indexer.</param>
        /// <param name="indexParameterList">The list of parameters.</param>
        /// <param name="parameterEnd">The indexer parameter end type.</param>
        /// <param name="getRequireList">The list of require assertions for the getter.</param>
        /// <param name="getEnsureList">The list of ensure assertions for the getter.</param>
        /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param>
        /// <param name="setRequireList">The list of require assertions for the setter.</param>
        /// <param name="setEnsureList">The list of ensure assertions for the setter.</param>
        /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param>
        public IndexerType(ITypeName baseTypeName, IClassType baseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType indexerKind, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd, IList <IAssertion> getRequireList, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IAssertion> setEnsureList, IList <IIdentifier> setExceptionIdentifierList)
            : this()
        {
            BaseType     = baseType;
            EntityType   = null;
            ParameterEnd = parameterEnd;
            IndexerKind  = indexerKind;

            ResolvedBaseTypeName.Item   = baseTypeName;
            ResolvedBaseType.Item       = baseType;
            ResolvedEntityTypeName.Item = entityTypeName;
            ResolvedEntityType.Item     = entityType;
            IndexParameterList          = indexParameterList;
            GetRequireList             = getRequireList;
            GetEnsureList              = getEnsureList;
            GetExceptionIdentifierList = getExceptionIdentifierList;
            SetRequireList             = setRequireList;
            SetEnsureList              = setEnsureList;
            SetExceptionIdentifierList = setExceptionIdentifierList;

            foreach (IEntityDeclaration Item in indexParameterList)
            {
                IName  ParameterName = (IName)Item.EntityName;
                string ValidText     = ParameterName.ValidText.Item;
                IScopeAttributeFeature ParameterFeature = Item.ValidEntity.Item;
                ParameterTable.Add(new Parameter(ValidText, ParameterFeature));
            }
            ParameterTable.Seal();
        }
示例#18
0
        private static ITypeName ExpandTypeName(IReadOnlyDictionary <string, string> typeAccelerators, GenericTypeName typeName)
        {
            var genericArgs = new ITypeName[typeName.GenericArguments.Count];

            for (int i = 0; i < genericArgs.Length; i++)
            {
                genericArgs[i] = ExpandTypeName(typeAccelerators, typeName.GenericArguments[i]);
            }

            ITypeName expandedTypeName = ExpandTypeName(typeAccelerators, (TypeName)typeName.TypeName, genericArgCount: genericArgs.Length);

            bool canUseOldTypeName = expandedTypeName == typeName.TypeName;

            for (int i = 0; i < genericArgs.Length; i++)
            {
                if (!canUseOldTypeName)
                {
                    break;
                }

                canUseOldTypeName &= genericArgs[i] == typeName.GenericArguments[i];
            }

            if (canUseOldTypeName)
            {
                return(typeName);
            }

            return(new GenericTypeName(s_emptyExtent, expandedTypeName, genericArgs));
        }
示例#19
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IProcedureFeature node, object data)
        {
            IClass     EmbeddingClass = node.EmbeddingClass;
            ITypeName  BaseTypeName   = EmbeddingClass.ResolvedClassTypeName.Item;
            IClassType BaseType       = EmbeddingClass.ResolvedClassType.Item;

            IList <ICommandOverloadType> OverloadList = new List <ICommandOverloadType>();

            foreach (ICommandOverload Item in node.OverloadList)
            {
                OverloadList.Add(Item.ResolvedAssociatedType.Item);
            }

            ProcedureType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType.SourceType, BaseType, OverloadList, out ITypeName ResolvedProcedureTypeName, out IProcedureType ResolvedProcedureType);
            node.ResolvedAgentTypeName.Item = ResolvedProcedureTypeName;
            node.ResolvedAgentType.Item     = ResolvedProcedureType;

            node.ResolvedFeature.Item = node;

#if COVERAGE
            string TypeString = ResolvedProcedureType.ToString();
            Debug.Assert(!node.ResolvedEffectiveTypeName.IsAssigned);
            Debug.Assert(!node.ResolvedEffectiveType.IsAssigned);
#endif
        }
示例#20
0
        /// <summary>
        /// Creates an instance of a class type, or reuse an existing instance.
        /// </summary>
        /// <param name="instancingClassType">The class type to instanciate.</param>
        /// <param name="resolvedTypeName">The proposed type instance name.</param>
        /// <param name="resolvedType">The proposed type instance.</param>
        public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType)
        {
            bool IsNewInstance = false;

            ISealableDictionary <string, ICompiledType> InstancedTypeArgumentTable = new SealableDictionary <string, ICompiledType>();

            foreach (KeyValuePair <string, ICompiledType> TypeArgument in TypeArgumentTable)
            {
                ITypeName     InstancedTypeArgumentName = null;
                ICompiledType InstancedTypeArgument     = TypeArgument.Value;
                InstancedTypeArgument.InstanciateType(instancingClassType, ref InstancedTypeArgumentName, ref InstancedTypeArgument);

                InstancedTypeArgumentTable.Add(TypeArgument.Key, InstancedTypeArgument);

                if (InstancedTypeArgument != TypeArgument.Value)
                {
                    IsNewInstance = true;
                }
            }

            if (IsNewInstance)
            {
                ISealableDictionary <ITypeName, ICompiledType> InstancingTypeTable = instancingClassType.GetTypeTable();
                ResolveType(InstancingTypeTable, BaseClass, InstancedTypeArgumentTable, instancingClassType, out resolvedTypeName, out resolvedType);
            }
        }
示例#21
0
        /// <summary>
        /// Creates a <see cref="ClassType"/>.
        /// </summary>
        /// <param name="baseClass">The class used to instanciate this type.</param>
        /// <param name="typeArgumentTable">Arguments if the class is generic.</param>
        /// <param name="instancingClassType">The class type if this instance is a derivation (such as renaming).</param>
        public static IClassType Create(IClass baseClass, ISealableDictionary <string, ICompiledType> typeArgumentTable, ICompiledTypeWithFeature instancingClassType)
        {
            ISealableDictionary <ITypeName, ICompiledType> ConformanceTable = new SealableDictionary <ITypeName, ICompiledType>();

            if (baseClass.ResolvedClassType.IsAssigned)
            {
                IClassType ResolvedClassType = baseClass.ResolvedClassType.Item;

                if (ResolvedClassType.ConformanceTable.IsSealed)
                {
                    foreach (IInheritance InheritanceItem in baseClass.InheritanceList)
                    {
                        if (InheritanceItem.Conformance == BaseNode.ConformanceType.Conformant)
                        {
                            ITypeName     ParentTypeName = InheritanceItem.ResolvedParentTypeName.Item;
                            ICompiledType ParentType     = InheritanceItem.ResolvedParentType.Item;
                            ParentType.InstanciateType(instancingClassType, ref ParentTypeName, ref ParentType);
                            ConformanceTable.Add(ParentTypeName, ParentType);
                        }
                    }

                    ConformanceTable.Seal();
                }
            }

            IClassType ClassType = new ClassType(baseClass, typeArgumentTable, instancingClassType, ConformanceTable);

            return(ClassType);
        }
示例#22
0
        /// <summary>
        ///     Derives an array-type name from this type name.
        /// </summary>
        /// <param name="baseType">The array's base type</param>
        /// <param name="rank">the rank of the array; must be greater than 0</param>
        public static IArrayTypeName From(ITypeName baseType, int rank)
        {
            Asserts.That(rank > 0, "rank smaller than 1");
            rank     = baseType.IsArray ? baseType.AsArrayTypeName.Rank + rank : rank;
            baseType = baseType.IsArray ? baseType.AsArrayTypeName.ArrayBaseType : baseType;
            var arrMarker = CreateArrayMarker(rank);

            if (baseType.IsTypeParameter)
            {
                if (baseType.AsTypeParameterName.IsBound)
                {
                    var paramType = baseType.AsTypeParameterName.TypeParameterType;
                    return
                        (new TypeParameterName("{0}{1} -> {2}".FormatEx(baseType.Name, arrMarker, paramType.Identifier)));
                }
                return(new TypeParameterName("{0}{1}".FormatEx(baseType.Name, arrMarker)));
            }

            if (baseType.IsPredefined)
            {
                return(new PredefinedTypeName(baseType.Identifier + arrMarker));
            }

            if (baseType.IsDelegateType || baseType.IsUnknown)
            {
                return(new ArrayTypeName(baseType.Identifier + arrMarker));
            }

            return(new ArrayTypeName(InsertMarkerAfterRawName(baseType, arrMarker)));
        }
        private static bool IsWithinGetter(ISource source, IErrorList errorList, out ITypeName resultTypeName, out ICompiledType resultType)
        {
            resultTypeName = null;
            resultType     = null;

            if (source.EmbeddingOverload is IQueryOverload AsQueryOverload)
            {
                return(CheckQueryConsistency(source, AsQueryOverload, errorList, out resultTypeName, out resultType));
            }
            else if (source.EmbeddingFeature is IPropertyFeature AsPropertyFeature)
            {
                if (CheckGetterConsistency(source, AsPropertyFeature.GetterBody, errorList))
                {
                    resultTypeName = AsPropertyFeature.ResolvedEntityTypeName.Item;
                    resultType     = AsPropertyFeature.ResolvedEntityType.Item;
                    return(true);
                }
            }
            else if (source.EmbeddingFeature is IIndexerFeature AsIndexerFeature)
            {
                if (CheckGetterConsistency(source, AsIndexerFeature.GetterBody, errorList))
                {
                    resultTypeName = AsIndexerFeature.ResolvedEntityTypeName.Item;
                    resultType     = AsIndexerFeature.ResolvedEntityType.Item;
                    return(true);
                }
            }
            else
            {
                errorList.AddError(new ErrorUnavailableResult(source));
            }

            return(false);
        }
示例#24
0
 protected static MethodReference MethodRef(string name,
                                            ITypeName retType,
                                            ITypeName declType,
                                            string varRef = "this")
 {
     return(MethodRef(Method("[{0}] [{1}].{2}()", retType, declType, name), VarRef(varRef)));
 }
示例#25
0
        /// <summary>
        /// Creates a procedure type with resolved arguments.
        /// </summary>
        /// <param name="baseTypeName">Name of the resolved base type.</param>
        /// <param name="baseType">The base type.</param>
        /// <param name="resolvedBaseType">The resolved base type.</param>
        /// <param name="overloadList">The list of resolved overloads.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static void BuildType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, IList <ICommandOverloadType> overloadList, out ITypeName resolvedTypeName, out IProcedureType resolvedType)
        {
            IProcedureType ResolvedProcedureType = new ProcedureType(baseTypeName, baseType, resolvedBaseType, overloadList);

            resolvedTypeName = new TypeName(ResolvedProcedureType.TypeFriendlyName);
            resolvedType     = ResolvedProcedureType;
        }
        private bool ResolveClassTypeRenames(IClassType classType, IConstraint node, out ITypeName destinationTypeName, out ICompiledType destinationType)
        {
            bool Success = false;

            destinationType     = null;
            destinationTypeName = null;

            IClass EmbeddingClass = node.EmbeddingClass;
            ISealableDictionary <string, string> SourceIdentifierTable      = new SealableDictionary <string, string>(); // string (source) -> string (destination)
            ISealableDictionary <string, string> DestinationIdentifierTable = new SealableDictionary <string, string>(); // string (destination) -> string (source)
            ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > RenamedExportTable = classType.ExportTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, ITypedefType>     RenamedTypedefTable  = classType.TypedefTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, IDiscrete>        RenamedDiscreteTable = classType.DiscreteTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFeatureTable  = classType.FeatureTable.CloneUnsealed();

            bool AllRenameValid = true;

            foreach (KeyValuePair <IIdentifier, IIdentifier> Entry in node.RenameTable)
            {
                if (!CheckRename(Entry, new IDictionaryIndex <IFeatureName>[] { RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name)))
                {
                    AllRenameValid = false;
                }
            }

            if (AllRenameValid)
            {
                IClassType ClonedType = classType.CloneWithRenames(RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable, EmbeddingClass.ResolvedClassType.Item);
                destinationType     = ClonedType;
                destinationTypeName = new TypeName(destinationType.TypeFriendlyName);
                Success             = true;
            }

            return(Success);
        }
示例#27
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IFunctionFeature node, object data)
        {
            IClass      EmbeddingClass = node.EmbeddingClass;
            ITypeName   BaseTypeName   = EmbeddingClass.ResolvedClassTypeName.Item;
            IClassType  BaseType       = EmbeddingClass.ResolvedClassType.Item;
            IResultType CommonResults  = (IResultType)data;

            IList <IQueryOverloadType> OverloadList = new List <IQueryOverloadType>();

            foreach (IQueryOverload Overload in node.OverloadList)
            {
                Debug.Assert(Overload.ResolvedAssociatedType.IsAssigned);
                OverloadList.Add(Overload.ResolvedAssociatedType.Item);
            }

            ITypeName     ResolvedFunctionTypeName;
            IFunctionType ResolvedFunctionType;

            FunctionType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType.SourceType, BaseType, OverloadList, out ResolvedFunctionTypeName, out ResolvedFunctionType);

            node.ResolvedAgentTypeName.Item = ResolvedFunctionTypeName;
            node.ResolvedAgentType.Item     = ResolvedFunctionType;
            node.ResolvedFeature.Item       = node;

#if COVERAGE
            string TypeString = ResolvedFunctionType.ToString();
#endif
        }
示例#28
0
        /// <summary>
        /// Creates an instance of a class type, or reuse an existing instance.
        /// </summary>
        /// <param name="instancingClassType">The class type to instanciate.</param>
        /// <param name="resolvedTypeName">The proposed type instance name.</param>
        /// <param name="resolvedType">The proposed type instance.</param>
        public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType)
        {
            bool IsNewInstance = false;

            ITypeName     InstancedBaseTypeName = ResolvedBaseTypeName.Item;
            ICompiledType InstancedBaseType     = ResolvedBaseType.Item;

            InstancedBaseType.InstanciateType(instancingClassType, ref InstancedBaseTypeName, ref InstancedBaseType);
            IsNewInstance |= InstancedBaseType != ResolvedBaseType.Item;

            IList <ICommandOverloadType> InstancedOverloadList = new List <ICommandOverloadType>();

            foreach (ICommandOverloadType Overload in OverloadList)
            {
                ICommandOverloadType InstancedOverload = Overload;
                CommandOverloadType.InstanciateCommandOverloadType(instancingClassType, ref InstancedOverload);
                IsNewInstance |= InstancedOverload != Overload;

                InstancedOverloadList.Add(InstancedOverload);
            }

            if (IsNewInstance)
            {
                ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable();
                ResolveType(TypeTable, InstancedBaseTypeName, (IObjectType)BaseType, (ICompiledTypeWithFeature)InstancedBaseType, InstancedOverloadList, out resolvedTypeName, out IProcedureType ResolvedProcedureType);
                resolvedType = ResolvedProcedureType;
            }
        }
示例#29
0
        private static void GetCommonResultType(IList <IQueryOverloadType> overloadList, int index, out ITypeName resultTypeName, out ICompiledType resultType)
        {
            IList <IParameter> SameIndexList = new List <IParameter>();

            foreach (IQueryOverloadType Overload in overloadList)
            {
                ISealableList <IParameter> ResultTable = Overload.ResultTable;
                if (index < ResultTable.Count)
                {
                    SameIndexList.Add(ResultTable[index]);
                }
            }

            IParameter    SelectedParameter         = SameIndexList[0];
            ITypeName     SelectedParameterTypeName = SelectedParameter.ResolvedParameter.ResolvedEffectiveTypeName.Item;
            ICompiledType SelectedParameterType     = SelectedParameter.ResolvedParameter.ResolvedEffectiveType.Item;

            for (int i = 1; i < SameIndexList.Count; i++)
            {
                IParameter    CurrentParameter         = SameIndexList[i];
                ITypeName     CurrentParameterTypeName = CurrentParameter.ResolvedParameter.ResolvedEffectiveTypeName.Item;
                ICompiledType CurrentParameterType     = CurrentParameter.ResolvedParameter.ResolvedEffectiveType.Item;

                if (ObjectType.TypeConformToBase(SelectedParameterType, CurrentParameterType, isConversionAllowed: false))
                {
                    SelectedParameter         = CurrentParameter;
                    SelectedParameterTypeName = CurrentParameterTypeName;
                    SelectedParameterType     = CurrentParameterType;
                }
            }

            resultTypeName = SelectedParameterTypeName;
            resultType     = SelectedParameterType;
        }
示例#30
0
        private static string InsertMarkerAfterRawName(ITypeName baseType, string arrayMarker)
        {
            Asserts.Not(baseType.IsArray);
            Asserts.Not(baseType.IsDelegateType);
            Asserts.Not(baseType.IsTypeParameter);
            Asserts.Not(baseType.IsPredefined);

            var id     = baseType.Identifier;
            var arrIdx = -1;

            if (baseType.HasTypeParameters)
            {
                var closeGeneric = id.LastIndexOf("]", StringComparison.Ordinal);
                arrIdx = id.FindCorrespondingOpenBracket(closeGeneric);
            }
            else
            {
                var beforeAssemble = id.Length - baseType.Assembly.Identifier.Length;
                var comma          = id.FindPrevious(beforeAssemble, ',');
                arrIdx = comma;
            }

            Asserts.Not(arrIdx == -1);
            return(id.Insert(arrIdx, arrayMarker));
        }
示例#31
0
        private bool FindSourceItemPrecursor(IClassType instancingClassType, IFeatureInstance featureInstance, IPrecursorInstance precursorInstance, ref ITypeName indexTypeName, ref ICompiledType indexType)
        {
            bool IsConformantToEnumerable = false;

            if (precursorInstance.Ancestor.BaseClass.ClassGuid == LanguageClasses.OverLoopSource.Guid)
            {
                if (precursorInstance.Precursor.Feature is IPropertyFeature AsPropertyAncestor)
                {
                    if (AsPropertyAncestor.ValidFeatureName.Item.Name == "Item")
                    {
                        if (featureInstance.Feature is IPropertyFeature AsPropertyFeature)
                        {
                            Debug.Assert(indexTypeName == null);
                            Debug.Assert(indexType == null);

                            ITypeName     IndexResultTypeName = AsPropertyFeature.ResolvedEntityTypeName.Item;
                            ICompiledType IndexResultType     = AsPropertyFeature.ResolvedEntityType.Item;

                            IndexResultType.InstanciateType(instancingClassType, ref IndexResultTypeName, ref IndexResultType);

                            IsConformantToEnumerable = true;
                            indexTypeName            = IndexResultTypeName;
                            indexType = IndexResultType;
                        }
                    }
                }
            }

            return(IsConformantToEnumerable);
        }
示例#32
0
 private void CheckTypeName(Ast ast, ITypeName typename)
 {
     Type reflectionType = typename.GetReflectionType();
     if ((reflectionType == null) || (Type.GetTypeCode(reflectionType.IsArray ? reflectionType.GetElementType() : reflectionType) == TypeCode.Object))
     {
         this.ReportError(ast, () => ParserStrings.TypeNotAllowedInDataSection, new object[] { typename.FullName });
     }
 }
示例#33
0
 public TypeExpressionAst(IScriptExtent extent, ITypeName typeName) : base(extent)
 {
     if (typeName == null)
     {
         throw PSTraceSource.NewArgumentNullException("typeName");
     }
     this.TypeName = typeName;
 }
示例#34
0
 protected AttributeBaseAst(IScriptExtent extent, ITypeName typeName) : base(extent)
 {
     if (typeName == null)
     {
         throw PSTraceSource.NewArgumentNullException("typeName");
     }
     this.TypeName = typeName;
 }
示例#35
0
 public ArrayTypeName(IScriptExtent extent, ITypeName elementType, int rank)
 {
     if ((extent == null) || (elementType == null))
     {
         throw PSTraceSource.NewArgumentNullException((extent == null) ? "extent" : "name");
     }
     if (rank <= 0)
     {
         throw PSTraceSource.NewArgumentException("rank");
     }
     this._extent = extent;
     this.Rank = rank;
     this.ElementType = elementType;
 }
示例#36
0
 public GenericTypeName(IScriptExtent extent, ITypeName genericTypeName, IEnumerable<ITypeName> genericArguments)
 {
     if ((genericTypeName == null) || (extent == null))
     {
         throw PSTraceSource.NewArgumentNullException((extent == null) ? "extent" : "genericTypeName");
     }
     if ((genericArguments == null) || !genericArguments.Any<ITypeName>())
     {
         throw PSTraceSource.NewArgumentException("genericArguments");
     }
     this._extent = extent;
     this.TypeName = genericTypeName;
     this.GenericArguments = new ReadOnlyCollection<ITypeName>(genericArguments.ToArray<ITypeName>());
 }
示例#37
0
 internal static void CheckArrayTypeNameDepth(ITypeName typeName, IScriptExtent extent, Parser parser)
 {
     int num = 0;
     for (ITypeName name = typeName; !(name is TypeName); name = ((ArrayTypeName) name).ElementType)
     {
         num++;
         if (num > 200)
         {
             parser.ReportError(extent, ParserStrings.ScriptTooComplicated, new object[0]);
             return;
         }
         if (!(name is ArrayTypeName))
         {
             break;
         }
     }
 }
示例#38
0
 public AttributeAst(IScriptExtent extent, ITypeName typeName, IEnumerable<ExpressionAst> positionalArguments, IEnumerable<NamedAttributeArgumentAst> namedArguments) : base(extent, typeName)
 {
     if ((positionalArguments != null) && positionalArguments.Any<ExpressionAst>())
     {
         this.PositionalArguments = new ReadOnlyCollection<ExpressionAst>(positionalArguments.ToArray<ExpressionAst>());
         base.SetParents(positionalArguments);
     }
     else
     {
         this.PositionalArguments = EmptyPositionalArguments;
     }
     if ((namedArguments != null) && namedArguments.Any<NamedAttributeArgumentAst>())
     {
         this.NamedArguments = new ReadOnlyCollection<NamedAttributeArgumentAst>(namedArguments.ToArray<NamedAttributeArgumentAst>());
         base.SetParents(namedArguments);
     }
     else
     {
         this.NamedArguments = EmptyNamedAttributeArguments;
     }
 }
示例#39
0
        internal static string MapTypeNameToMofType(ITypeName typeName, string memberName, string className, out bool isArrayType, out string embeddedInstanceType, List<object> embeddedInstanceTypes, ref string[] enumNames)
        {
            TypeName propTypeName;
            var arrayTypeName = typeName as ArrayTypeName;
            if (arrayTypeName != null)
            {
                isArrayType = true;
                propTypeName = arrayTypeName.ElementType as TypeName;
            }
            else
            {
                isArrayType = false;
                propTypeName = typeName as TypeName;
            }

            if (propTypeName == null || propTypeName._typeDefinitionAst == null)
            {
                throw new NotSupportedException(string.Format(
                    CultureInfo.InvariantCulture,
                    ParserStrings.UnsupportedPropertyTypeOfDSCResourceClass,
                    memberName,
                    typeName.FullName,
                    typeName));
            }

            if (propTypeName._typeDefinitionAst.IsEnum)
            {
                enumNames = propTypeName._typeDefinitionAst.Members.Select(m => m.Name).ToArray();
                isArrayType = false;
                embeddedInstanceType = null;
                return "string";
            }

            if (!embeddedInstanceTypes.Contains(propTypeName._typeDefinitionAst))
            {
                embeddedInstanceTypes.Add(propTypeName._typeDefinitionAst);
            }

            // The type is obviously not a string, but in the mof, we represent
            // it as string (really, embeddedinstance of the class type)
            embeddedInstanceType = propTypeName.Name.Replace('.', '_');
            return "string";
        }
示例#40
0
文件: Compiler.cs 项目: nickchal/pash
 internal static Expression ConvertValue(ITypeName typeName, Expression expr)
 {
     Type reflectionType = typeName.GetReflectionType();
     if (reflectionType == null)
     {
         return Expression.Dynamic(PSDynamicConvertBinder.Get(), typeof(object), Expression.Call(CachedReflectionInfo.TypeOps_ResolveTypeName, Expression.Constant(typeName)), expr);
     }
     if (reflectionType.Equals(typeof(void)))
     {
         return Expression.Block(typeof(void), new Expression[] { expr });
     }
     return expr.Convert(reflectionType);
 }
示例#41
0
 internal static void CheckArrayTypeNameDepth(ITypeName typeName, IScriptExtent extent, Parser parser)
 {
     int count = 0;
     ITypeName type = typeName;
     while ((type is TypeName) == false)
     {
         count++;
         if (count > 200)
         {
             parser.ReportError(extent, () => ParserStrings.ScriptTooComplicated);
             break;
         }
         if (type is ArrayTypeName)
         {
             type = ((ArrayTypeName)type).ElementType;
         }
         else
         {
             break;
         }
     }
 }
示例#42
0
        private void CheckTypeName(Ast ast, ITypeName typename)
        {
            Type type = typename.GetReflectionType();

            // Only allow simple types of arrays of simple types as defined by System.Typecode
            // The permitted types are: Empty, Object, DBNull, Boolean, Char, SByte, Byte,
            // Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, Decimal, DateTime, String
            // We reject anything with a typecode or element typecode of object...
            // If we couldn't resolve the type, then it's definitely an error.
            if (type == null || ((type.IsArray ? type.GetElementType() : type).GetTypeCode() == TypeCode.Object))
            {
                ReportError(ast, () => ParserStrings.TypeNotAllowedInDataSection, typename.FullName);
            }
        }
 private IFieldDeclaration CreateFieldToHoldWrappedClass(IConstructLanguage language, ITypeName typeName, IClassDeclaration classDeclaration)
 {
     IFieldDeclaration fieldDeclaration = language.Field(language.Modifiers(Modifiers.Private | Modifiers.Readonly), typeName);
     NamingPolicy fieldsNamingPolicy = fieldDeclaration.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
     string fieldName = fieldsNamingPolicy.ChangeNameAccordingToPolicy(classDeclaration.Identifier.Name, classDeclaration.SolutionModel);
     fieldDeclaration.Identifier = language.Identifier(fieldName);
     return fieldDeclaration;
 }
示例#44
0
 public TypeConstraintAst(IScriptExtent extent, ITypeName typeName)
     : base(extent, typeName)
 {
 }
示例#45
0
        /// <summary>
        /// This constructor creates a type from a ITypeName.
        /// </summary>
        public PSTypeName(ITypeName typeName)
        {
            if (typeName == null)
            {
                throw PSTraceSource.NewArgumentNullException("typeName");
            }

            _type = typeName.GetReflectionType();
            if (_type != null)
            {
                Name = _type.FullName;
            }
            else
            {
                var t = typeName as TypeName;
                if (t != null && t._typeDefinitionAst != null)
                {
                    TypeDefinitionAst = t._typeDefinitionAst;
                    Name = TypeDefinitionAst.Name;
                }
                else
                {
                    _type = null;
                    Name = typeName.FullName;
                }
            }
        }
示例#46
0
        private ITypeName CompleteArrayTypeName(ITypeName elementType, TypeName typeForAssemblyQualification, Token firstTokenAfterLBracket)
        {
            while (true)
            {
                Token token;
                switch (firstTokenAfterLBracket.Kind)
                {
                    case TokenKind.Comma:
                        int dim = 1;
                        token = firstTokenAfterLBracket;
                        Token lastComma;
                        do
                        {
                            lastComma = token;
                            dim += 1;
                            token = NextToken();
                        } while (token.Kind == TokenKind.Comma);

                        if (token.Kind != TokenKind.RBracket)
                        {
                            // ErrorRecovery: just pretend we saw a ']'.

                            UngetToken(token);
                            ReportError(After(lastComma), () => ParserStrings.EndSquareBracketExpectedAtEndOfAttribute);
                        }

                        elementType = new ArrayTypeName(ExtentOf(elementType.Extent, token.Extent), elementType, dim);
                        break;

                    case TokenKind.RBracket:
                        elementType = new ArrayTypeName(ExtentOf(elementType.Extent, firstTokenAfterLBracket.Extent), elementType, 1);
                        break;

                    case TokenKind.EndOfInput:
                        UngetToken(firstTokenAfterLBracket);
                        ReportError(Before(firstTokenAfterLBracket), () => ParserStrings.EndSquareBracketExpectedAtEndOfAttribute);
                        break;

                    default:
                        // ErrorRecovery: sync to ']', and return null to avoid cascading errors.

                        ReportError(firstTokenAfterLBracket.Extent, () => ParserStrings.UnexpectedToken, firstTokenAfterLBracket.Text);
                        SyncOnError(true, TokenKind.RBracket);
                        break;
                }

                token = PeekToken();
                if (token.Kind == TokenKind.Comma)
                {
                    SkipToken();
                    var assemblyName = _tokenizer.GetAssemblyNameSpec();
                    if (string.IsNullOrEmpty(assemblyName))
                    {
                        ReportError(After(token), () => ParserStrings.MissingAssemblyNameSpecification);
                    }
                    else
                    {
                        typeForAssemblyQualification.AssemblyName = assemblyName;
                    }
                    break;
                }

                if (token.Kind != TokenKind.LBracket)
                {
                    break;
                }

                // Jagged array, skip the '[' and keep parsing.
                SkipToken();
                firstTokenAfterLBracket = NextToken();
            }

            return elementType;
        }
示例#47
0
 private bool DispatchTypeName(ITypeName type, int genericArgumentCount, bool isAttribute)
 {
     RuntimeHelpers.EnsureSufficientExecutionStack();
     var typeName = type as TypeName;
     if (typeName != null)
     {
         return VisitTypeName(typeName, genericArgumentCount, isAttribute);
     }
     else
     {
         var arrayTypeName = type as ArrayTypeName;
         if (arrayTypeName != null)
         {
             return VisitArrayTypeName(arrayTypeName);
         }
         else
         {
             var genericTypeName = type as GenericTypeName;
             if (genericTypeName != null)
             {
                 return VisitGenericTypeName(genericTypeName);
             }
         }
     }
     return false;
 }
示例#48
0
 protected AttributeBaseAst(IScriptExtent extent, ITypeName typeName)
     : base(extent)
 {
     this.TypeName = typeName;
 }
示例#49
0
 public TypeExpressionAst(IScriptExtent extent, ITypeName typeName)
     : base(extent)
 {
     this.TypeName = typeName;
 }
示例#50
0
        internal Expression CompileTypeName(ITypeName typeName, IScriptExtent errorPos)
        {
            Type type;
            try
            {
                // If creating the type throws an exception, just defer that error until runtime.
                type = typeName.GetReflectionType();
            }
            catch (Exception e)
            {
                CommandProcessorBase.CheckForSevereException(e);
                type = null;
            }

            if (type != null)
            {
                return Expression.Constant(type, typeof(Type));
            }

            return Expression.Call(CachedReflectionInfo.TypeOps_ResolveTypeName,
                                   Expression.Constant(typeName),
                                   Expression.Constant(errorPos));
        }
        private IConstructorDeclaration CreateConstructor(IClassDeclaration classDeclaration, IIdentifier fieldIdentifier, ITypeName typeName)
        {
            IConstructLanguage language = classDeclaration.Language;

            IParameter parameter = language.Parameter(typeName);
            NamingPolicy parameterNamingPolicy = parameter.PrimaryNamingPolicy(classDeclaration.FileModel.UserSettings);
            string parameterName = parameterNamingPolicy.ChangeNameAccordingToPolicy(classDeclaration.Identifier.Name, classDeclaration.SolutionModel);
            parameter.Identifier = language.Identifier(parameterName);
            Modifiers constructorModifiers = Modifiers.Public;
            Modifiers visibility = classDeclaration.Modifiers.Modifiers.GetVisibility();
            if (visibility == Modifiers.None || visibility.IsInternal())
            {
                constructorModifiers = Modifiers.Internal;
            }

            IConstructorDeclaration constructor = language.Constructor(language.None<IDocComment>(),
                language.None<IAttributes>(),
                language.Modifiers(constructorModifiers),
                language.Parameters(parameter),
                language.None<IConstructorInitializer>(),
                language.Block(
                    language.AssignmentStatement(
                        language.MemberAccess(language.This(), fieldIdentifier),
                        language.VariableAccess(parameter.Identifier))));

            return constructor;
        }
示例#52
0
文件: Compiler.cs 项目: nickchal/pash
 internal Expression CompileTypeName(ITypeName typeName)
 {
     Type reflectionType;
     try
     {
         reflectionType = typeName.GetReflectionType();
     }
     catch (Exception exception)
     {
         CommandProcessorBase.CheckForSevereException(exception);
         reflectionType = null;
     }
     if (reflectionType != null)
     {
         return Expression.Constant(reflectionType);
     }
     return Expression.Call(CachedReflectionInfo.TypeOps_ResolveTypeName, Expression.Constant(typeName));
 }
示例#53
0
 internal static TypeName FindTypeNameToComplete(ITypeName type, IScriptPosition cursor)
 {
     TypeName name = type as TypeName;
     if (name != null)
     {
         if ((cursor.Offset > type.Extent.StartOffset) && (cursor.Offset <= type.Extent.EndOffset))
         {
             return name;
         }
         return null;
     }
     GenericTypeName name2 = type as GenericTypeName;
     if (name2 != null)
     {
         name = FindTypeNameToComplete(name2.TypeName, cursor);
         if (name != null)
         {
             return name;
         }
         foreach (ITypeName name3 in name2.GenericArguments)
         {
             name = FindTypeNameToComplete(name3, cursor);
             if (name != null)
             {
                 return name;
             }
         }
         return null;
     }
     ArrayTypeName name4 = type as ArrayTypeName;
     if (name4 == null)
     {
         return null;
     }
     return (TypeName) (FindTypeNameToComplete(name4.ElementType, cursor) ?? null);
 }
示例#54
0
文件: Parser.cs 项目: nickchal/pash
 private ITypeName CompleteArrayTypeName(ITypeName elementType, TypeName typeForAssemblyQualification, Token firstTokenAfterLBracket)
 {
     Token token;
     Token token1;
     while (true)
     {
         TokenKind kind = firstTokenAfterLBracket.Kind;
         if (kind == TokenKind.EndOfInput)
         {
             this.UngetToken(firstTokenAfterLBracket);
             this.ReportError(Parser.Before(firstTokenAfterLBracket), ParserStrings.EndSquareBracketExpectedAtEndOfAttribute, new object[0]);
         }
         else
         {
             if (kind == TokenKind.RBracket)
             {
                 elementType = new ArrayTypeName(Parser.ExtentOf(elementType.Extent, firstTokenAfterLBracket.Extent), elementType, 1);
             }
             else
             {
                 if (kind != TokenKind.Comma)
                 {
                     object[] text = new object[1];
                     text[0] = firstTokenAfterLBracket.Text;
                     this.ReportError(firstTokenAfterLBracket.Extent, ParserStrings.UnexpectedToken, text);
                     TokenKind[] tokenKindArray = new TokenKind[1];
                     tokenKindArray[0] = TokenKind.RBracket;
                     this.SyncOnError(tokenKindArray);
                 }
                 else
                 {
                     int num = 1;
                     token = firstTokenAfterLBracket;
                     do
                     {
                         token1 = token;
                         num++;
                         token = this.NextToken();
                     }
                     while (token.Kind == TokenKind.Comma);
                     if (token.Kind != TokenKind.RBracket)
                     {
                         this.UngetToken(token);
                         this.ReportError(Parser.After(token1), ParserStrings.EndSquareBracketExpectedAtEndOfAttribute, new object[0]);
                     }
                     elementType = new ArrayTypeName(Parser.ExtentOf(elementType.Extent, token.Extent), elementType, num);
                 }
             }
         }
         token = this.PeekToken();
         if (token.Kind != TokenKind.Comma)
         {
             if (token.Kind != TokenKind.LBracket)
             {
                 break;
             }
             this.SkipToken();
             firstTokenAfterLBracket = this.NextToken();
         }
         else
         {
             this.SkipToken();
             string assemblyNameSpec = this._tokenizer.GetAssemblyNameSpec();
             if (!string.IsNullOrEmpty(assemblyNameSpec))
             {
                 typeForAssemblyQualification.AssemblyName = assemblyNameSpec;
                 break;
             }
             else
             {
                 this.ReportError(Parser.After(token), ParserStrings.MissingAssemblyNameSpecification, new object[0]);
                 break;
             }
         }
     }
     return elementType;
 }
示例#55
0
 private static Type LoadTypeWithPartialName(ITypeName typeNameInfo, Assembly initialAssembly, string fullTypeName)
 {
     Type type2;
     uint nameCount = typeNameInfo.GetNameCount();
     uint typeArgumentCount = typeNameInfo.GetTypeArgumentCount();
     IntPtr[] ptrArray = new IntPtr[nameCount];
     IntPtr[] ptrArray2 = new IntPtr[typeArgumentCount];
     try
     {
         Type nestedType = null;
         if (nameCount == 0)
         {
             throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { fullTypeName }));
         }
         GCHandle handle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);
         nameCount = typeNameInfo.GetNames(nameCount, handle.AddrOfPinnedObject());
         handle.Free();
         string name = Marshal.PtrToStringBSTR(ptrArray[0]);
         string assemblyName = typeNameInfo.GetAssemblyName();
         if (!string.IsNullOrEmpty(assemblyName))
         {
             Assembly assembly = Assembly.LoadWithPartialName(assemblyName);
             if (assembly == null)
             {
                 assembly = Assembly.LoadWithPartialName(new AssemblyName(assemblyName).Name);
             }
             nestedType = assembly.GetType(name);
         }
         else if (initialAssembly != null)
         {
             nestedType = initialAssembly.GetType(name);
         }
         else
         {
             nestedType = Type.GetType(name);
         }
         if (nestedType == null)
         {
             throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { fullTypeName }));
         }
         for (int i = 1; i < nameCount; i++)
         {
             string str3 = Marshal.PtrToStringBSTR(ptrArray[i]);
             nestedType = nestedType.GetNestedType(str3, BindingFlags.NonPublic | BindingFlags.Public);
             if (nestedType == null)
             {
                 throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { fullTypeName }));
             }
         }
         if (typeArgumentCount != 0)
         {
             GCHandle handle2 = GCHandle.Alloc(ptrArray2, GCHandleType.Pinned);
             typeArgumentCount = typeNameInfo.GetTypeArguments(typeArgumentCount, handle2.AddrOfPinnedObject());
             handle2.Free();
             Type[] typeArguments = new Type[typeArgumentCount];
             for (int j = 0; j < typeArgumentCount; j++)
             {
                 typeArguments[j] = LoadTypeWithPartialName((ITypeName) Marshal.GetObjectForIUnknown(ptrArray2[j]), null, fullTypeName);
             }
             return nestedType.MakeGenericType(typeArguments);
         }
         type2 = nestedType;
     }
     finally
     {
         for (int k = 0; k < ptrArray.Length; k++)
         {
             IntPtr ptr1 = ptrArray[k];
             Marshal.FreeBSTR(ptrArray[k]);
         }
         for (int m = 0; m < ptrArray2.Length; m++)
         {
             IntPtr ptr2 = ptrArray2[m];
             Marshal.Release(ptrArray2[m]);
         }
     }
     return type2;
 }
示例#56
0
 public AttributeAst(IScriptExtent extent, ITypeName typeName, IEnumerable<ExpressionAst> positionalArguments, IEnumerable<NamedAttributeArgumentAst> namedArguments)
     : base(extent, typeName)
 {
     this.PositionalArguments = positionalArguments.ToReadOnlyCollection();
     this.NamedArguments = namedArguments.ToReadOnlyCollection();
 }
示例#57
0
        internal static TypeName FindTypeNameToComplete(ITypeName type, IScriptPosition cursor)
        {
            var typeName = type as TypeName;
            if (typeName != null)
            {
                // If the cursor is at the start offset, it's not really inside, so return null.
                // If the cursor is at the end offset, it's not really inside, but it's just before the cursor,
                // we don want to complete it.
                return (cursor.Offset > type.Extent.StartOffset && cursor.Offset <= type.Extent.EndOffset)
                           ? typeName
                           : null;
            }

            var genericTypeName = type as GenericTypeName;
            if (genericTypeName != null)
            {
                typeName = FindTypeNameToComplete(genericTypeName.TypeName, cursor);
                if (typeName != null)
                    return typeName;
                foreach (var t in genericTypeName.GenericArguments)
                {
                    typeName = FindTypeNameToComplete(t, cursor);
                    if (typeName != null)
                        return typeName;
                }
                return null;
            }

            var arrayTypeName = type as ArrayTypeName;
            if (arrayTypeName != null)
            {
                return FindTypeNameToComplete(arrayTypeName.ElementType, cursor) ?? null;
            }

            return null;
        }