Beispiel #1
0
 public Type(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.Name = Name;
 }
Beispiel #2
0
 public virtual Function OnCreateFunction(CodeString Name, TypeOfFunction FuncType,
                                          FunctionOverloads Overload = null, List <Modifier> Mods = null)
 {
     return(new Function(this, Name, FuncType, Overload));
 }
Beispiel #3
0
 public StructuredType(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
 }
Beispiel #4
0
        public ExpressionNode DeclareVarAndCreateIdNode(CodeString Code, Identifier Type, CodeString Name)
        {
            var Var = CreateAndDeclareVar(Type, Name);

            if (Var == null)
            {
                return(null);
            }

            return(NewNode(new IdExpressionNode(Var, Code, ExpressionFlags.IdMustBeAssigned)));
        }
Beispiel #5
0
 public Identifier RecognizeIdentifier(CodeString Code)
 {
     return(Identifiers.Recognize(this, Code));
 }
Beispiel #6
0
        static bool CopyCatchVar(Command TryComm, CodeScopeNode Scope, Identifier Type, CodeString Name, CodeString Code)
        {
            var CatchVar = GetOrCreateCatchVariable(TryComm);
            var NewVar   = Scope.CreateAndDeclareVariable(Name, Type);

            if (NewVar == null || CatchVar == null)
            {
                return(false);
            }

            return(CopyCatchVar(Scope, CatchVar, NewVar, Code));
        }
Beispiel #7
0
        public static CodeScopeNode CreateCatchScope(Command TryComm, CodeString CommandCode, CodeString Inner,
                                                     Identifier Type = null, CodeString Name = new CodeString())
        {
            var State = TryComm.State;

            if ((TryComm.Flags & CommandFlags.CatchesAllException) != 0)
            {
                State.Messages.Add(MessageId.CatchesAllException, CommandCode);
                return(null);
            }

            if (TryComm.CatchScope == null)
            {
                CreateRootCatchScope(TryComm);
            }

            var ExceptionClass = Identifiers.GetByFullNameFast <ClassType>(State, "System.Exception");

            if (ExceptionClass == null)
            {
                throw new ApplicationException();
            }

            if (Type == null || Type.IsEquivalent(ExceptionClass))
            {
                TryComm.Flags |= CommandFlags.CatchesAllException;
                if (TryComm.CatchScope.Children.Count == 0)
                {
                    if ((TryComm.Flags & CommandFlags.TryHasCatchVariable) != 0)
                    {
                        throw new ApplicationException();
                    }

                    if (Type != null && !CreateCatchVariable(TryComm, Type, Name))
                    {
                        return(null);
                    }

                    TryComm.CatchScope.Code = Inner;
                    return(TryComm.CatchScope);
                }
                else
                {
                    var Cond      = TryComm.CatchScope.Children[0] as Command;
                    var ElseScope = new CodeScopeNode(Cond, Inner);
                    Cond.Children.Add(ElseScope);

                    if (Type != null && !CopyCatchVar(TryComm, ElseScope, Type, Name, CommandCode))
                    {
                        return(null);
                    }

                    return(ElseScope);
                }
            }
            else
            {
                if (!Identifiers.IsSubtypeOf(Type, ExceptionClass))
                {
                    State.Messages.Add(MessageId.CannotBeThisType, Name);
                    return(null);
                }

                Command Cond;
                if (TryComm.CatchScope.Children.Count == 0)
                {
                    Cond             = new Command(TryComm.CatchScope, TryComm.Code, CommandType.If);
                    Cond.Expressions = new List <ExpressionNode>();
                    TryComm.CatchScope.Children.Add(Cond);
                }
                else
                {
                    Cond = TryComm.CatchScope.Children[0] as Command;
                }

                var Condition = CreateCatchCondition(TryComm, Cond, Type, CommandCode);
                if (Condition == null)
                {
                    return(null);
                }

                var ThenScope = new CodeScopeNode(Cond, Inner);
                Cond.Expressions.Add(Condition);
                Cond.Children.Add(ThenScope);

                if (!CopyCatchVar(TryComm, ThenScope, Type, Name, CommandCode))
                {
                    return(null);
                }

                return(ThenScope);
            }
        }
