コード例 #1
0
ファイル: Structures.cs プロジェクト: bencz/Zinnia-lang
        public List <IdentifierFound> SearchBase(IdContainer Container, string Name, Predicate <Identifier> Func = null)
        {
            var Out = new List <IdentifierFound>();

            SearchBase(Container, Name, Out, Func);
            return(Out);
        }
コード例 #2
0
        public static VarDeclarationList Create(IdContainer Container, CodeString Code, List <Modifier> DefaultModifiers = null,
                                                VarDeclarationListFlags Flags = VarDeclarationListFlags.Default)
        {
            var Ret = new VarDeclarationList(DefaultModifiers);
            var Rec = Container.State.Language.VarDeclRecognizer;

            if (Rec != null)
            {
                var EnableMessages = (Flags & VarDeclarationListFlags.EnableMessages) != 0;
                if (!Rec.Recognize(Container, Code, EnableMessages, Ret))
                {
                    return(null);
                }
                if (!Ret.Process(Container, Flags))
                {
                    return(null);
                }
            }
            else
            {
                throw new ApplicationException("A variable declaration recognizer is not avaiable");
            }

            return(Ret);
        }
コード例 #3
0
        static bool CreateAndDeclareRecursively(IdContainer Container, TypeDeclarationList Out)
        {
            var RetValue = true;
            var State    = Container.State;
            var Scope    = Container as NonCodeScope;

            if (Scope != null && Scope.Code.IsValid)
            {
                var NewList = new TypeDeclarationList();
                var Rec     = State.Language.TypeDeclRecognizer;
                if (!Rec.Recognize(Scope, NewList) || !NewList.Declare())
                {
                    RetValue = false;
                }

                Out.AddRange(NewList);
            }

            for (var i = 0; i < Container.Children.Count; i++)
            {
                var e = Container.Children[i];
                if (!CreateAndDeclareRecursively(e, Out))
                {
                    RetValue = false;
                }
            }

            return(RetValue);
        }
コード例 #4
0
ファイル: GlobalContainer.cs プロジェクト: bencz/Zinnia-lang
        static bool ProcessStructureIdentifiers(IdContainer Container)
        {
            var RetValue = true;

            if (Container.IsNotLoadedAssemblyScope())
            {
                if (Container is StructuredScope)
                {
                    var Scope = Container as StructuredScope;
                    if (!Scope.ProcessIdentifiers())
                    {
                        RetValue = false;
                    }
                }

                for (var i = 0; i < Container.Children.Count; i++)
                {
                    if (!ProcessStructureIdentifiers(Container.Children[i]))
                    {
                        RetValue = false;
                    }
                }
            }

            return(RetValue);
        }
コード例 #5
0
ファイル: CodeChecker.cs プロジェクト: bencz/Zinnia-lang
        public OnEnterLeaveResult Jump(IdContainer JumpTo, JumpMode Mode = JumpMode.Enter)
        {
            var Common  = Container.GetCommonContainer(JumpTo);
            var TryComm = Container.GetParent <Command>(x =>
                                                        x.Type == CommandType.Try && x.FinallyScope != null, Common);

            if (TryComm != null)
            {
                Container   = TryComm.FinallyScope;
                FinallyJump = new JumpDestination(JumpTo, Mode);
                return(OnEnterLeaveResult.EnterNew);
            }
            else
            {
                Container = JumpTo;
                if (Mode == JumpMode.Enter)
                {
                    return(OnEnterLeaveResult.EnterNew);
                }
                else if (Mode == JumpMode.Leave)
                {
                    return(OnEnterLeaveResult.LeaveNew);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Mode");
                }
            }
        }
コード例 #6
0
ファイル: Structures.cs プロジェクト: bencz/Zinnia-lang
        public void SearchBase(IdContainer Container, string Name, List <IdentifierFound> Out, Predicate <Identifier> Func = null)
        {
            for (var i = 0; i < BaseStructures.Length; i++)
            {
                if (Name == null || BaseStructures[i].Name.IsEqual(Name))
                {
                    if (Func == null || Func(BaseStructures[i].Base))
                    {
                        Out.Add(new IdentifierFound(Container, BaseStructures[i].Base));
                    }
                }
            }

            if (Out.Count == 0)
            {
                for (var i = 0; i < BaseStructures.Length; i++)
                {
                    var BaseId    = BaseStructures[i].Base;
                    var Structure = BaseId.UnderlyingStructureOrRealId as StructuredType;
                    if (Structure != null)
                    {
                        Structure.SearchBase(Container, Name, Out, Func);
                    }
                }
            }
        }
