private void CreateGenericTypeMembers(TypeSymbol templateType, TypeSymbol instanceType, IList <TypeSymbol> typeArguments) { foreach (MemberSymbol memberSymbol in templateType.Members) { if (memberSymbol.AssociatedType.Type == SymbolType.GenericParameter && ((GenericParameterSymbol)memberSymbol.AssociatedType).IsTypeParameter) { MemberSymbol instanceMemberSymbol = CreateGenericMember(memberSymbol, typeArguments); instanceType.AddMember(instanceMemberSymbol); } else if (memberSymbol.AssociatedType.IsGeneric && memberSymbol.AssociatedType.GenericArguments == null && memberSymbol.AssociatedType.GenericParameters.Count == typeArguments.Count) { TypeSymbol genericType = CreateGenericTypeSymbol(memberSymbol.AssociatedType, typeArguments); if (genericType == null) { genericType = instanceType; } List <TypeSymbol> memberTypeArgs = new List <TypeSymbol> { genericType }; MemberSymbol instanceMemberSymbol = CreateGenericMember(memberSymbol, memberTypeArgs); instanceType.AddMember(instanceMemberSymbol); } else { instanceType.AddMember(memberSymbol); } } IndexerSymbol indexer = null; if (templateType.Type == SymbolType.Class) { indexer = ((ClassSymbol)templateType).Indexer; } else if (templateType.Type == SymbolType.Interface) { indexer = ((InterfaceSymbol)templateType).Indexer; } if (indexer != null) { if (indexer.AssociatedType.Type == SymbolType.GenericParameter) { MemberSymbol instanceIndexer = CreateGenericMember(indexer, typeArguments); instanceType.AddMember(instanceIndexer); } else if (indexer.AssociatedType.IsGeneric && indexer.AssociatedType.GenericArguments == null && indexer.AssociatedType.GenericParameters.Count == typeArguments.Count) { TypeSymbol genericType = CreateGenericTypeSymbol(indexer.AssociatedType, typeArguments); if (genericType == null) { genericType = instanceType; } List <TypeSymbol> memberTypeArgs = new List <TypeSymbol> { genericType }; MemberSymbol instanceMemberSymbol = CreateGenericMember(indexer, memberTypeArgs); instanceType.AddMember(instanceMemberSymbol); } else { instanceType.AddMember(indexer); } } }
private MemberSymbol CreateGenericMember(MemberSymbol templateMember, IList <TypeSymbol> typeArguments) { TypeSymbol parentType = (TypeSymbol)templateMember.Parent; TypeSymbol instanceAssociatedType; if (templateMember.AssociatedType.Type == SymbolType.GenericParameter) { GenericParameterSymbol genericParameter = (GenericParameterSymbol)templateMember.AssociatedType; instanceAssociatedType = typeArguments[genericParameter.Index]; } else { instanceAssociatedType = typeArguments[0]; } if (templateMember.Type == SymbolType.Indexer) { IndexerSymbol templateIndexer = (IndexerSymbol)templateMember; IndexerSymbol instanceIndexer = new IndexerSymbol(parentType, instanceAssociatedType); if (templateIndexer.UseScriptIndexer) { instanceIndexer.SetScriptIndexer(); } instanceIndexer.SetVisibility(templateIndexer.Visibility); return(instanceIndexer); } if (templateMember.Type == SymbolType.Property) { PropertySymbol templateProperty = (PropertySymbol)templateMember; PropertySymbol instanceProperty = new PropertySymbol(templateProperty.Name, parentType, instanceAssociatedType); if (templateProperty.IsTransformed) { instanceProperty.SetTransformedName(templateProperty.GeneratedName); } instanceProperty.SetNameCasing(templateProperty.IsCasePreserved); instanceProperty.SetVisibility(templateProperty.Visibility); return(instanceProperty); } if (templateMember.Type == SymbolType.Field) { FieldSymbol templateField = (FieldSymbol)templateMember; FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType); if (templateField.IsTransformed) { instanceField.SetTransformName(templateField.GeneratedName); } instanceField.SetNameCasing(templateField.IsCasePreserved); instanceField.SetVisibility(templateField.Visibility); return(instanceField); } if (templateMember.Type == SymbolType.Method) { MethodSymbol templateMethod = (MethodSymbol)templateMember; MethodSymbol instanceMethod = new MethodSymbol(templateMethod.Name, parentType, instanceAssociatedType); if (templateMethod.IsAliased) { instanceMethod.SetTransformedName(templateMethod.TransformName); } else if (templateMethod.IsTransformed) { instanceMethod.SetTransformedName(templateMethod.GeneratedName); } if (templateMethod.SkipGeneration) { instanceMethod.SetSkipGeneration(); } if (templateMethod.InterfaceMember != null) { instanceMethod.SetInterfaceMember(templateMethod.InterfaceMember); } instanceMethod.SetNameCasing(templateMethod.IsCasePreserved); instanceMethod.SetVisibility(templateMethod.Visibility); return(instanceMethod); } Debug.Fail("Unexpected generic member '" + templateMember.Name + " on type '" + ((TypeSymbol)templateMember.Parent).FullName + "'."); return(null); }
public virtual void AddMember(MemberSymbol memberSymbol) { AddMember(memberSymbol, false); }
private string TransformMember(MemberSymbol memberSymbol) { if (memberSymbol.InterfaceMember != null || memberSymbol.Name.Length < 3 || memberSymbol.IsTransformAllowed == false) { // Interface members do get obfuscated // Also members with already short names do not get // obfuscated, as doing so might infact increase the name size return(null); } TypeSymbol type = (TypeSymbol)memberSymbol.Parent; if (memberSymbol.IsPublic == false) { if (memberSymbol is CodeMemberSymbol && ((CodeMemberSymbol)memberSymbol).IsOverride) { ClassSymbol baseType = ((ClassSymbol)type).BaseClass; if (baseType == null) { baseType = (ClassSymbol)((ISymbolTable)memberSymbol.SymbolSet.SystemNamespace).FindSymbol("Object", null, SymbolFilter.Types); Debug.Assert(baseType != null); } MemberSymbol baseMember = (MemberSymbol)((ISymbolTable)baseType).FindSymbol(memberSymbol.Name, type, SymbolFilter.Members); Debug.Assert(baseMember != null); return(baseMember.GeneratedName); } int minimizationDepth = 0; int currentCount = -1; if (type is ClassSymbol) { currentCount = ((ClassSymbol)type).TransformationCookie; } else if (type is EnumerationSymbol) { currentCount = ((EnumerationSymbol)type).TransformationCookie; } if (type is ClassSymbol) { minimizationDepth = ((ClassSymbol)type).MinimizationDepth; if (currentCount == -1) { ClassSymbol baseClass = ((ClassSymbol)type).BaseClass; if (baseClass != null && baseClass.IsApplicationType) { // Set current count to the base classes transformation // cookie, so the generated one will the next one in // sequence currentCount = baseClass.TransformationCookie; } } } currentCount++; if (type is ClassSymbol) { ((ClassSymbol)type).TransformationCookie = currentCount; } else if (type is EnumerationSymbol) { ((EnumerationSymbol)type).TransformationCookie = currentCount; } return(GenerateName(currentCount, minimizationDepth)); } return(null); }
public VariableSymbol(string name, MemberSymbol parent, TypeSymbol valueType) : base(SymbolType.Variable, name, parent, valueType) { }