Beispiel #8
0
 public ConstVariable(IdContainer Container, CodeString Name, Identifier Type, ConstValue Value)
     : base(Container, Name, Type)
 {
     this.ConstInitValue = Value;
     this.DeclaredIdType = DeclaredIdType.Constant;
 }
Beispiel #9
0
 public MemberFunction(IdContainer Container, CodeString Name, TypeOfFunction Type,
                       FunctionOverloads Overload)
     : base(Container, Name, Type, Overload)
 {
 }
Beispiel #10
0
 public WithScopeNode(IdContainer Parent, CodeString Code, ExpressionNode Node)
     : base(Parent, Code)
 {
     WithNode = Node;
 }
Beispiel #11
0
 public MemberVariable(IdContainer Container, CodeString Name, Identifier Type)
     : base(Container, Name, Type)
 {
 }
Beispiel #12
0
        private bool ProcessLinkedAssignmentMember(CodeString Code, ref LinkedExprNode LinkedNode,
                                                   out ExpressionNode Dst, out ExpressionNode Src)
        {
            Dst = null;
            Src = null;

            var MemberId = Expressions.GetMemberIdentifier(LinkedNode.Node);

            if (MemberId.RealId is Property)
            {
                if (LinkedNode.Node is IdExpressionNode)
                {
                    Dst = Parent.NewNode(new IdExpressionNode(MemberId, Code));
                    Src = Parent.NewNode(new IdExpressionNode(MemberId, Code));
                    return(Dst != null && Src != null);
                }
                else
                {
                    var LinkedOpNode = LinkedNode.Node as OpExpressionNode;
                    if (LinkedOpNode.Operator != Operator.Member)
                    {
                        throw new ApplicationException();
                    }

                    var NewLinkedNode = new LinkedExprNode(LinkedOpNode.Children[0]);
                    var DstCh         = new ExpressionNode[]
                    {
                        Parent.NewNode(new LinkingNode(NewLinkedNode, Code)),
                        Parent.NewNode(new IdExpressionNode(MemberId, Code)),
                    };

                    if (DstCh[0] == null || DstCh[1] == null)
                    {
                        return(false);
                    }

                    var SrcCh = new ExpressionNode[]
                    {
                        Parent.NewNode(new LinkingNode(NewLinkedNode, Code)),
                        Parent.NewNode(new IdExpressionNode(MemberId, Code)),
                    };

                    if (SrcCh[0] == null || SrcCh[1] == null)
                    {
                        return(false);
                    }

                    Dst        = Parent.NewNode(new OpExpressionNode(Operator.Member, DstCh, Code));
                    Src        = Parent.NewNode(new OpExpressionNode(Operator.Member, SrcCh, Code));
                    LinkedNode = NewLinkedNode;
                    return(Dst != null && Src != null);
                }
            }
            else if (IsClassMemberNode(LinkedNode.Node))
            {
                LinkedNode.Node = LinkedNode.Node.Children[0];

                Dst = Parent.NewNode(new LinkingNode(LinkedNode, Code));
                Src = Parent.NewNode(new LinkingNode(LinkedNode, Code));
                if (Dst == null || Src == null)
                {
                    return(false);
                }

                var MemberIdNode1 = Parent.NewNode(new IdExpressionNode(MemberId, Code));
                var MemberIdNode2 = Parent.NewNode(new IdExpressionNode(MemberId, Code));
                if (MemberIdNode1 == null || MemberIdNode2 == null)
                {
                    return(false);
                }

                var DstCh = new ExpressionNode[] { Dst, MemberIdNode1 };
                var SrcCh = new ExpressionNode[] { Src, MemberIdNode2 };

                Dst = Parent.NewNode(new OpExpressionNode(Operator.Member, DstCh, Code));
                Src = Parent.NewNode(new OpExpressionNode(Operator.Member, SrcCh, Code));
                return(Dst != null && Src != null);
            }
            else
            {
                LinkedNode.Node = Expressions.GetAddress(Parent, LinkedNode.Node, Code);
                if (LinkedNode.Node == null)
                {
                    return(false);
                }

                Dst = Parent.NewNode(new LinkingNode(LinkedNode, Code));
                Src = Parent.NewNode(new LinkingNode(LinkedNode, Code));
                if (Dst == null || Src == null)
                {
                    return(false);
                }

                Dst = Expressions.Indirection(Parent, Dst, Code);
                Src = Expressions.Indirection(Parent, Src, Code);
                return(Dst != null && Src != null);
            }
        }