コード例 #7
0
 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;
 }
コード例 #8
0
        public bool RecognizeRecursively(IdContainer Container)
        {
            var RetValue = true;
            var State    = Container.State;
            var Scope    = Container as NonCodeScope;

            if (State.Language.AliasDeclRecognizer == null)
            {
                return(true);
            }

            if (Scope != null && Scope.Code.IsValid)
            {
                if (!State.Language.AliasDeclRecognizer.Recognize(Scope, this))
                {
                    RetValue = false;
                }
            }

            for (var i = 0; i < Container.Children.Count; i++)
            {
                if (!RecognizeRecursively(Container.Children[i]))
                {
                    RetValue = false;
                }
            }

            return(RetValue);
        }
コード例 #9
0
ファイル: Structures.cs プロジェクト: bencz/Zinnia-lang
        public NonstaticFunctionType(IdContainer Container, Identifier Child, bool DoUpdate = true)
            : base(Container, new CodeString(), true)
        {
            Children = new Identifier[1] {
                Child
            };
            if (Child != null && !(Child is TypeOfFunction))
            {
                throw new ArgumentException(null, "Child");
            }

            this.UndeclaredIdType = UndeclaredIdType.NonstaticFunctionType;
            var Scope = new StructuredScope(Container, new CodeString(), this);

            StructuredScope = Scope;

            var SelfType = Container.GlobalContainer.CommonIds.Object;
            var Self     = new MemberVariable(Scope, new CodeString("Self"), SelfType);

            Self.Access = IdentifierAccess.Public;
            Scope.IdentifierList.Add(Self);

            var PointerType = Container.GlobalContainer.CommonIds.VoidPtr;
            var Pointer     = new MemberVariable(Scope, new CodeString("Pointer"), PointerType);

            Pointer.Access = IdentifierAccess.Public;
            Scope.IdentifierList.Add(Pointer);

            if (DoUpdate)
            {
                Update();
            }
        }
コード例 #10
0
ファイル: IdContainer.cs プロジェクト: bencz/Zinnia-lang
        public IdContainer(IdContainer Parent)
        {
            this.Parent = Parent;

            if (Parent == null)
            {
                if (!(this is GlobalContainer))
                {
                    throw new ArgumentNullException("Parent");
                }
            }
            else
            {
                if (State == null)
                {
                    State = Parent.State;
                }
                if (FunctionScope == null)
                {
                    FunctionScope = Parent.FunctionScope;
                }

                if (FunctionScope != null)
                {
                    LocalIndex = FunctionScope.ContainerLocalIndexCount;
                    FunctionScope.ContainerLocalIndexCount++;
                }
            }
        }
コード例 #11
0
        static bool CreateAndDeclareRecursively(IdContainer Container, ConstDeclarationList Out)
        {
            var RetValue = true;
            var State    = Container.State;
            var Scope    = Container as NonCodeScope;

            if (Scope != null && Scope.Code.IsValid)
            {
                if (!State.Language.ConstDeclRecognizer.Recognize(Scope, Out))
                {
                    RetValue = false;
                }
            }

            for (var i = 0; i < Container.Children.Count; i++)
            {
                var e = Container.Children[i];
                if (!CreateAndDeclareRecursively(e, Out))
                {
                    RetValue = false;
                }
            }

            return(RetValue);
        }
