/// <summary> /// Expands the specified macro. /// </summary> /// <param name="macro">The macro.</param> /// <returns></returns> public override Statement Expand(MacroStatement macro) { Property property = new Property(propertyName); property.LexicalInfo = macro.LexicalInfo; property.Getter = new Method(); if(macro.Arguments.Count==1) { property.Getter.Body.Add( new ReturnStatement(macro.Arguments[0]) ); } else if( macro.Arguments.Count == 0 && macro.Body != null && macro.Body.IsEmpty == false)//use the macro block { property.Getter.Body = macro.Body; } else { CompilerErrorFactory.CustomError(macro.LexicalInfo, macro.Name + " must have a single expression argument or a block"); return null; } ClassDefinition clazz = (ClassDefinition) macro.GetAncestor(NodeType.ClassDefinition); clazz.Members.Add(property); return null; }
override public void LeaveProperty(Property node) { MakeStaticIfNeeded(node); CantBeMarkedTransient(node); CantBeMarkedPartial(node); CheckExplicitImpl(node); CheckModifierCombination(node); }
IReturnType CreateReturnType(AST.Property property) { if (property.Type == null && property.Getter != null && property.Getter.Body != null) { return(new BooInferredReturnType(property.Getter.Body, OuterClass, false)); } return(CreateReturnType(property.Type)); }
protected override void ExtendBaseClass(TypeDefinition definition) { Property property = new Property("Environment"); property.Getter = new Method("getter_Environment"); property.Getter.Body.Add( new ReturnStatement( new StringLiteralExpression(environment ?? "") ) ); definition.Members.Add(property); }
override public void Apply(Node node) { Field f = (Field)node; Property p = new Property(); p.Name = f.Name; p.Type = f.Type; p.Setter = CreateSetter(f); p.Getter = CreateGetter(f); ((TypeDefinition)f.ParentNode).Members.Replace(f, p); }
// get the directory name where this script reside and create a property // that return this value. // this is used to calculate relative paths when loading subviews. private void ScriptDirectoryProperty(ClassDefinition macro, Module module) { Property p = new Property("ScriptDirectory"); p.Modifiers = TypeMemberModifiers.Override; p.Getter = new Method("getScriptDirectory"); p.Getter.Body.Add( new ReturnStatement( new StringLiteralExpression( Path.GetDirectoryName(module.LexicalInfo.FileName)))); macro.Members.Add(p); }
private DomRegion GetClientRegion(AST.Node m) { AST.LexicalInfo l = m.LexicalInfo; if (l.Line < 0) { return(DomRegion.Empty); } AST.SourceLocation l2; if (m is AST.Method) { l2 = ((AST.Method)m).Body.EndSourceLocation; } else if (m is AST.Property) { AST.Property p = (AST.Property)m; if (p.Getter != null && p.Getter.Body != null) { l2 = p.Getter.Body.EndSourceLocation; if (p.Setter != null && p.Setter.Body != null) { if (p.Setter.Body.EndSourceLocation.Line > l2.Line) { l2 = p.Setter.Body.EndSourceLocation; } } } else if (p.Setter != null && p.Setter.Body != null) { l2 = p.Setter.Body.EndSourceLocation; } else { l2 = p.EndSourceLocation; } } else { l2 = m.EndSourceLocation; } if (l2 == null || l2.Line < 0 || l.Line == l2.Line) { return(DomRegion.Empty); } // TODO: use l.Column / l2.Column when the tab-bug has been fixed return(new DomRegion(l.Line, GetLineEnd(l.Line), l2.Line, GetLineEnd(l2.Line))); }
public override void OnProperty(AST.Property node) { DefaultProperty property = new DefaultProperty(node.Name, CreateReturnType(node), GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass); ConvertAttributes(node, property); ConvertParameters(node.Parameters, property); if (node.Getter != null && node.Getter.Body != null) { property.GetterRegion = GetClientRegion(node.Getter); } if (node.Setter != null && node.Setter.Body != null) { property.SetterRegion = GetClientRegion(node.Setter); } property.IsIndexer = (node.Name == "self"); OuterClass.Properties.Add(property); property.UserData = node; }
public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { B.Property m = new B.Property(GetLexicalInfo(propertyDeclaration)); m.Name = propertyDeclaration.Name; m.Modifiers = ConvertModifier(propertyDeclaration, B.TypeMemberModifiers.Private); ConvertAttributes(propertyDeclaration.Attributes, m.Attributes); if (currentType != null) { currentType.Members.Add(m); } ConvertParameters(propertyDeclaration.Parameters, m.Parameters); if (propertyDeclaration.IsIndexer) { m.Name = "self"; } m.EndSourceLocation = GetLocation(propertyDeclaration.EndLocation); m.Type = ConvertTypeReference(propertyDeclaration.TypeReference); m.ExplicitInfo = ConvertInterfaceImplementations(propertyDeclaration.InterfaceImplementations, propertyDeclaration, m); if (!propertyDeclaration.IsWriteOnly) { m.Getter = new B.Method(GetLexicalInfo(propertyDeclaration.GetRegion)); if (propertyDeclaration.GetRegion != null) { ConvertAttributes(propertyDeclaration.GetRegion.Attributes, m.Getter.Attributes); m.Getter.Modifiers = ConvertModifier(propertyDeclaration.GetRegion, B.TypeMemberModifiers.None); m.Getter.Body = ConvertMethodBlock(propertyDeclaration.GetRegion.Block); m.Getter.ReturnType = m.Type; } } if (!propertyDeclaration.IsReadOnly) { m.Setter = new B.Method(GetLexicalInfo(propertyDeclaration.SetRegion)); if (propertyDeclaration.SetRegion != null) { ConvertAttributes(propertyDeclaration.SetRegion.Attributes, m.Setter.Attributes); m.Setter.Modifiers = ConvertModifier(propertyDeclaration.SetRegion, B.TypeMemberModifiers.None); m.Setter.Body = ConvertMethodBlock(propertyDeclaration.SetRegion.Block); } } return(m); }
void SetPropertyAccessorModifiers(Property property, Method accessor) { if (!accessor.IsVisibilitySet) accessor.Modifiers |= property.Visibility; if (property.IsStatic) accessor.Modifiers |= TypeMemberModifiers.Static; if (property.IsVirtual) accessor.Modifiers |= TypeMemberModifiers.Virtual; if (property.IsAbstract) accessor.Modifiers |= TypeMemberModifiers.Abstract; else if (accessor.IsAbstract) // an abstract accessor makes the entire property abstract property.Modifiers |= TypeMemberModifiers.Abstract; }
override public object Clone() { Property clone = new Property(); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._isSynthetic = _isSynthetic; clone._entity = _entity; if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone(); clone._modifiers = _modifiers; clone._name = _name; if (null != _attributes) { clone._attributes = _attributes.Clone() as AttributeCollection; clone._attributes.InitializeParent(clone); } if (null != _parameters) { clone._parameters = _parameters.Clone() as ParameterDeclarationCollection; clone._parameters.InitializeParent(clone); } if (null != _getter) { clone._getter = _getter.Clone() as Method; clone._getter.InitializeParent(clone); } if (null != _setter) { clone._setter = _setter.Clone() as Method; clone._setter.InitializeParent(clone); } if (null != _type) { clone._type = _type.Clone() as TypeReference; clone._type.InitializeParent(clone); } if (null != _explicitInfo) { clone._explicitInfo = _explicitInfo.Clone() as ExplicitMemberInfo; clone._explicitInfo.InitializeParent(clone); } return clone; }
public object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { B.Property m = new B.Property(GetLexicalInfo(propertyDeclaration)); m.Name = propertyDeclaration.Name; m.Modifiers = ConvertModifier(propertyDeclaration, B.TypeMemberModifiers.Private); ConvertAttributes(propertyDeclaration.Attributes, m.Attributes); if (currentType != null) currentType.Members.Add(m); ConvertParameters(propertyDeclaration.Parameters, m.Parameters); if (propertyDeclaration.IsIndexer) m.Name = "self"; m.EndSourceLocation = GetLocation(propertyDeclaration.EndLocation); m.Type = ConvertTypeReference(propertyDeclaration.TypeReference); m.ExplicitInfo = ConvertInterfaceImplementations(propertyDeclaration.InterfaceImplementations, propertyDeclaration, m); if (!propertyDeclaration.IsWriteOnly) { m.Getter = new B.Method(GetLexicalInfo(propertyDeclaration.GetRegion)); if (propertyDeclaration.GetRegion != null) { ConvertAttributes(propertyDeclaration.GetRegion.Attributes, m.Getter.Attributes); m.Getter.Modifiers = ConvertModifier(propertyDeclaration.GetRegion, B.TypeMemberModifiers.None); m.Getter.Body = ConvertMethodBlock(propertyDeclaration.GetRegion.Block); m.Getter.ReturnType = m.Type; } } if (!propertyDeclaration.IsReadOnly) { m.Setter = new B.Method(GetLexicalInfo(propertyDeclaration.SetRegion)); if (propertyDeclaration.SetRegion != null) { ConvertAttributes(propertyDeclaration.SetRegion.Attributes, m.Setter.Attributes); m.Setter.Modifiers = ConvertModifier(propertyDeclaration.SetRegion, B.TypeMemberModifiers.None); m.Setter.Body = ConvertMethodBlock(propertyDeclaration.SetRegion.Block); } } return m; }
protected IProperty GetEntity(Property node) { return (IProperty)TypeSystemServices.GetEntity(node); }
public override void OnProperty(Property node) { node.Name = node.Name.TrimStart('@'); base.OnProperty(node); }
void SetPropertyAccessorModifiers(Property property, Method accessor) { if (!accessor.IsVisibilitySet) { accessor.Modifiers |= property.Visibility; } if (property.IsStatic) { accessor.Modifiers |= TypeMemberModifiers.Static; } if (property.IsVirtual) { accessor.Modifiers |= TypeMemberModifiers.Virtual; } /* if (property.IsOverride) { accessor.Modifiers |= TypeMemberModifiers.Override; } */ if (property.IsAbstract) { accessor.Modifiers |= TypeMemberModifiers.Abstract; } else if (accessor.IsAbstract) { // an abstract accessor makes the entire property abstract property.Modifiers |= TypeMemberModifiers.Abstract; } }
private void NormalizeDefaultItemProperty(Property node) { if (!IsDefaultItemProperty(node)) return; node.Name = "Item"; TypeDefinition declaringType = node.DeclaringType; if (declaringType != null) AddDefaultMemberAttribute(declaringType, node); }
public override void OnProperty(Property node) { }
public override void LeaveProperty(Property node) { if (!node.IsVisibilitySet && null == node.ExplicitInfo) { node.Modifiers |= TypeMemberModifiers.Public; } if (IsInterface(node.DeclaringType)) { node.Modifiers |= TypeMemberModifiers.Abstract; } if (null != node.Getter) { SetPropertyAccessorModifiers(node, node.Getter); node.Getter.Name = "get_" + node.Name; } if (null != node.Setter) { SetPropertyAccessorModifiers(node, node.Setter); node.Setter.Name = "set_" + node.Name; } LeaveMember(node); }
// get the original file name for this script and create a property // that return this value. private void ViewFileNameProperty(ClassDefinition macro, Module module) { var p = new Property("ViewFileName") { Modifiers = TypeMemberModifiers.Override, Getter = new Method("getViewFileName") }; p.Getter.Body.Add( new ReturnStatement( new StringLiteralExpression(module.LexicalInfo.FileName))); macro.Members.Add(p); }
protected override Statement ExpandImpl(MacroStatement macro) { Module module = macro.findModule(); string propname = ""; TypeReference type = new SimpleTypeReference("System.Object"); Expression initializer = null; if (macro.Arguments[0] is BinaryExpression) { var bin = macro.Arguments[0] as BinaryExpression; initializer = bin.Right; if (bin.Left is TryCastExpression) { var tce = bin.Left as TryCastExpression; propname = tce.Target.ToCodeString(); type = tce.Type ?? type; } //else //{ // propname = bin.Left.ToCodeString(); //} } //else //{ // propname = macro.Arguments[0].ToCodeString(); //} var geter = new Method("get_" + propname); geter.ReturnType = type; geter.Body = new Block(); if (initializer != null) { geter.Body.add( new IfStatement( new BinaryExpression( BinaryOperatorType.Equality, new NullLiteralExpression(), new MethodInvocationExpression( new ReferenceExpression("TryGetParameterNoIgnoreNull"), new StringLiteralExpression(propname)) ), new Block().add(new MethodInvocationExpression( new ReferenceExpression("SetProperty"), new StringLiteralExpression(propname), initializer ?? new NullLiteralExpression())) , null ) ); } var convertmethod = new GenericReferenceExpression(); convertmethod.Target = new ReferenceExpression("_convert"); convertmethod.GenericArguments.Add(type); var valuecall = new MethodInvocationExpression( new ReferenceExpression("TryGetParameterNoIgnoreNull"), new StringLiteralExpression(propname)); var convertcall = new MethodInvocationExpression(convertmethod,valuecall); geter.Body.add(new ReturnStatement(new CastExpression(convertcall, type))); var seter = new Method("set_" + propname); seter.Body = new Block().add(new MethodInvocationExpression( new ReferenceExpression("SetProperty"), new StringLiteralExpression(propname), new ReferenceExpression("value"))); var prop = new Property(geter, seter, type); prop.Name = propname; //try //{ ((TypeDefinition)module.Members[0]).Members.Insert(0, prop); //} //catch //{ // module.Members.Insert(0, prop); //in test env //} return null; }
private void AddDefaultMemberAttribute(TypeDefinition type, Property node) { if (!ContainsDefaultMemberAttribute(type)) { Attribute attribute = CodeBuilder.CreateAttribute( DefaultMemberAttributeStringConstructor(), new StringLiteralExpression(node.Name)); attribute.LexicalInfo = node.LexicalInfo; type.Attributes.Add(attribute); } }
private void NormalizePropertyModifiers(Property node) { if (IsInterfaceMember(node)) node.Modifiers = TypeMemberModifiers.Public | TypeMemberModifiers.Abstract; else if (!node.IsVisibilitySet && null == node.ExplicitInfo) node.Modifiers |= Context.Parameters.DefaultPropertyVisibility; if (null != node.Getter) { SetPropertyAccessorModifiers(node, node.Getter); node.Getter.Name = "get_" + node.Name; } if (null != node.Setter) { SetPropertyAccessorModifiers(node, node.Setter); node.Setter.Name = "set_" + node.Name; } }
private static bool IsDefaultItemProperty(Property node) { return (node.Name == "Item" || node.Name == "self") && node.Parameters.Count > 0 && !node.IsStatic; }
override public void LeaveProperty(Property node) { NormalizeDefaultItemProperty(node); NormalizePropertyModifiers(node); LeaveMember(node); }
public InternalProperty(TypeSystemServices typeSystemServices, Property property) { _typeSystemServices = typeSystemServices; _property = property; }
public override void LeaveProperty(Property node) { CheckName(node,node.Name); }
override public void LeaveProperty(Property node) { LeaveMember(node); }