示例#1
0
        public override bool AttachTo(IOwnedNode parent)
        {
            // IMPORTANT: when function is attached to a type, the type is NOT fully constructed!

            bool result = base.AttachTo(parent);

            // property accessors will see owner type in second attach, when property is attached to type
            TypeDefinition owner_type = this.ContainingType();

            if (this.MetaThisParameter == null && owner_type != null && // method
                !this.Modifier.HasStatic && !owner_type.Modifier.HasStatic)
            {
                NameReference type_name = owner_type.InstanceOf.NameOf; // initially already tied to target
                this.MetaThisParameter = FunctionParameter.Create(NameFactory.ThisVariableName,
                                                                  owner_type.Modifier.HasHeapOnly ? NameFactory.PointerNameReference(type_name)
                        : NameFactory.ReferenceNameReference(type_name),
                                                                  Variadic.None, null, isNameRequired: false,
                                                                  usageMode: ExpressionReadMode.OptionalUse);
                this.MetaThisParameter.AttachTo(this);
            }

            // marking regular functions a static one will make further processing easier
            if (!this.Modifier.HasStatic && parent is IEntity entity_parent && entity_parent.Modifier.HasStatic)
            {
                this.SetModifier(this.Modifier | EntityModifier.Static);
            }

            if (!this.Modifier.IsAccessSet)
            {
                if (parent is TypeContainerDefinition)
                {
                    this.SetModifier(this.Modifier | EntityModifier.Public);
                }
                else if (parent is Property prop)
                {
                    this.SetModifier(this.Modifier | prop.Modifier.AccessLevels);
                }
            }

            return(result);
        }
示例#2
0
 private void setResultParameter(INameReference result)
 {
     this.ResultParameter = FunctionParameter.Create("", result, ExpressionReadMode.OptionalUse);
 }