public ApplyAttributeTask(CompilerContext context, Ast.Attribute attribute, Type type) { _context = context; _attribute = attribute; _type = type; _targetNode = TargetNode(); }
public ApplyAttributeTask(CompilerContext context, Ast.Attribute attribute, Type type) { _context = context; _attribute = attribute; _type = type; _targetNode = TargetNode(); }
public static JToken ToJson(Ast.Attribute a) { var obj = (JObject)ToJson((SyntaxNode)a); obj["type"] = "Attribute"; obj["id"] = ToJson((dynamic)a.Id); obj["value"] = ToJson(a.Value); return(obj); }
private void CheckAttributeParameters(Ast.Attribute node) { foreach (var e in node.Arguments) { if (e.NodeType == NodeType.BinaryExpression && ((BinaryExpression)e).Operator == BinaryOperatorType.Assign) { Error(node, CompilerErrorFactory.ColonInsteadOfEquals(node)); } } }
private static Type AttributeType(Ast.Attribute node) { IExternalEntity attr = node.Entity as IExternalEntity; if (null == attr) { return(null); } return(attr.MemberInfo.DeclaringType); }
private static bool IsOfType(Ast.Attribute attribute, IType attributeType) { var entity = TypeSystemServices.GetEntity(attribute); if (entity == attributeType) { return(true); } var constructor = entity as IConstructor; return(constructor != null && constructor.DeclaringType == attributeType); }
private static AttributeTargets?TargetFor(Ast.Attribute node) { if (node.ParentNode is Method) { AttributeCollection returnTypeAttributes = ((Method)node.ParentNode).ReturnTypeAttributes; if (returnTypeAttributes.Contains(node)) { return(AttributeTargets.ReturnValue); } } AttributeTargets target; if (NodeUsageTargets().TryGetValue(node.ParentNode.GetType(), out target)) { return(target); } return(null); }
void ScheduleAttributeApplication(Ast.Attribute attribute, Type type) { _pendingApplications.Add(new ApplyAttributeTask(Context, attribute, type)); }
void Error(Ast.Attribute node, CompilerError error) { node.Entity = TypeSystemServices.ErrorEntity; Errors.Add(error); }
override public void OnAttribute(Ast.Attribute attribute) { if (null != attribute.Entity) { return; } var entity = NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, true)) ?? NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, false)) ?? NameResolutionService.ResolveQualifiedName(attribute.Name); if (entity == null) { var suggestion = NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, true)) ?? NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, false)); Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name, suggestion)); return; } if (entity.IsAmbiguous()) { Error(attribute, CompilerErrorFactory.AmbiguousReference( attribute, attribute.Name, ((Ambiguous)entity).Entities)); return; } if (EntityType.Type != entity.EntityType) { Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name, entity, null)); return; } IType attributeType = ((ITypedEntity)entity).Type; if (IsAstAttribute(attributeType)) { ExternalType externalType = attributeType as ExternalType; if (null == externalType) { Error(attribute, CompilerErrorFactory.AstAttributeMustBeExternal(attribute, attributeType)); } else { ScheduleAttributeApplication(attribute, externalType.ActualType); RemoveCurrentNode(); } } else { if (!IsSystemAttribute(attributeType)) { Error(attribute, CompilerErrorFactory.TypeNotAttribute(attribute, attributeType)); } else { // remember the attribute's type attribute.Name = attributeType.FullName; attribute.Entity = entity; CheckAttributeParameters(attribute); } } }
static Ast.Attribute CreateNonCustomAttribute(Type attributeType, ModuleDefinition module) { Debug.Assert(attributeType.Name.EndsWith("Attribute", StringComparison.Ordinal)); Ast.Attribute attr = new Ast.Attribute(); attr.Type = new SimpleType(attributeType.Name.Substring(0, attributeType.Name.Length - "Attribute".Length)); if (module != null) { attr.Type.AddAnnotation(new TypeReference(attributeType.Namespace, attributeType.Name, module, module.TypeSystem.Corlib)); } return attr; }