Ejemplo n.º 1
0
        public List <IdentifierFound> SearchBase(IdContainer Container, string Name, Predicate <Identifier> Func = null)
        {
            var Out = new List <IdentifierFound>();

            SearchBase(Container, Name, Out, Func);
            return(Out);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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");
                }
            }
        }
Ejemplo n.º 6
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 9
0
        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();
            }
        }
Ejemplo n.º 10
0
        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++;
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
0
        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();
            }
        }
Ejemplo n.º 13
0
        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();
            }
        }
Ejemplo n.º 14
0
        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();
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 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 };
 }
Ejemplo n.º 18
0
 public CharType(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.Size             = 2;
     this.Align            = 2;
     this.ConstValueType   = ConstValueType.Char;
     this.UndeclaredIdType = UndeclaredIdType.Char;
 }
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
 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();
 }
Ejemplo n.º 21
0
 public BooleanType(IdContainer Container, CodeString Name)
     : base(Container, Name)
 {
     this.Size             = 1;
     this.Align            = 1;
     this.ConstValueType   = ConstValueType.Boolean;
     this.UndeclaredIdType = UndeclaredIdType.Boolean;
 }
Ejemplo n.º 22
0
 public Property ToProperty(IdContainer Container)
 {
     if (!CheckName(Container.State))
     {
         return(null);
     }
     return(Container.CreateProperty(Name, Type, null, Modifiers));
 }
Ejemplo n.º 23
0
        public CodeContext Copy(IdContainer Container)
        {
            var Ret = Copy();

            Ret.Container = Container;
            Ret.Flags     = Flags;
            return(Ret);
        }
Ejemplo n.º 24
0
 public TupleType(IdContainer Container, StructuredScope StructuredTypeScope)
     : base(Container, new CodeString())
 {
     this.UndeclaredIdType = UndeclaredIdType.Tuple;
     this.DeclaredIdType   = DeclaredIdType.Unknown;
     this.StructuredScope  = StructuredTypeScope;
     Update();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 26
0
        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];
        }
Ejemplo n.º 27
0
        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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 29
0
 public FunctionParameter(IdContainer Container, CodeString Name, Identifier Type)
     : base(Container, Name, Type)
 {
     DeclaredIdType = DeclaredIdType.Unknown;
     if (Type != null)
     {
         Access = Type.Access;
     }
 }
Ejemplo n.º 30
0
 public void ReplaceChild(IdContainer From, IdContainer To)
 {
     for (var i = 0; i < Children.Count; i++)
     {
         if (Children[i] == From)
         {
             Children[i] = To;
         }
     }
 }