/// <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 }
/// <summary> /// Clones this instance using the specified ancestor. /// </summary> /// <param name="ancestor">The ancestor.</param> public virtual IFeatureInstance Clone(IClassType ancestor) { IPrecursorInstance NewPrecursor = new PrecursorInstance(ancestor, this); Debug.Assert(NewPrecursor.Ancestor == ancestor); IFeatureInstance ClonedObject = new FeatureInstance(Owner, Feature); foreach (IPrecursorInstance PrecursorInstance in PrecursorList) { ClonedObject.PrecursorList.Add(PrecursorInstance); } ClonedObject.PrecursorList.Add(NewPrecursor); ClonedObject.SetIsForgotten(IsForgotten); ClonedObject.SetIsKept(IsKept); ClonedObject.SetIsDiscontinued(IsDiscontinued); ClonedObject.SetInheritBySideAttribute(InheritBySideAttribute); if (OriginalPrecursor.IsAssigned) { ClonedObject.OriginalPrecursor.Item = OriginalPrecursor.Item; } return(ClonedObject); }
/// <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 }
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); }
/// <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(IAssignmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; // This list has been verified during the node tree check. Debug.Assert(node.DestinationList.Count > 0); IExpression SourceExpression = (IExpression)node.Source; IResultType SourceResult = SourceExpression.ResolvedResult.Item; if (node.DestinationList.Count > SourceResult.Count) { AddSourceError(new ErrorAssignmentMismatch(node)); Success = false; } else { IClass EmbeddingClass = node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ISealableDictionary <IQualifiedName, ICompiledFeature> FinalFeatureTable = new SealableDictionary <IQualifiedName, ICompiledFeature>(); for (int i = 0; i < node.DestinationList.Count; i++) { IQualifiedName Destination = (QualifiedName)node.DestinationList[i]; IList <IIdentifier> ValidPath = Destination.ValidPath.Item; ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node); if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute)) { Success = false; }
private static IList <ICompiledType> GetTypesConvertibleTo(IClassType type) { ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = type.FeatureTable; ISealableDictionary <IFeatureName, IFunctionFeature> ConversionToTable = type.BaseClass.ConversionToTable; IList <ICompiledType> Result = new List <ICompiledType>(); foreach (KeyValuePair <IFeatureName, IFunctionFeature> Entry in ConversionToTable) { IFunctionFeature Feature = Entry.Value; foreach (IQueryOverload Overload in Feature.OverloadList) { ISealableList <IParameter> ParameterTable = Overload.ParameterTable; Debug.Assert(ParameterTable.IsSealed); Debug.Assert(ParameterTable.Count == 0); ISealableList <IParameter> ResultTable = Overload.ResultTable; Debug.Assert(ResultTable.IsSealed); Debug.Assert(ResultTable.Count == 1); IParameter OverloadResult = ResultTable[0]; Debug.Assert(OverloadResult.ResolvedParameter.ResolvedEffectiveType.IsAssigned); ICompiledType OverloadResultType = OverloadResult.ResolvedParameter.ResolvedEffectiveType.Item; Result.Add(OverloadResultType); } } return(Result); }
/// <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); } } }
protected static void GetInheritedTypes(IReferenceType type, HashSet <IReferenceType> inheritedTypes) { Contract.Requires <ArgumentNullException>(type != null, "type"); Contract.Requires <ArgumentNullException>(inheritedTypes != null, "inheritedTypes"); List <IReferenceType> immediateBases = new List <IReferenceType>(); IClassType classtype = type as IClassType; if (classtype != null) { IClassType basetype = classtype.GetSuperclass(); if (basetype != null) { immediateBases.Add(basetype); } immediateBases.AddRange(classtype.GetInterfaces(false)); } IInterfaceType interfacetype = type as IInterfaceType; if (interfacetype != null) { immediateBases.AddRange(interfacetype.GetSuperInterfaces()); } foreach (var baseType in immediateBases) { if (inheritedTypes.Add(baseType)) { GetInheritedTypes(baseType, inheritedTypes); } } }
/// <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); }
public static IEnumerable <IMember> GetAvailableMembersFor(this IClassType targetClass, Predicate <IMember> predicate) { IClassType current = targetClass; var currentYield = new Dictionary <IMemberUniqueIdentifier, IMember>(); CheckAgain: foreach (var memberEntry in current.Members.Values) { var member = memberEntry.Entry; if (predicate(member)) { if (!currentYield.ContainsKey(member.UniqueIdentifier)) { currentYield.Add(member.UniqueIdentifier, member); yield return(member); } } } if (current.BaseType == null) { yield break; } else { current = current.BaseType; goto CheckAgain; } }
public int GetThreadPriorityId(out int priorityId) { #if HIDE_THREADS priorityId = 0; return(VSConstants.S_OK); #endif if (_getPriorityMethod == null) { IClassType type = (IClassType)_thread.GetReferenceType(); _getPriorityMethod = type.GetConcreteMethod("getPriority", "()I"); } priorityId = 0; if (_getPriorityMethod == null) { return(VSConstants.E_FAIL); } try { using (var result = _thread.InvokeMethod(null, _getPriorityMethod, InvokeOptions.SingleThreaded)) { priorityId = ((IIntegerValue)result.Value).GetValue(); return(VSConstants.S_OK); } } catch (DebuggerException) { priorityId = 0; return(VSConstants.E_FAIL); } }
/// <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 <IFeatureName, IDiscrete> MergedDiscreteTable = (ISealableDictionary <IFeatureName, IDiscrete>)data; Debug.Assert(node.ResolvedClassType.IsAssigned); IClassType ThisClassType = node.ResolvedClassType.Item; ThisClassType.DiscreteTable.Merge(MergedDiscreteTable); ThisClassType.DiscreteTable.Seal(); node.DiscreteTable.Merge(MergedDiscreteTable); node.DiscreteTable.Seal(); Debug.Assert(node.DiscreteWithValueTable.Count == 0); foreach (KeyValuePair <IFeatureName, IDiscrete> Entry in node.DiscreteTable) { if (Entry.Value.NumericValue.IsAssigned) { IExpression NumericValue = (IExpression)Entry.Value.NumericValue.Item; node.DiscreteWithValueTable.Add(Entry.Key, NumericValue); } } node.DiscreteWithValueTable.Seal(); foreach (IClassType Item in node.GenericInstanceList) { Item.DiscreteTable.Merge(MergedDiscreteTable); Item.DiscreteTable.Seal(); } }
public override void Validate(Environment env) { var classMembers = Type.Members; if (Handle != null) { var wrapper = new GenericClassWrapper(Type, Handle.Names.ToList()); Type = wrapper; } Type.Name = ClassName; env.Scopes.Types.Bind(ClassName, Type); using var _ = env.Scopes.Use(); if (Handle != null) { Handle.Bind(env); } env.Scopes.Values.Bind("this", new VariableBinding() { Type = Type, }); foreach (var member in Members) { member.Validate(env); classMembers.Add(member.Name, member.Binding.Type); env.Scopes.Values.Bind(member.Name, member.Binding); } }
/// <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(); }
/// <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; }
/// <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(IInitializedObjectExpression node, object data) { IResultType ResolvedResult = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item1; IResultException ResolvedException = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item2; ISealableList <IExpression> ConstantSourceList = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item3; ILanguageConstant ExpressionConstant = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item4; ITypeName InitializedObjectTypeName = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item5; IClassType InitializedObjectType = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item6; ISealableDictionary <string, ICompiledFeature> AssignedFeatureTable = ((Tuple <IResultType, IResultException, ISealableList <IExpression>, ILanguageConstant, ITypeName, IClassType, ISealableDictionary <string, ICompiledFeature> >)data).Item7; node.ResolvedResult.Item = ResolvedResult; node.ConstantSourceList.AddRange(ConstantSourceList); node.ConstantSourceList.Seal(); node.ResolvedClassTypeName.Item = InitializedObjectTypeName; node.ResolvedClassType.Item = InitializedObjectType; Debug.Assert(node.AssignedFeatureTable.Count == 0); node.AssignedFeatureTable.Merge(AssignedFeatureTable); node.AssignedFeatureTable.Seal(); IClass BaseClass = InitializedObjectType.BaseClass; BaseClass.InitializedObjectList.Add(node); }
public int SetThreadName(string pszName) { #if HIDE_THREADS return(VSConstants.S_OK); #endif if (_setThreadNameMethod == null) { IClassType type = (IClassType)_thread.GetReferenceType(); _setThreadNameMethod = type.GetConcreteMethod("setName", "(Ljava/lang/String;)V"); } if (_setThreadNameMethod == null) { return(VSConstants.E_FAIL); } using (var stringValue = _program.VirtualMachine.GetMirrorOf(pszName)) { using (_thread.InvokeMethod(null, _setThreadNameMethod, InvokeOptions.None, stringValue.Value)) { return(VSConstants.S_OK); } } }
public int GetThreadId(out uint pdwThreadId) { #if HIDE_THREADS pdwThreadId = 0; return(VSConstants.S_OK); #endif if (_getIdMethod == null) { IClassType type = (IClassType)_thread.GetReferenceType(); _getIdMethod = type.GetConcreteMethod("getId", "()J"); } pdwThreadId = 0; if (_getIdMethod == null) { return(VSConstants.E_FAIL); } try { using (var result = _thread.InvokeMethod(null, _getIdMethod, InvokeOptions.SingleThreaded)) { pdwThreadId = (uint)((ILongValue)result.Value).GetValue(); return(VSConstants.S_OK); } } catch (DebuggerException) { pdwThreadId = 0; return(VSConstants.E_FAIL); } }
public bool HandlesName(IDeclaration declaredMember) { if (declaredMember is IFieldMember) { if (declaredMember.ParentTarget is IClassType) { IClassType parentC = declaredMember.ParentTarget as IClassType; if (parentC.Name == "CliMetadataTableStreamAndHeader") { return(false); } } return(true); } else if (declaredMember is IMethodParameterMember) { return(true); } else if (declaredMember is IConstructorParameterMember) { return(true); } else if (declaredMember is IStatementBlockLocalMember) { return(true); } return(false); }
/// <summary> /// Compares two types. /// </summary> /// <param name="type1">The first type.</param> /// <param name="type2">The second type.</param> public static bool TypesHaveIdenticalSignature(IClassType type1, IClassType type2) { bool IsIdentical = true; IsIdentical &= type1.BaseClass == type2.BaseClass; IsIdentical &= type1.TypeArgumentTable.Count == type2.TypeArgumentTable.Count; IList <ICompiledType> TypeArgumentList1 = new List <ICompiledType>(); IList <ICompiledType> TypeArgumentList2 = new List <ICompiledType>(); foreach (KeyValuePair <string, ICompiledType> Entry in type1.TypeArgumentTable) { ICompiledType TypeArgument = Entry.Value; TypeArgumentList1.Add(TypeArgument); } foreach (KeyValuePair <string, ICompiledType> Entry in type2.TypeArgumentTable) { ICompiledType TypeArgument = Entry.Value; TypeArgumentList2.Add(TypeArgument); } for (int i = 0; i < TypeArgumentList1.Count && i < TypeArgumentList2.Count; i++) { IsIdentical &= ObjectType.TypesHaveIdenticalSignature(TypeArgumentList1[i], TypeArgumentList2[i]); } return(IsIdentical); }
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); }
private EvaluatedExpression FindClass(string signature) { Contract.Requires <ArgumentNullException>(signature != null, "signature"); Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(signature)); Contract.Ensures(Contract.Result <EvaluatedExpression>() != null); switch (signature[0]) { case 'Z': return(GetField(GetReflectedType(FindClass("Ljava/lang/Boolean;")), "TYPE")); case 'B': return(GetField(GetReflectedType(FindClass("Ljava/lang/Byte;")), "TYPE")); case 'C': return(GetField(GetReflectedType(FindClass("Ljava/lang/Character;")), "TYPE")); case 'D': return(GetField(GetReflectedType(FindClass("Ljava/lang/Double;")), "TYPE")); case 'F': return(GetField(GetReflectedType(FindClass("Ljava/lang/Float;")), "TYPE")); case 'I': return(GetField(GetReflectedType(FindClass("Ljava/lang/Integer;")), "TYPE")); case 'J': return(GetField(GetReflectedType(FindClass("Ljava/lang/Long;")), "TYPE")); case 'S': return(GetField(GetReflectedType(FindClass("Ljava/lang/Short;")), "TYPE")); case 'V': return(GetField(GetReflectedType(FindClass("Ljava/lang/Void;")), "TYPE")); case '[': case 'L': if (_classForNameMethod == null) { _javaLangClassClass = (IClassType)_stackFrame.GetVirtualMachine().GetClassesByName("java.lang.Class").Single(); _classForNameMethod = _javaLangClassClass.GetConcreteMethod("forName", "(Ljava/lang/String;)Ljava/lang/Class;"); } if (signature[0] != '[') { signature = SignatureHelper.DecodeTypeName(signature); } using (var signatureValue = _stackFrame.GetVirtualMachine().GetMirrorOf(signature)) { var result = _javaLangClassClass.InvokeMethod(null, _classForNameMethod, InvokeOptions.None, signatureValue.Value); return(new EvaluatedExpression(signature, signature, result.Value, true)); } default: throw new ArgumentException(); } }
private bool GetBaseClass(ICSharpClass cSharpClass, IClassSplitting splitting, IDictionary <IClass, ICSharpClass> classTable, out ICSharpClass result) { result = null; IClass BaseClass = null; // If the class inherits from a class that must be a parent, select it as base class. foreach (IInheritance InheritanceItem in cSharpClass.Source.InheritanceList) { IClassType ClassParentType = InheritanceItem.ResolvedClassParentType.Item; IClass ParentClass = ClassParentType.BaseClass; Debug.Assert(ParentClass != null); if (splitting.MustInherit.Contains(ParentClass)) { Debug.Assert(BaseClass == null); BaseClass = ParentClass; } } // No such class. Try classes that don't have to be interface. if (BaseClass == null) { IList <IClass> ParentCandidates = new List <IClass>(); foreach (IInheritance InheritanceItem in cSharpClass.Source.InheritanceList) { IClassType ClassParentType = InheritanceItem.ResolvedClassParentType.Item; IClass ParentClass = ClassParentType.BaseClass; if (splitting.OtherParents.Contains(ParentClass)) { ParentCandidates.Add(ParentClass); } } if (ParentCandidates.Count > 0) { BaseClass = ParentCandidates[0]; } } if (BaseClass != null) { foreach (KeyValuePair <IClass, ICSharpClass> Entry in classTable) { ICSharpClass Item = Entry.Value; if (Item.Source == BaseClass) { Debug.Assert(result == null); result = Item; } } } return(result != null); }
private static bool TryGetCollectionValues(IObjectReference objectReference, out ReadOnlyCollection <IValue> values, out IType elementType) { IArrayReference arrayReference = objectReference as IArrayReference; if (arrayReference == null) { int size; if (TryGetCollectionSize(objectReference, out size)) { IClassType classType = objectReference.GetReferenceType() as IClassType; if (classType != null) { IObjectReference collectionObject = null; ReadOnlyCollection <IInterfaceType> interfaces = classType.GetInterfaces(true); if (interfaces.Any(i => i.GetName() == "java.util.Collection")) { collectionObject = objectReference; } else if (interfaces.Any(i => i.GetName() == "java.util.Map")) { IMethod entrySetMethod = classType.GetConcreteMethod("entrySet", "()Ljava/util/Set;"); IStrongValueHandle <IValue> result = objectReference.InvokeMethod(null, entrySetMethod, InvokeOptions.None); if (result != null) { collectionObject = result.Value as IObjectReference; } } if (collectionObject != null) { IClassType collectionObjectType = collectionObject.GetReferenceType() as IClassType; if (collectionObjectType != null) { IMethod toArrayMethod = collectionObjectType.GetConcreteMethod("toArray", "()[Ljava/lang/Object;"); IStrongValueHandle <IValue> result = collectionObject.InvokeMethod(null, toArrayMethod, InvokeOptions.None); if (result != null) { arrayReference = result.Value as IArrayReference; } } } } } } if (arrayReference != null) { values = arrayReference.GetValues(); IArrayType arrayType = (IArrayType)arrayReference.GetReferenceType(); elementType = arrayType.GetComponentType(); return(true); } values = null; elementType = null; return(false); }
private void Remove(IClassType classType) { if (Contains(classType) == true) { ItemsByIdentity.Remove(classType); ItemsByName.Remove(classType.Name); ItemsById.Remove(classType.Id); } }
public override void VisitClassType <TAttributeGroup, TGenericParameter, TClassReference, TInterfaceReference, TEventCollection, TPropertyCollection, TIndexerCollection, TMethodCollection, TFieldCollection, TConstructor, TOperatorOverload, TConversionOperator, TNestedClassCollection, TNestedDelegate, TNestedEnum, TNestedInterface, TNestedStructCollection, TStaticConstructor, TDestructor>( IClassType <TAttributeGroup, TGenericParameter, TClassReference, TInterfaceReference, TEventCollection, TPropertyCollection, TIndexerCollection, TMethodCollection, TFieldCollection, TConstructor, TOperatorOverload, TConversionOperator, TNestedClassCollection, TNestedDelegate, TNestedEnum, TNestedInterface, TNestedStructCollection, TStaticConstructor, TDestructor> @class) { classTypeDefinitions.Add(@class); if (includeNestedClasses) { base.VisitClassType(@class); } }
/// <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(IClass node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; Debug.Assert(node.LocalTypedefTable.IsSealed); ISealableDictionary <IFeatureName, ITypedefType> MergedTypedefTable = node.LocalTypedefTable.CloneUnsealed(); foreach (IInheritance InheritanceItem in node.InheritanceList) { IClassType InheritanceParent = InheritanceItem.ResolvedType.Item; ISealableDictionary <IFeatureName, ITypedefType> InheritedTypedefTable = InheritanceParent.TypedefTable; foreach (KeyValuePair <IFeatureName, ITypedefType> InstanceEntry in InheritedTypedefTable) { IFeatureName InstanceName = InstanceEntry.Key; ITypedefType InstanceItem = InstanceEntry.Value; bool ConflictingEntry = false; foreach (KeyValuePair <IFeatureName, ITypedefType> Entry in MergedTypedefTable) { IFeatureName LocalName = Entry.Key; ITypedefType LocalItem = Entry.Value; if (InstanceName.Name == LocalName.Name) { if (InstanceItem != LocalItem) { AddSourceError(new ErrorDuplicateName(InheritanceItem, LocalName.Name)); ConflictingEntry = true; Success = false; } } else if (InstanceItem == LocalItem) { AddSourceError(new ErrorTypedefNameConflict(InheritanceItem, LocalName.Name, InstanceName.Name)); ConflictingEntry = true; Success = false; } } if (!ConflictingEntry && !MergedTypedefTable.ContainsKey(InstanceName)) { MergedTypedefTable.Add(InstanceName, InstanceItem); } } } if (Success) { data = MergedTypedefTable; } return(Success); }
/// <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(IInheritance node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IClassType ParentTypeWithRename = null; IClassType ResolvedParent = node.ResolvedClassParentType.Item; 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 = ResolvedParent.ExportTable.CloneUnsealed(); ISealableDictionary <IFeatureName, ITypedefType> RenamedTypedefTable = ResolvedParent.TypedefTable.CloneUnsealed(); ISealableDictionary <IFeatureName, IDiscrete> RenamedDiscreteTable = ResolvedParent.DiscreteTable.CloneUnsealed(); ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in ResolvedParent.FeatureTable) { IFeatureName AncestorFeatureName = Entry.Key; IFeatureInstance AncestorFeatureInstance = Entry.Value; RenamedFeatureTable.Add(AncestorFeatureName, AncestorFeatureInstance.Clone(ResolvedParent)); } foreach (IRename RenameItem in node.RenameList) { Success &= RenameItem.CheckGenericRename(new IDictionaryIndex <IFeatureName>[] { RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name), ErrorList); } if (Success) { Success &= ResolveInstancingAfterRename(node, RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable); if (Success) { IClass EmbeddingClass = node.EmbeddingClass; ParentTypeWithRename = ClassType.Create(ResolvedParent.BaseClass, ResolvedParent.TypeArgumentTable, EmbeddingClass.ResolvedClassType.Item); ParentTypeWithRename.ExportTable.Merge(RenamedExportTable); ParentTypeWithRename.ExportTable.Seal(); ParentTypeWithRename.TypedefTable.Merge(RenamedTypedefTable); ParentTypeWithRename.TypedefTable.Seal(); ParentTypeWithRename.DiscreteTable.Merge(RenamedDiscreteTable); ParentTypeWithRename.DiscreteTable.Seal(); ParentTypeWithRename.FeatureTable.Merge(RenamedFeatureTable); ParentTypeWithRename.FeatureTable.Seal(); } } if (Success) { data = ParentTypeWithRename; } return(Success); }
public MyPlayer(string name, int healthPoints, int magicPoints, int physicalAttack, int magicAttack, int speed, IClassType thisClass) { _name = name; _healthPoints = healthPoints; _magicPoints = magicPoints; _physicalAttack = physicalAttack; _magicAttack = magicAttack; _speed = speed; classType = thisClass; }
private void generatedCodeAttribute_Disposed(object sender, EventArgs e) { if (this.generatedCodeAttribute != null) { #if DEBUG Debug.WriteLine("GeneratedCodeAttribute Disposed."); #endif this.generatedCodeAttribute.Disposed -= generatedCodeAttribute_Disposed; this.generatedCodeAttribute = null; } }