Beispiel #13
0
 public FlagType(IdContainer Container, CodeString Name, CodeString Str_TypeOfValues)
     : base(Container, Name, Str_TypeOfValues)
 {
     this.Str_TypeOfValues = Str_TypeOfValues;
     this.DeclaredIdType   = DeclaredIdType.Flag;
 }
Beispiel #14
0
 public NonFloatType(IdContainer Container, CodeString Name, int Size)
     : base(Container, Name, Size)
 {
     this.ConstValueType = ConstValueType.Integer;
 }
Beispiel #15
0
        static bool CallStaticConstructors(IdContainer Container, CodeScopeNode Scope, PluginRoot Plugin, CodeString Code)
        {
            for (var i = 0; i < Container.Children.Count; i++)
            {
                if (!CallStaticConstructors(Container.Children[i], Scope, Plugin, Code))
                {
                    return(false);
                }
            }

            for (var i = 0; i < Container.IdentifierList.Count; i++)
            {
                var Ctor = Container.IdentifierList[i] as Constructor;
                if (Ctor == null || (Ctor.Flags & IdentifierFlags.Static) == 0)
                {
                    continue;
                }

                if (!Plugin.Begin())
                {
                    return(false);
                }

                var CtorNode = Plugin.NewNode(new IdExpressionNode(Ctor, Code));
                if (CtorNode == null)
                {
                    Plugin.Reset(); return(false);
                }

                var NodeCh = new ExpressionNode[] { CtorNode };
                var Node   = Plugin.NewNode(new OpExpressionNode(Operator.Call, NodeCh, Code));
                if (Node == null || Plugin.End(ref Node) == PluginResult.Failed)
                {
                    Plugin.Reset(); return(false);
                }

                Scope.Children.Add(new Command(Scope, Code, CommandType.Expression)
                {
                    Expressions = new List <ExpressionNode>()
                    {
                        Node
                    },
                });
            }

            return(true);
        }
Beispiel #16
0
 public Constructor(IdContainer Container, TypeOfFunction Type, FunctionOverloads Overload, CodeString Declaration)
     : base(Container, new CodeString(), Type, Overload)
 {
     this.Declaration    = Declaration;
     this.DeclaredIdType = DeclaredIdType.Constructor;
 }
Beispiel #17
0
        static bool CopyCatchVar(CodeScopeNode Scope, Identifier From, Identifier To, CodeString Code)
        {
            var Plugin = Scope.GetPlugin();

            if (!Plugin.Begin())
            {
                return(false);
            }

            var Ch = new ExpressionNode[]
            {
                Plugin.NewNode(new IdExpressionNode(To, Code)),
                Plugin.NewNode(new IdExpressionNode(From, Code)),
            };

            if (Ch[0] == null || Ch[1] == null)
            {
                return(false);
            }

            if (!To.Children[0].IsEquivalent(From.Children[0]))
            {
                var CastCh1 = Plugin.NewNode(new IdExpressionNode(To.Children[0], Code));
                if (CastCh1 == null)
                {
                    return(false);
                }

                var CastCh = new ExpressionNode[] { Ch[1], CastCh1 };
                Ch[1] = Plugin.NewNode(new OpExpressionNode(Operator.Cast, CastCh, Code));
                if (Ch[1] == null)
                {
                    return(false);
                }
            }

            var Node = Plugin.NewNode(new OpExpressionNode(Operator.Assignment, Ch, Code));

            if (Node == null || Plugin.End(ref Node) == PluginResult.Failed)
            {
                return(false);
            }

            var Comm = new Command(Scope, Code, CommandType.Expression);

            Comm.Expressions = new List <ExpressionNode>()
            {
                Node
            };
            Scope.Children.Add(Comm);
            return(true);
        }
