public BinaryExpression(Operator operatorType, Expression leftOperand, Expression rightOperand, TypeSymbol evaluatedType) : base(ExpressionType.Binary, evaluatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers) { _operator = operatorType; _leftOperand = leftOperand; _rightOperand = rightOperand; }
public NewDelegateExpression(Expression typeExpression, TypeSymbol associatedType) : base(ExpressionType.NewDelegate, associatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers) { Debug.Assert(associatedType.Type == SymbolType.Delegate); _typeExpression = typeExpression; _associatedType = associatedType; }
private FieldSymbol BuildField(FieldDeclarationNode fieldNode, TypeSymbol typeSymbol) { TypeSymbol fieldType = typeSymbol.SymbolSet.ResolveType(fieldNode.Type, _symbolTable, typeSymbol); Debug.Assert(fieldType != null); if (fieldType != null) { FieldSymbol symbol = new FieldSymbol(fieldNode.Name, typeSymbol, fieldType); BuildMemberDetails(symbol, typeSymbol, fieldNode, fieldNode.Attributes); if (fieldNode.Initializers.Count != 0) { VariableInitializerNode initializer = (VariableInitializerNode)fieldNode.Initializers[0]; if ((initializer.Value != null) && (initializer.Value.NodeType != ParseNodeType.Literal)) { symbol.SetImplementationState(/* hasInitializer */ true); } } if (fieldNode.NodeType == ParseNodeType.ConstFieldDeclaration) { Debug.Assert(fieldNode.Initializers.Count == 1); VariableInitializerNode initializer = (VariableInitializerNode)fieldNode.Initializers[0]; if ((initializer.Value != null) && (initializer.Value.NodeType == ParseNodeType.Literal)) { symbol.SetConstant(); symbol.Value = ((LiteralToken)initializer.Value.Token).LiteralValue; } // TODO: Handle other constant cases that can be evaluated at compile // time (eg. combining enum flags) } return symbol; } return null; }
private EventSymbol BuildEvent(EventDeclarationNode eventNode, TypeSymbol typeSymbol) { TypeSymbol handlerType = typeSymbol.SymbolSet.ResolveType(eventNode.Type, _symbolTable, typeSymbol); Debug.Assert(handlerType != null); if (handlerType != null) { EventSymbol eventSymbol = new EventSymbol(eventNode.Name, typeSymbol, handlerType); BuildMemberDetails(eventSymbol, typeSymbol, eventNode, eventNode.Attributes); if (eventNode.IsField) { eventSymbol.SetImplementationState(SymbolImplementationFlags.Generated); } else { if ((eventNode.Modifiers & Modifiers.Abstract) != 0) { eventSymbol.SetImplementationState(SymbolImplementationFlags.Abstract); } else if ((eventNode.Modifiers & Modifiers.Override) != 0) { eventSymbol.SetImplementationState(SymbolImplementationFlags.Override); } } return eventSymbol; } return null; }
public LateBoundExpression(Expression objectReference, Expression nameExpression, LateBoundOperation operation, TypeSymbol evaluatedType) : base(ExpressionType.LateBound, evaluatedType, SymbolFilter.Public | SymbolFilter.InstanceMembers) { _objectReference = objectReference; _nameExpression = nameExpression; _operation = operation; _parameters = new Collection<Expression>(); }
public AnonymousMethodSymbol(CodeMemberSymbol containingMember, ISymbolTable stackContext, TypeSymbol returnType, bool isStatic) : base(SymbolType.AnonymousMethod, /* name */ String.Empty, (TypeSymbol)containingMember.Parent, returnType) { SetVisibility(isStatic ? MemberVisibility.Public | MemberVisibility.Static : MemberVisibility.Public); _containingMember = containingMember; _stackContext = stackContext; _containingMember.AddAnonymousMethod(this); }
public static void GenerateRegistrationScript(ScriptGenerator generator, TypeSymbol typeSymbol) { ClassSymbol classSymbol = typeSymbol as ClassSymbol; if ((classSymbol != null) && classSymbol.IsExtenderClass) { return; } ScriptTextWriter writer = generator.Writer; writer.Write(typeSymbol.GeneratedName); writer.Write(": "); switch (typeSymbol.Type) { case SymbolType.Class: writer.Write("[ "); writer.Write(typeSymbol.FullGeneratedName); writer.Write(", "); if (((ClassSymbol)typeSymbol).IsStaticClass == false) { writer.Write(typeSymbol.FullGeneratedName); writer.Write("$, "); } else { writer.Write("null, "); } if ((classSymbol.BaseClass == null) || classSymbol.IsTestClass) { // TODO: We need to introduce the notion of a base class that only exists in the metadata // and not at runtime. At that point this check of IsTestClass can be generalized. writer.Write("null"); } else { writer.Write(classSymbol.BaseClass.FullGeneratedName); } if (classSymbol.Interfaces != null) { foreach (InterfaceSymbol interfaceSymbol in classSymbol.Interfaces) { writer.Write(", "); writer.Write(interfaceSymbol.FullGeneratedName); } } writer.Write(" ]"); break; case SymbolType.Interface: writer.Write("[ "); writer.Write(typeSymbol.FullGeneratedName); writer.Write(" ]"); break; case SymbolType.Record: case SymbolType.Resources: case SymbolType.Enumeration: writer.Write(typeSymbol.FullGeneratedName); break; } }
public void AddType(TypeSymbol typeSymbol) { Debug.Assert(typeSymbol != null); Debug.Assert(String.IsNullOrEmpty(typeSymbol.Name) == false); Debug.Assert(_typeMap.ContainsKey(typeSymbol.Name) == false); _types.Add(typeSymbol); _typeMap[typeSymbol.Name] = typeSymbol; if (typeSymbol.IsApplicationType) { _hasApplicationTypes = true; } }
private EnumerationFieldSymbol BuildEnumField(EnumerationFieldNode fieldNode, TypeSymbol typeSymbol) { Debug.Assert(typeSymbol is EnumerationSymbol); EnumerationSymbol enumSymbol = (EnumerationSymbol)typeSymbol; TypeSymbol fieldTypeSymbol; if (enumSymbol.UseNamedValues) { fieldTypeSymbol = _symbols.ResolveIntrinsicType(IntrinsicType.String); } else { fieldTypeSymbol = _symbols.ResolveIntrinsicType(IntrinsicType.Integer); } EnumerationFieldSymbol fieldSymbol = new EnumerationFieldSymbol(fieldNode.Name, typeSymbol, fieldNode.Value, fieldTypeSymbol); BuildMemberDetails(fieldSymbol, typeSymbol, fieldNode, fieldNode.Attributes); return fieldSymbol; }
private string TransformType(TypeSymbol typeSymbol, out bool transformChildren) { transformChildren = (typeSymbol.Type != SymbolType.Interface) && (typeSymbol.Type != SymbolType.Delegate); if ((typeSymbol.Type == SymbolType.Enumeration) && ((EnumerationSymbol)typeSymbol).UseNamedValues) { // If the enum uses named values, then don't transform, as its // unlikely the code wants to use some random generated name as the // named value. transformChildren = false; } if ((typeSymbol.IsPublic == false) && typeSymbol.IsTransformAllowed) { return GenerateName(typeSymbol.Name); } return null; }
private PropertySymbol BuildProperty(PropertyDeclarationNode propertyNode, TypeSymbol typeSymbol) { TypeSymbol propertyType = typeSymbol.SymbolSet.ResolveType(propertyNode.Type, _symbolTable, typeSymbol); Debug.Assert(propertyType != null); if (propertyType != null) { PropertySymbol property = new PropertySymbol(propertyNode.Name, typeSymbol, propertyType); BuildMemberDetails(property, typeSymbol, propertyNode, propertyNode.Attributes); SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular; if (propertyNode.SetAccessor == null) { implFlags |= SymbolImplementationFlags.ReadOnly; } if ((propertyNode.Modifiers & Modifiers.Abstract) != 0) { implFlags |= SymbolImplementationFlags.Abstract; } else if ((propertyNode.Modifiers & Modifiers.Override) != 0) { implFlags |= SymbolImplementationFlags.Override; } property.SetImplementationState(implFlags); property.AddParameter(new ParameterSymbol("value", property, propertyType, ParameterMode.In)); return property; } return null; }
private MethodSymbol BuildMethod(MethodDeclarationNode methodNode, TypeSymbol typeSymbol) { MethodSymbol method = null; if (methodNode.NodeType == ParseNodeType.ConstructorDeclaration) { method = new ConstructorSymbol(typeSymbol, (methodNode.Modifiers & Modifiers.Static) != 0); } else { TypeSymbol returnType = typeSymbol.SymbolSet.ResolveType(methodNode.Type, _symbolTable, typeSymbol); Debug.Assert(returnType != null); if (returnType != null) { method = new MethodSymbol(methodNode.Name, typeSymbol, returnType); BuildMemberDetails(method, typeSymbol, methodNode, methodNode.Attributes); ICollection<string> conditions = null; foreach (AttributeNode attrNode in methodNode.Attributes) { if (attrNode.TypeName.Equals("Conditional", StringComparison.Ordinal)) { if (conditions == null) { conditions = new List<string>(); } Debug.Assert(attrNode.Arguments[0] is LiteralNode); Debug.Assert(((LiteralNode)attrNode.Arguments[0]).Value is string); conditions.Add((string)((LiteralNode)attrNode.Arguments[0]).Value); } } if (conditions != null) { method.SetConditions(conditions); } } } if (method != null) { if ((methodNode.Modifiers & Modifiers.Abstract) != 0) { method.SetImplementationState(SymbolImplementationFlags.Abstract); } else if ((methodNode.Modifiers & Modifiers.Override) != 0) { method.SetImplementationState(SymbolImplementationFlags.Override); } if ((methodNode.Parameters != null) && (methodNode.Parameters.Count != 0)) { foreach (ParameterNode parameterNode in methodNode.Parameters) { ParameterSymbol paramSymbol = BuildParameter(parameterNode, method); if (paramSymbol != null) { paramSymbol.SetParseContext(parameterNode); method.AddParameter(paramSymbol); } } } if ((method.Visibility & MemberVisibility.Static) != 0) { string scriptAlias = GetAttributeValue(methodNode.Attributes, "ScriptAlias"); if (scriptAlias != null) { method.SetAlias(scriptAlias); } } } return method; }
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 TypeSymbol CreateGenericTypeCore(TypeSymbol templateType, IList <TypeSymbol> typeArguments) { if (templateType.Type == SymbolType.Class) { ClassSymbol genericClass = (ClassSymbol)templateType; ClassSymbol instanceClass = new ClassSymbol(genericClass.Name, (NamespaceSymbol)genericClass.Parent); instanceClass.SetInheritance(genericClass.BaseClass, genericClass.Interfaces); instanceClass.SetImported(genericClass.DependencyName); if (genericClass.IgnoreNamespace) { instanceClass.SetIgnoreNamespace(); } instanceClass.ScriptNamespace = genericClass.ScriptNamespace; if (genericClass.IsTransformed) { instanceClass.SetTransformedName(genericClass.GeneratedName); } else if (genericClass.IsTransformAllowed == false) { instanceClass.DisableNameTransformation(); } instanceClass.AddGenericParameters(genericClass.GenericParameters); instanceClass.AddGenericArguments(genericClass, typeArguments); CreateGenericTypeMembers(genericClass, instanceClass, typeArguments); return(instanceClass); } else if (templateType.Type == SymbolType.Interface) { InterfaceSymbol genericInterface = (InterfaceSymbol)templateType; InterfaceSymbol instanceInterface = new InterfaceSymbol(genericInterface.Name, (NamespaceSymbol)genericInterface.Parent); instanceInterface.SetImported(genericInterface.DependencyName); if (genericInterface.IgnoreNamespace) { instanceInterface.SetIgnoreNamespace(); } if (genericInterface.IsTransformed) { instanceInterface.SetTransformedName(genericInterface.GeneratedName); } else if (genericInterface.IsTransformAllowed == false) { instanceInterface.DisableNameTransformation(); } instanceInterface.AddGenericParameters(genericInterface.GenericParameters); instanceInterface.AddGenericArguments(genericInterface, typeArguments); CreateGenericTypeMembers(genericInterface, instanceInterface, typeArguments); return(instanceInterface); } else if (templateType.Type == SymbolType.Delegate) { DelegateSymbol genericDelegate = (DelegateSymbol)templateType; DelegateSymbol instanceDelegate = new DelegateSymbol(genericDelegate.Name, (NamespaceSymbol)genericDelegate.Parent); instanceDelegate.AddGenericParameters(genericDelegate.GenericParameters); instanceDelegate.AddGenericArguments(genericDelegate, typeArguments); CreateGenericTypeMembers(genericDelegate, instanceDelegate, typeArguments); return(instanceDelegate); } return(null); }
public PropertySymbol(string name, TypeSymbol parent, TypeSymbol propertyType) : this(SymbolType.Property, name, parent, propertyType) { }
public MethodSymbol(string name, TypeSymbol parent, TypeSymbol returnType, MemberVisibility visibility) : this(SymbolType.Method, name, parent, returnType) { SetVisibility(visibility); }
public bool IsSymbol(TypeSymbol symbol, string symbolName) { return(((ISymbolTable)this).FindSymbol(symbolName, null, SymbolFilter.Types) == symbol); }
public ConstructorSymbol(TypeSymbol parent, bool isStatic) : base(SymbolType.Constructor, /* name */ String.Empty, parent, /* associatedType */ parent) { SetVisibility(isStatic ? MemberVisibility.Public | MemberVisibility.Static : MemberVisibility.Public); }
public IndexerSymbol(TypeSymbol parent, TypeSymbol propertyType) : base(SymbolType.Indexer, "Item", parent, propertyType) { }
/// <summary> /// This maps C# intrinsic types (managed types that have an equivalent /// C# keyword) /// </summary> public TypeSymbol ResolveIntrinsicType(IntrinsicType type) { string mappedTypeName = null; string mappedNamespace = null; switch (type) { case IntrinsicType.Object: mappedTypeName = "Object"; break; case IntrinsicType.Boolean: mappedTypeName = "Boolean"; break; case IntrinsicType.String: mappedTypeName = "String"; break; case IntrinsicType.Integer: mappedTypeName = "Int32"; break; case IntrinsicType.UnsignedInteger: mappedTypeName = "UInt32"; break; case IntrinsicType.Long: mappedTypeName = "Int64"; break; case IntrinsicType.UnsignedLong: mappedTypeName = "UInt64"; break; case IntrinsicType.Short: mappedTypeName = "Int16"; break; case IntrinsicType.UnsignedShort: mappedTypeName = "UInt16"; break; case IntrinsicType.Byte: mappedTypeName = "Byte"; break; case IntrinsicType.SignedByte: mappedTypeName = "SByte"; break; case IntrinsicType.Single: mappedTypeName = "Single"; break; case IntrinsicType.Decimal: mappedTypeName = "Decimal"; break; case IntrinsicType.Double: mappedTypeName = "Double"; break; case IntrinsicType.Delegate: mappedTypeName = "Delegate"; break; case IntrinsicType.Function: mappedTypeName = "Function"; break; case IntrinsicType.Void: mappedTypeName = "Void"; break; case IntrinsicType.Array: mappedTypeName = "Array"; break; case IntrinsicType.Dictionary: mappedTypeName = "Dictionary"; mappedNamespace = "System.Collections"; break; case IntrinsicType.GenericList: mappedTypeName = "List`1"; mappedNamespace = "System.Collections.Generic"; break; case IntrinsicType.GenericDictionary: mappedTypeName = "Dictionary`2"; mappedNamespace = "System.Collections.Generic"; break; case IntrinsicType.Type: mappedTypeName = "Type"; break; case IntrinsicType.IEnumerator: mappedTypeName = "IEnumerator"; mappedNamespace = "System.Collections"; break; case IntrinsicType.Enum: mappedTypeName = "Enum"; break; case IntrinsicType.Exception: mappedTypeName = "Exception"; break; case IntrinsicType.Script: mappedTypeName = "Script"; break; case IntrinsicType.Number: mappedTypeName = "Number"; break; case IntrinsicType.Arguments: mappedTypeName = "Arguments"; break; case IntrinsicType.Nullable: mappedTypeName = "Nullable`1"; break; default: Debug.Fail("Unmapped intrinsic type " + type); break; } NamespaceSymbol ns = _systemNamespace; if (mappedNamespace != null) { ns = GetNamespace(mappedNamespace); Debug.Assert(ns != null); } if (mappedTypeName != null) { TypeSymbol typeSymbol = (TypeSymbol)((ISymbolTable)ns).FindSymbol(mappedTypeName, null, SymbolFilter.Types); Debug.Assert(typeSymbol != null); return(typeSymbol); } return(null); }
private FieldSymbol BuildPropertyAsField(PropertyDeclarationNode propertyNode, TypeSymbol typeSymbol) { AttributeNode intrinsicPropertyAttribute = AttributeNode.FindAttribute(propertyNode.Attributes, "IntrinsicProperty"); if (intrinsicPropertyAttribute == null) { return null; } TypeSymbol fieldType = typeSymbol.SymbolSet.ResolveType(propertyNode.Type, _symbolTable, typeSymbol); Debug.Assert(fieldType != null); if (fieldType != null) { FieldSymbol symbol = new FieldSymbol(propertyNode.Name, typeSymbol, fieldType); BuildMemberDetails(symbol, typeSymbol, propertyNode, propertyNode.Attributes); string scriptAlias = GetAttributeValue(propertyNode.Attributes, "ScriptAlias"); if (scriptAlias != null) { symbol.SetAlias(scriptAlias); } return symbol; } return null; }
private void BuildType(TypeSymbol typeSymbol, UserTypeNode typeNode) { Debug.Assert(typeSymbol != null); Debug.Assert(typeNode != null); ParseNodeList attributes = typeNode.Attributes; if (AttributeNode.FindAttribute(attributes, "Imported") != null) { typeSymbol.SetImported(/* dependencyName */ null); } if (AttributeNode.FindAttribute(attributes, "IgnoreNamespace") != null) { typeSymbol.SetIgnoreNamespace(); } if (AttributeNode.FindAttribute(attributes, "PreserveName") != null) { typeSymbol.DisableNameTransformation(); } string scriptName = GetAttributeValue(attributes, "ScriptName"); if (scriptName != null) { typeSymbol.SetTransformedName(scriptName); } if (typeNode.Type == TokenType.Class) { bool globalizeMembers = false; string mixinRoot = null; AttributeNode globalMethodsAttribute = AttributeNode.FindAttribute(attributes, "GlobalMethods"); if (globalMethodsAttribute != null) { globalizeMembers = true; } else { AttributeNode mixinAttribute = AttributeNode.FindAttribute(attributes, "Mixin"); if (mixinAttribute != null) { Debug.Assert(mixinAttribute.Arguments[0] is LiteralNode); Debug.Assert(((LiteralNode)mixinAttribute.Arguments[0]).Value is string); mixinRoot = (string)((LiteralNode)mixinAttribute.Arguments[0]).Value; globalizeMembers = true; } } if (globalizeMembers) { ((ClassSymbol)typeSymbol).SetGlobalMethods(mixinRoot); } } if (typeNode.Type == TokenType.Enum) { if (AttributeNode.FindAttribute(attributes, "NamedValues") != null) { ((EnumerationSymbol)typeSymbol).SetNamedValues(); } else if (AttributeNode.FindAttribute(attributes, "NumericValues") != null) { ((EnumerationSymbol)typeSymbol).SetNumericValues(); } } }
protected Expression(ExpressionType type, TypeSymbol evaluatedType, SymbolFilter memberMask) { _type = type; _evaluatedType = evaluatedType; _memberMask = memberMask | SymbolFilter.Members; }
private MemberVisibility GetVisibility(MemberNode node, TypeSymbol typeSymbol) { if (typeSymbol.Type == SymbolType.Interface) { return MemberVisibility.Public; } MemberVisibility visibility = MemberVisibility.PrivateInstance; if (((node.Modifiers & Modifiers.Static) != 0) || (node.NodeType == ParseNodeType.ConstFieldDeclaration)) { visibility |= MemberVisibility.Static; } if ((node.Modifiers & Modifiers.Public) != 0) { visibility |= MemberVisibility.Public; } else { if ((node.Modifiers & Modifiers.Protected) != 0) { visibility |= MemberVisibility.Protected; } if ((node.Modifiers & Modifiers.Internal) != 0) { visibility |= MemberVisibility.Internal; } } return visibility; }
public void Reevaluate(TypeSymbol evaluatedType) { _evaluatedType = evaluatedType; }
public IndexerSymbol(TypeSymbol parent, TypeSymbol propertyType, MemberVisibility visibility) : this(parent, propertyType) { SetVisibility(visibility); }
public VariableSymbol(string name, MemberSymbol parent, TypeSymbol valueType) : base(SymbolType.Variable, name, parent, valueType) { }
public static void GenerateScript(ScriptGenerator generator, TypeSymbol typeSymbol) { Debug.Assert(generator != null); Debug.Assert(typeSymbol != null); Debug.Assert(typeSymbol.IsApplicationType); if (typeSymbol.Type == SymbolType.Delegate) { // No-op ... there is currently nothing to generate for a particular delegate type return; } if ((typeSymbol.Type == SymbolType.Record) && (typeSymbol.IsPublic == false) && (((RecordSymbol)typeSymbol).Constructor == null)) { // Nothing to generate for internal records with no explicit ctor return; } if ((typeSymbol.Type == SymbolType.Class) && ((ClassSymbol)typeSymbol).IsModuleClass) { // No members on script modules, which only contain startup code return; } ScriptTextWriter writer = generator.Writer; writer.WriteLine("// " + typeSymbol.FullName); writer.WriteLine(); switch (typeSymbol.Type) { case SymbolType.Class: if (((ClassSymbol)typeSymbol).IsExtenderClass) { GenerateExtensionMethods(generator, (ClassSymbol)typeSymbol); } else { GenerateClass(generator, (ClassSymbol)typeSymbol); } break; case SymbolType.Interface: GenerateInterface(generator, (InterfaceSymbol)typeSymbol); break; case SymbolType.Enumeration: GenerateEnumeration(generator, (EnumerationSymbol)typeSymbol); break; case SymbolType.Record: GenerateRecord(generator, (RecordSymbol)typeSymbol); break; case SymbolType.Resources: GenerateResources(generator, (ResourcesSymbol)typeSymbol); break; } writer.WriteLine(); writer.WriteLine(); }
private IndexerSymbol BuildIndexer(IndexerDeclarationNode indexerNode, TypeSymbol typeSymbol) { TypeSymbol indexerType = typeSymbol.SymbolSet.ResolveType(indexerNode.Type, _symbolTable, typeSymbol); Debug.Assert(indexerType != null); if (indexerType != null) { IndexerSymbol indexer = new IndexerSymbol(typeSymbol, indexerType); BuildMemberDetails(indexer, typeSymbol, indexerNode, indexerNode.Attributes); if (AttributeNode.FindAttribute(indexerNode.Attributes, "IntrinsicProperty") != null) { indexer.SetIntrinsic(); } SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular; if (indexerNode.SetAccessor == null) { implFlags |= SymbolImplementationFlags.ReadOnly; } if ((indexerNode.Modifiers & Modifiers.Abstract) != 0) { implFlags |= SymbolImplementationFlags.Abstract; } else if ((indexerNode.Modifiers & Modifiers.Override) != 0) { implFlags |= SymbolImplementationFlags.Override; } indexer.SetImplementationState(implFlags); Debug.Assert(indexerNode.Parameters.Count != 0); foreach (ParameterNode parameterNode in indexerNode.Parameters) { ParameterSymbol paramSymbol = BuildParameter(parameterNode, indexer); if (paramSymbol != null) { paramSymbol.SetParseContext(parameterNode); indexer.AddParameter(paramSymbol); } } indexer.AddParameter(new ParameterSymbol("value", indexer, indexerType, ParameterMode.In)); return indexer; } return null; }
public MethodSymbol(string name, TypeSymbol parent, TypeSymbol returnType) : this(SymbolType.Method, name, parent, returnType) { }
private void BuildMemberDetails(MemberSymbol memberSymbol, TypeSymbol typeSymbol, MemberNode memberNode, ParseNodeList attributes) { if (memberSymbol.Type != SymbolType.EnumerationField) { memberSymbol.SetVisibility(GetVisibility(memberNode, typeSymbol)); } bool preserveCase = (AttributeNode.FindAttribute(attributes, "PreserveCase") != null); memberSymbol.SetNameCasing(preserveCase); string scriptName = GetAttributeValue(attributes, "ScriptName"); if (scriptName != null) { memberSymbol.SetTransformedName(scriptName); } else if (AttributeNode.FindAttribute(attributes, "PreserveName") != null) { memberSymbol.DisableNameTransformation(); } }
protected MethodSymbol(SymbolType type, string name, TypeSymbol parent, TypeSymbol returnType) : base(type, name, parent, returnType) { }
private void BuildMembers(TypeSymbol typeSymbol) { if (typeSymbol.Type == SymbolType.Delegate) { DelegateTypeNode delegateNode = (DelegateTypeNode)typeSymbol.ParseContext; TypeSymbol returnType = typeSymbol.SymbolSet.ResolveType(delegateNode.ReturnType, _symbolTable, typeSymbol); Debug.Assert(returnType != null); if (returnType != null) { MethodSymbol invokeMethod = new MethodSymbol("Invoke", typeSymbol, returnType, MemberVisibility.Public); invokeMethod.SetTransformedName(String.Empty); // Mark the method as abstract, as there is no actual implementation of the method // to be generated invokeMethod.SetImplementationState(SymbolImplementationFlags.Abstract); typeSymbol.AddMember(invokeMethod); } return; } CustomTypeNode typeNode = (CustomTypeNode)typeSymbol.ParseContext; foreach (MemberNode member in typeNode.Members) { MemberSymbol memberSymbol = null; switch (member.NodeType) { case ParseNodeType.FieldDeclaration: case ParseNodeType.ConstFieldDeclaration: memberSymbol = BuildField((FieldDeclarationNode)member, typeSymbol); break; case ParseNodeType.PropertyDeclaration: memberSymbol = BuildPropertyAsField((PropertyDeclarationNode)member, typeSymbol); if (memberSymbol == null) { memberSymbol = BuildProperty((PropertyDeclarationNode)member, typeSymbol); } break; case ParseNodeType.IndexerDeclaration: memberSymbol = BuildIndexer((IndexerDeclarationNode)member, typeSymbol); break; case ParseNodeType.ConstructorDeclaration: case ParseNodeType.MethodDeclaration: if ((member.Modifiers & Modifiers.Extern) != 0) { // Extern methods are there for defining overload signatures, so // we just skip them as far as metadata goes. The validator has // taken care of the requirements/constraints around use of extern methods. continue; } memberSymbol = BuildMethod((MethodDeclarationNode)member, typeSymbol); break; case ParseNodeType.EventDeclaration: memberSymbol = BuildEvent((EventDeclarationNode)member, typeSymbol); break; case ParseNodeType.EnumerationFieldDeclaration: memberSymbol = BuildEnumField((EnumerationFieldNode)member, typeSymbol); break; } if (memberSymbol != null) { memberSymbol.SetParseContext(member); if ((typeSymbol.IsApplicationType == false) && ((memberSymbol.Type == SymbolType.Constructor) || (typeSymbol.GetMember(memberSymbol.Name) != null))) { // If the type is an imported type, then it is allowed to contain // overloads, and we're simply going to ignore its existence, as long // as one overload has been added to the member table. continue; } typeSymbol.AddMember(memberSymbol); if ((typeSymbol.Type == SymbolType.Class) && (memberSymbol.Type == SymbolType.Event)) { EventSymbol eventSymbol = (EventSymbol)memberSymbol; if (eventSymbol.DefaultImplementation) { // Add a private field that will serve as the backing member // later on in the conversion (eg. in non-event expressions) MemberVisibility visibility = MemberVisibility.PrivateInstance; if ((eventSymbol.Visibility & MemberVisibility.Static) != 0) { visibility |= MemberVisibility.Static; } FieldSymbol fieldSymbol = new FieldSymbol("__" + Utility.CreateCamelCaseName(eventSymbol.Name), typeSymbol, eventSymbol.AssociatedType); fieldSymbol.SetVisibility(visibility); fieldSymbol.SetParseContext(((EventDeclarationNode)eventSymbol.ParseContext).Field); typeSymbol.AddMember(fieldSymbol); } } } } }
protected PropertySymbol(SymbolType type, string name, TypeSymbol parent, TypeSymbol propertyType) : base(type, name, parent, propertyType) { }
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.IsIntrinsic) { instanceIndexer.SetIntrinsic(); } instanceIndexer.SetVisibility(templateIndexer.Visibility); return(instanceIndexer); } else 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); } else if (templateMember.Type == SymbolType.Field) { FieldSymbol templateField = (FieldSymbol)templateMember; FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType); if (templateField.IsTransformed) { instanceField.SetTransformedName(templateField.GeneratedName); } instanceField.SetNameCasing(templateField.IsCasePreserved); instanceField.SetVisibility(templateField.Visibility); return(instanceField); } else if (templateMember.Type == SymbolType.Method) { MethodSymbol templateMethod = (MethodSymbol)templateMember; MethodSymbol instanceMethod = new MethodSymbol(templateMethod.Name, parentType, instanceAssociatedType); if (templateMethod.IsTransformed) { instanceMethod.SetTransformedName(templateMethod.GeneratedName); } 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); }