コード例 #12
0
ファイル: Structures.cs プロジェクト: bencz/Zinnia-lang
        public PointerAndLength(IdContainer Container, Identifier Child, bool DoUpdate = true)
            : base(Container, new CodeString(), true)
        {
            this.UndeclaredIdType = UndeclaredIdType.PointerAndLength;
            var Scope = new StructuredScope(Container, new CodeString(), this);

            StructuredScope = Scope;

            var PointerType = new PointerType(Container, Child, DoUpdate);
            var Pointer     = new MemberVariable(Scope, new CodeString("Pointer"), PointerType);

            Pointer.Access = IdentifierAccess.Public;
            Scope.IdentifierList.Add(Pointer);

            var LengthType = Container.GlobalContainer.CommonIds.UIntPtr;
            var Length     = new MemberVariable(Scope, new CodeString("Length"), LengthType);

            Length.Access = IdentifierAccess.Public;
            Scope.IdentifierList.Add(Length);

            if (DoUpdate)
            {
                Update();
            }
        }
コード例 #13
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
        public UnsignedType(IdContainer Container, CodeString Name, int Size)
            : base(Container, Name, Size)
        {
            MaxValue = BigInteger.Pow(2, Size * 8) - 1;
            MinValue = new BigInteger(0);

            if (Size == 1)
            {
                UndeclaredIdType = UndeclaredIdType.Byte;
            }
            else if (Size == 2)
            {
                UndeclaredIdType = UndeclaredIdType.UInt16;
            }
            else if (Size == 4)
            {
                UndeclaredIdType = UndeclaredIdType.UInt32;
            }
            else if (Size == 8)
            {
                UndeclaredIdType = UndeclaredIdType.UInt64;
            }
            else
            {
                throw new ApplicationException();
            }
        }
コード例 #14
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
        public TypeOfFunction(IdContainer Container, CallingConvention Conv, Identifier RetType,
                              FunctionParameter[] Params, bool Calc = true) : base(Container, new CodeString())
        {
            if (Conv == CallingConvention.Unknown)
            {
                throw new ApplicationException();
            }

            if (Params != null)
            {
                Children    = new Identifier[Params.Length + 1];
                Children[0] = RetType;
                Params.CopyTo(Children, 1);
            }
            else
            {
                Children = new Identifier[] { RetType };
            }

            this.UndeclaredIdType = UndeclaredIdType.Function;
            this.Size             = Container.State.Arch.RegSize;
            this.Align            = this.Size;
            this.CallConv         = Conv;
            if (Calc)
            {
                Update();
            }
        }
コード例 #15
0
ファイル: Modifiers.cs プロジェクト: bencz/Zinnia-lang
        public static List <Modifier> Recognize(IdContainer Container, ref CodeString Code)
        {
            var Out  = new List <Modifier>();
            var Lang = Container.State.Language;

            if (Lang.ModRecognizers != null)
            {
                var Recs = Lang.ModRecognizers;
                CustomRecognize(ref Code, (ref CodeString xCode) =>
                {
                    for (var i = 0; i < Recs.Length; i++)
                    {
                        var Res = Recs[i].Recognize(Container, ref xCode, Out);
                        if (Res != SimpleRecResult.Unknown)
                        {
                            return(Res);
                        }
                    }

                    return(SimpleRecResult.Unknown);
                });
            }

            return(Out);
        }
コード例 #16
0
ファイル: GlobalContainer.cs プロジェクト: bencz/Zinnia-lang
        static bool ProcessScopes(IdContainer Container, List <Identifier> Out)
        {
            var RetValue = true;

            if (Container.IsNotLoadedAssemblyScope())
            {
                if (Container is NonCodeScope)
                {
                    var Scope = Container as NonCodeScope;
                    if (!Scope.ProcessScope())
                    {
                        RetValue = false;
                    }

                    if (Scope is IdentifierScope)
                    {
                        var IdScope = Scope as IdentifierScope;
                        Out.Add(IdScope.Identifier);
                    }

                    Scope.GetMTProcIds(Out);
                }

                for (var i = 0; i < Container.Children.Count; i++)
                {
                    if (!ProcessScopes(Container.Children[i], Out))
                    {
                        RetValue = false;
                    }
                }
            }

            return(RetValue);
        }
コード例 #17
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
 public EnumType(IdContainer Container, CodeString Name, CodeString Str_TypeOfValues)
     : base(Container, Name)
 {
     this.Str_TypeOfValues = Str_TypeOfValues;
     this.ConstValueType   = ConstValueType.Integer;
     this.DeclaredIdType   = DeclaredIdType.Enum;
     this.Children         = new Identifier[] { null };
 }