Beispiel #18
0
 public Destructor(IdContainer Container, TypeOfFunction Type, CodeString Declaration)
     : base(Container, new CodeString(), Type, null)
 {
     this.Declaration    = Declaration;
     this.DeclaredIdType = DeclaredIdType.Destructor;
 }
Beispiel #19
0
        static ExpressionNode CreateCatchCondition(Command TryComm, Command Condition, Identifier Type, CodeString Code)
        {
            var CatchVar = GetOrCreateCatchVariable(TryComm);

            if (CatchVar == null)
            {
                return(null);
            }

            var Plugin = Condition.GetPlugin();

            if (!Plugin.Begin())
            {
                return(null);
            }

            var Ch = new ExpressionNode[]
            {
                Plugin.NewNode(new IdExpressionNode(CatchVar, Code)),
                Plugin.NewNode(new IdExpressionNode(Type, Code)),
            };

            var Node = Plugin.NewNode(new OpExpressionNode(Operator.Is, Ch, Code));

            if (Node == null || Plugin.End(ref Node) == PluginResult.Failed)
            {
                return(null);
            }

            return(Node);
        }
Beispiel #20
0
 public Property(IdContainer Container, CodeString Name, Type Type)
     : base(Container, Name)
 {
     this.Children       = new Identifier[] { Type };
     this.DeclaredIdType = DeclaredIdType.Property;
 }
Beispiel #21
0
 public Variable CreateVariable(Identifier Type, CodeString Name)
 {
     return(Container.CreateVariable(Name, Type));
 }
Beispiel #22
0
 public Property(IdContainer Container, CodeString Name, Identifier[] Children)
     : base(Container, Name)
 {
     this.Children       = Children;
     this.DeclaredIdType = DeclaredIdType.Property;
 }
Beispiel #23
0
        public ExpressionNode DeclareVarAndCreateIdNode(CodeString Code, CodeString TypeName, CodeString Name)
        {
            var Type = Container.RecognizeIdentifier(TypeName, GetIdOptions.DefaultForType);

            if (Type == null)
            {
                return(null);
            }

            return(DeclareVarAndCreateIdNode(Code, Type, Name));
        }
Beispiel #24
0
 public Variable(IdContainer Container, CodeString Name, Identifier Type)
     : base(Container, Name)
 {
     this.DeclaredIdType = DeclaredIdType.Variable;
     Children            = new Identifier[] { Type };
 }
Beispiel #25
0
 public Identifier RecognizeIdentifier(CodeString Code, GetIdOptions Options, IList <IIdRecognizer> Recognizers)
 {
     return(Identifiers.Recognize(this, Code, Options, Recognizers));
 }
Beispiel #26
0
 public Namespace(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.DeclaredIdType = DeclaredIdType.Namespace;
     Access = IdentifierAccess.Public;
 }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
 public StructType(IdContainer Container, CodeString Name, Identifier[] Children = null)
     : base(Container, Name)
 {
     this.Children       = Children;
     this.DeclaredIdType = DeclaredIdType.Struct;
 }
Beispiel #30
0
 public NumberType(IdContainer Container, CodeString Name, int Size)
     : base(Container, Name)
 {
     this.Size  = Size;
     this.Align = Size;
 }