public Function CreateSetter(CodeString Declaration, CodeString ValueName, CodeString Code, IdentifierAccess Access = IdentifierAccess.Public) { var PChildren = Property.Children.Length; var Children = new Identifier[PChildren + 1]; Children[0] = GlobalContainer.CommonIds.Void; Children[PChildren] = new FunctionParameter(this, ValueName, Property.TypeOfSelf); for (var i = 1; i < PChildren; i++) { Children[i] = Property.Children[i]; } var Type = new TypeOfFunction(this, DefaultCallConv, Children); var Ret = CreateFunctionForAccessor("set", Declaration, Type, Access); if (Ret == null || !CreateScopeForAccessor(Ret, Code)) { return(null); } Setter = Ret; return(Ret); }
public Constructor CreateDeclaredConstructor(CodeString Declaration, FunctionParameter[] Params, List <Modifier> Mods = null) { if (ConstructorOverloads == null) { ConstructorOverloads = new FunctionOverloads(null); } var RetType = (Type)GlobalContainer.CommonIds.Void; if (StructuredType is ClassType) { if ((Mods == null || (Modifiers.GetFlags(Mods) & IdentifierFlags.Static) == 0) && (StructuredType.Flags & (IdentifierFlags.Static | IdentifierFlags.Abstract)) == 0) { RetType = StructuredType; } } var FuncType = new TypeOfFunction(this, DefaultCallConv, RetType, Params); var Func = new Constructor(this, FuncType, ConstructorOverloads, Declaration); if (!AdjustAndDeclareFunction(Func, Mods)) { return(null); } return(Func); }
public Function(IdContainer Container, CodeString Name, TypeOfFunction Type, FunctionOverloads Overload) : base(Container, Name) { this.Overload = Overload; this.Children = new Identifier[] { Type }; this.DeclaredIdType = DeclaredIdType.Function; }
public FunctionScope(IdContainer Parent, Function Function, CodeString Code) : base(Parent, Code) { this.Function = Function; this.FunctionScope = this; this.Type = Function.TypeOfSelf.RealId as TypeOfFunction; this.ReturnLabel = State.AutoLabel; }
public override Function OnCreateFunction(CodeString Name, TypeOfFunction FuncType, FunctionOverloads Overload, List <Modifier> Mods = null) { if (Mods != null && (Modifiers.GetFlags(Mods) & IdentifierFlags.Static) != 0) { return(new Function(this, Name, FuncType, Overload)); } else { return(new MemberFunction(this, Name, FuncType, Overload)); } }
public Function CreateAndDeclareFunction(CodeString Name, TypeOfFunction Type, List <Modifier> Mods = null) { var Func = CreateFunction(Name, Type, Mods); if (Func == null) { return(null); } if (!DeclareIdentifier(Func)) { return(null); } return(Func); }
public Function CreateFunction(CodeString Name, TypeOfFunction FuncType, List <Modifier> Mods = null) { var Overload = GetOverload(Name.ToString()); var Ret = OnCreateFunction(Name, FuncType, Overload, Mods); if (Ret == null) { return(null); } if (!AdjustFunction(Ret, Mods)) { return(null); } return(Ret); }
public Function CreateFunction(CodeString Name, CodeString SRetType, FunctionParameter[] Params, List <Modifier> Mods = null) { var RetType = RecognizeIdentifier(SRetType, GetIdOptions.DefaultForType); if (RetType == null) { return(null); } if (RetType.RealId is AutomaticType) { State.Messages.Add(MessageId.VarFuncRetType, SRetType); return(null); } var FuncType = new TypeOfFunction(this, DefaultCallConv, RetType, Params); return(CreateFunction(Name, FuncType, Mods)); }
public Function CreateGetter(CodeString Declaration, CodeString Code, IdentifierAccess Access = IdentifierAccess.Public) { var Children = new Identifier[Property.Children.Length]; for (var i = 0; i < Property.Children.Length; i++) { Children[i] = Property.Children[i]; } var Type = new TypeOfFunction(this, DefaultCallConv, Children); var Ret = CreateFunctionForAccessor("get", Declaration, Type, Access); if (Ret == null || !CreateScopeForAccessor(Ret, Code)) { return(null); } Getter = Ret; return(Ret); }
public Function CreateDeclaredFunctionAndScope(CodeString Name, TypeOfFunction Type, CodeString Inner, List <Modifier> Mods = null) { var Func = CreateAndDeclareFunction(Name, Type, Mods); if (Func == null) { return(null); } if (Func.HasCode) { Func.FunctionScope = new FunctionScope(this, Func, Inner); if (!Func.FunctionScope.Initialize()) { return(null); } } return(Func); }
Function CreateFunctionForAccessor(string Name, CodeString Declaration, TypeOfFunction Type, IdentifierAccess Access) { if (Identifiers.IsLessRestrictive(Access, Property.Access)) { State.Messages.Add(MessageId.PropertyAccessLevel, Name); return(null); } Function Ret; if (!(Parent is StructuredScope) || (Property.Flags & IdentifierFlags.Static) != 0) { Ret = new Function(this, new CodeString(Name), Type, null); } else { Ret = new MemberFunction(this, new CodeString(Name), Type, null); } Ret.Flags = Property.Flags; Ret.Access = Access; Ret.Declaration = Declaration; return(Ret); }
public override Function OnCreateFunction(CodeString Name, TypeOfFunction FuncType, FunctionOverloads Overload, List <Modifier> Mods = null) { throw new ApplicationException(); }
public virtual Function OnCreateFunction(CodeString Name, TypeOfFunction FuncType, FunctionOverloads Overload = null, List <Modifier> Mods = null) { return(new Function(this, Name, FuncType, Overload)); }
public bool CreateAssemblyEntry() { var Name = new CodeString(OutputAssembly.DescName + "_AssemblyEntry"); var FuncTypeCh = new Identifier[] { CommonIds.Void }; var FuncType = new TypeOfFunction(this, CallingConvention.ZinniaCall, FuncTypeCh); var Func = GlobalNamespaceScope.CreateDeclaredFunctionAndScope(Name, FuncType, new CodeString()); if (Func == null) { return(false); } var FS = Func.FunctionScope; FS.Flags &= ~FunctionScopeFlags.DisableParsing; AssemblyEntry = Func; //-------------------------------------------------------------------------------------- var Plugin = FS.GetPlugin(); #warning WARNING if ((Flags & GlobalContainerFlags.HasUninitedValues) != 0 || true) { if (!Plugin.Begin()) { return(false); } var ZeroMemFuncOptions = GetIdOptions.Default; ZeroMemFuncOptions.OverloadData.Specified = true; ZeroMemFuncOptions.OverloadData.Unnamed = new List <Identifier>() { CommonIds.VoidPtr, CommonIds.UIntPtr }; var ZeroMemFunc = Identifiers.GetFromMembers(GlobalNamespace, new CodeString("System.Memory.Zero"), ZeroMemFuncOptions); if (ZeroMemFunc == null) { return(false); } var ZeroMemFuncNode = Plugin.NewNode(new IdExpressionNode(ZeroMemFunc, Name)); var ZeroMemAddress = Plugin.NewNode(new LabelExpressionNode(Name, "_%UninitedValues_Begin")); var ZeroMemSizeTypeNode = Plugin.NewNode(new IdExpressionNode(CommonIds.UIntPtr, Name)); if (ZeroMemFuncNode == null || ZeroMemAddress == null || ZeroMemSizeTypeNode == null) { return(false); } var ZeroMemSizeString = "_%UninitedValues_End - _%UninitedValues_Begin"; var ZeroMemSizeCh0 = Plugin.NewNode(new LabelExpressionNode(Name, ZeroMemSizeString)); if (ZeroMemSizeCh0 == null) { return(false); } var ZeroMemSizeCastCh = new ExpressionNode[] { ZeroMemSizeCh0, ZeroMemSizeTypeNode }; var ZeroMemSize = Plugin.NewNode(new OpExpressionNode(Operator.Cast, ZeroMemSizeCastCh, Name)); if (ZeroMemSize == null) { return(false); } var ZeroMemCh = new ExpressionNode[] { ZeroMemFuncNode, ZeroMemAddress, ZeroMemSize }; var ZeroMem = Plugin.NewNode(new OpExpressionNode(Operator.Call, ZeroMemCh, Name)); if (ZeroMem == null || Plugin.End(ref ZeroMem) == PluginResult.Failed) { return(false); } var ZeroMemComm = new Command(FS, Name, CommandType.Expression); ZeroMemComm.Expressions = new List <ExpressionNode>() { ZeroMem }; FS.Children.Add(ZeroMemComm); } //-------------------------------------------------------------------------------------- for (var i = 0; i < Children.Count; i++) { var Ch = Children[i] as AssemblyScope; if (Ch.Assembly != OutputAssembly) { continue; } if (!CallStaticConstructors(Ch, FS, Plugin, Name)) { return(false); } } //----------------------------------------------------------------------------- if (State.Entry != null) { var Entry = GetEntryFunction(); if (Entry == null) { return(false); } if (!Plugin.Begin()) { return(false); } var EntryNode = Plugin.NewNode(new IdExpressionNode(Entry, Name)); if (EntryNode == null) { return(false); } var NodeCh = new ExpressionNode[] { EntryNode }; var Node = Plugin.NewNode(new OpExpressionNode(Operator.Call, NodeCh, Name)); if (Node == null || Plugin.End(ref Node) == PluginResult.Failed) { return(false); } var Comm = new Command(FS, Name, CommandType.Expression); Comm.Expressions = new List <ExpressionNode>() { Node }; FS.Children.Add(Comm); } return(true); }
public Destructor(IdContainer Container, TypeOfFunction Type, CodeString Declaration) : base(Container, new CodeString(), Type, null) { this.Declaration = Declaration; this.DeclaredIdType = DeclaredIdType.Destructor; }
public Constructor(IdContainer Container, TypeOfFunction Type, FunctionOverloads Overload, CodeString Declaration) : base(Container, new CodeString(), Type, Overload) { this.Declaration = Declaration; this.DeclaredIdType = DeclaredIdType.Constructor; }
public MemberFunction(IdContainer Container, CodeString Name, TypeOfFunction Type, FunctionOverloads Overload) : base(Container, Name, Type, Overload) { }
void ReadReference(LoaderReference Ref) { var NonDeclared = (UndeclaredIdType)Reader.ReadByte(); if (NonDeclared == UndeclaredIdType.Unknown) { ReadReferenceDeclared(Ref); return; } Identifier NewId; var Container = Ref.DstId.Container; if (NonDeclared == UndeclaredIdType.RefArrayType) { var Arr = new RefArrayType(Container, null, 0, false); ReadReference(Arr, ReferenceDestination.Children, 0); UpdateList.Add(Arr); Arr.Dimensions = ReadLEB128_Int(); NewId = Arr; } else if (NonDeclared == UndeclaredIdType.NonrefArrayType) { var Arr = new NonrefArrayType(Container, null, null, false); ReadReference(Arr, ReferenceDestination.Children, 0); UpdateList.Add(Arr); var Dimensions = ReadLEB128_Int(); if (Dimensions != 0) { var Lengths = new int[Dimensions]; for (var i = 0; i < Dimensions; i++) { Lengths[i] = ReadLEB128_Int(); } Arr.Lengths = Lengths; Arr.Dimensions = Dimensions; } NewId = Arr; } else if (NonDeclared == UndeclaredIdType.Pointer) { NewId = new PointerType(Container, null, false); ReadReference(NewId, ReferenceDestination.Children, 0); UpdateList.Add(NewId); } else if (NonDeclared == UndeclaredIdType.Reference) { var Mode = (ReferenceMode)Reader.ReadByte(); NewId = new ReferenceType(Container, null, Mode, false); ReadReference(NewId, ReferenceDestination.Children, 0); UpdateList.Add(NewId); } else if (NonDeclared == UndeclaredIdType.Tuple) { var Tuple = new TupleType(Container, (List <Identifier>)null); Tuple.InstanceSize = ReadLEB128_Int(); if (Tuple.InstanceSize <= 0) { throw new InvalidAssemblyException("Invalid size"); } Tuple.Size = Tuple.InstanceSize; Tuple.Align = ReadLEB128_Int(); Tuple.LayoutCalculated = true; if (!DataStoring.VerifyAlign(Tuple.Align)) { throw new InvalidAssemblyException("Invalid alignment"); } var Named = Reader.ReadBoolean(); var MemberCount = ReadLEB128_Int(); for (var i = 0; i < MemberCount; i++) { var Name = Named ? new CodeString(ReadLEB128_String()) : new CodeString(); var MemberVar = new MemberVariable(Tuple.StructuredScope, Name, null); MemberVar.Access = IdentifierAccess.Public; ReadReference(MemberVar, ReferenceDestination.Children, 0); MemberVar.Offset = ReadLEB128_Int(); Tuple.StructuredScope.IdentifierList.Add(MemberVar); } UpdateList.Add(Tuple); NewId = Tuple; } else if (NonDeclared == UndeclaredIdType.PointerAndLength) { var PAndL = new PointerAndLength(Container, null, false); ReadReference(PAndL.PointerType, ReferenceDestination.Children, 0); UpdateList.Add(PAndL); NewId = PAndL; } else if (NonDeclared == UndeclaredIdType.NonstaticFunctionType) { var FType = new NonstaticFunctionType(Container, null, false); ReadReference(FType, ReferenceDestination.Children, 0); UpdateList.Add(FType); NewId = FType; } else if (NonDeclared == UndeclaredIdType.Function) { var Conv = (CallingConvention)Reader.ReadByte(); NewId = new TypeOfFunction(Container, Conv, new Identifier[1], false); ReadReference(NewId, ReferenceDestination.Children, 0); ReadParameterReferences(NewId); UpdateList.Add(NewId); } else { NewId = Global.CommonIds.GetIdentifier(NonDeclared); if (NewId == null) { throw new InvalidAssemblyException(); } } SetReferencedId(Ref, NewId); }