コード例 #18
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
 public CharType(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.Size             = 2;
     this.Align            = 2;
     this.ConstValueType   = ConstValueType.Char;
     this.UndeclaredIdType = UndeclaredIdType.Char;
 }
コード例 #19
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
 public StringType(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.UndeclaredIdType = UndeclaredIdType.String;
     this.TypeFlags       |= TypeFlags.ReferenceValue;
     this.ConstValueType   = ConstValueType.String;
     this.Size             = this.Align = Container.State.Arch.RegSize;
 }
コード例 #20
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
 public EnumType(IdContainer Container, CodeString Name, Identifier TypeOfValues)
     : base(Container, Name)
 {
     this.Children       = new Identifier[] { TypeOfValues };
     this.ConstValueType = ConstValueType.Integer;
     this.DeclaredIdType = DeclaredIdType.Enum;
     Update();
 }
コード例 #21
0
ファイル: Types.cs プロジェクト: bencz/Zinnia-lang
 public BooleanType(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.Size             = 1;
     this.Align            = 1;
     this.ConstValueType   = ConstValueType.Boolean;
     this.UndeclaredIdType = UndeclaredIdType.Boolean;
 }
コード例 #22
0
 public Property ToProperty(IdContainer Container)
 {
     if (!CheckName(Container.State))
     {
         return(null);
     }
     return(Container.CreateProperty(Name, Type, null, Modifiers));
 }
コード例 #23
0
ファイル: CodeChecker.cs プロジェクト: bencz/Zinnia-lang
        public CodeContext Copy(IdContainer Container)
        {
            var Ret = Copy();

            Ret.Container = Container;
            Ret.Flags     = Flags;
            return(Ret);
        }
コード例 #24
0
ファイル: Structures.cs プロジェクト: bencz/Zinnia-lang
 public TupleType(IdContainer Container, StructuredScope StructuredTypeScope)
     : base(Container, new CodeString())
 {
     this.UndeclaredIdType = UndeclaredIdType.Tuple;
     this.DeclaredIdType   = DeclaredIdType.Unknown;
     this.StructuredScope  = StructuredTypeScope;
     Update();
 }
コード例 #25
0
 public AliasDeclaration(IdContainer Container, CodeString NewName, CodeString OldName,
                         List <Modifier> Mods = null)
 {
     this.Container = Container;
     this.NewName   = NewName;
     this.OldName   = OldName;
     this.Mods      = Mods;
 }
コード例 #26
0
ファイル: Structures.cs プロジェクト: bencz/Zinnia-lang
        public TupleType(IdContainer Container, CodeString Name, bool Named)
            : base(Container, Name)
        {
            this.UndeclaredIdType = UndeclaredIdType.Tuple;
            this.DeclaredIdType   = DeclaredIdType.Unknown;
            this.Named            = Named;

            this.BaseStructures = new StructureBase[0];
        }
コード例 #27
0
ファイル: FunctionScope.cs プロジェクト: bencz/Zinnia-lang
        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;
        }
コード例 #28
0
        public BaseVariable(IdContainer Container, Identifier Type)
            : base(Container, new CodeString(), Type)
        {
            var Lang = Container.State.Language;

            Name        = new CodeString(Lang.CodeProcessor.BaseName);
            Flags      |= IdentifierFlags.ReadOnly;
            PreAssigned = true;
        }
コード例 #29
0
 public FunctionParameter(IdContainer Container, CodeString Name, Identifier Type)
     : base(Container, Name, Type)
 {
     DeclaredIdType = DeclaredIdType.Unknown;
     if (Type != null)
     {
         Access = Type.Access;
     }
 }
コード例 #30
0
ファイル: IdContainer.cs プロジェクト: bencz/Zinnia-lang
 public void ReplaceChild(IdContainer From, IdContainer To)
 {
     for (var i = 0; i < Children.Count; i++)
     {
         if (Children[i] == From)
         {
             Children[i] = To;
         }
     }
 }