Beispiel #1
0
        public Variable ToVariable(IdContainer Container, bool Declare = false)
        {
            if (!CheckName(Container.State))
            {
                return(null);
            }

            var Ret = Container.CreateVariable(Name, Type, Modifiers);

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

            if (Declare && !Container.DeclareIdentifier(Ret))
            {
                return(null);
            }

            Ret.InitString = InitString;
            return(Ret);
        }
Beispiel #2
0
        public SimpleRecResult Declare()
        {
            var Options = new GetIdOptions(GetIdMode.Everywhere, false);
            var Id      = Container.RecognizeIdentifier(OldName, Options);

            if (Id == null)
            {
                return(SimpleRecResult.Unknown);
            }

            var Alias = new IdentifierAlias(Container, NewName, Id);

            if (Mods != null && !Modifiers.Apply(Mods, Alias))
            {
                return(SimpleRecResult.Failed);
            }

            if (!Container.DeclareIdentifier(Alias))
            {
                return(SimpleRecResult.Failed);
            }

            return(SimpleRecResult.Succeeded);
        }
Beispiel #3
0
        public SimpleRecResult Declare()
        {
            var State = Container.State;
            var Arch  = State.Arch;

            //------------------------------------------------------------------
            if (Type == TypeDeclType.Struct || Type == TypeDeclType.Class)
            {
                var NewType = (StructuredType)null;
                if (Type == TypeDeclType.Struct)
                {
                    NewType = new StructType(Container, Name);

                    if (Bases.Length > 0)
                    {
                        for (var i = 0; i < Bases.Length; i++)
                        {
                            State.Messages.Add(MessageId.CannotInherit, Bases[i].Name);
                        }

                        return(SimpleRecResult.Failed);
                    }
                }
                else
                {
                    NewType = new ClassType(Container, Name);
                }

                if (!Modifiers.Apply(Mods, NewType))
                {
                    return(SimpleRecResult.Failed);
                }
                if (!Container.DeclareIdentifier(NewType))
                {
                    return(SimpleRecResult.Failed);
                }

                NewType.BaseStructures  = Bases;
                NewType.StructuredScope = new StructuredScope(Container, Inner, NewType);
                Container.Children.Add(NewType.StructuredScope);
                DeclaredType = NewType;
                return(SimpleRecResult.Succeeded);
            }

            //------------------------------------------------------------------
            else if (Type == TypeDeclType.Enum || Type == TypeDeclType.Flag)
            {
                var NewType = (EnumType)null;
                if (Bases.Length == 1)
                {
                    if (Type == TypeDeclType.Flag)
                    {
                        NewType = new FlagType(Container, Name, Bases[0].Name);
                    }
                    else
                    {
                        NewType = new EnumType(Container, Name, Bases[0].Name);
                    }

                    if (Bases[0].Base != null)
                    {
                        NewType.Children[0] = Bases[0].Base;
                    }

                    if (Bases[0].Flags != StructureBaseFlags.None)
                    {
                        State.Messages.Add(MessageId.NotExpected, Bases[0].Declaration);
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Bases.Length > 1)
                {
                    for (var i = 1; i < Bases.Length; i++)
                    {
                        State.Messages.Add(MessageId.NotExpected, Bases[i].Declaration);
                    }

                    return(SimpleRecResult.Failed);
                }
                else
                {
                    if (Type == TypeDeclType.Flag)
                    {
                        NewType = new FlagType(Container, Name, new CodeString());
                    }
                    else
                    {
                        NewType = new EnumType(Container, Name, new CodeString());
                    }
                }

                if (!Modifiers.Apply(Mods, NewType))
                {
                    return(SimpleRecResult.Failed);
                }
                if (!Container.DeclareIdentifier(NewType))
                {
                    return(SimpleRecResult.Failed);
                }

                NewType.EnumScope = new EnumScope(Container, Inner, NewType);
                Container.Children.Add(NewType.EnumScope);
                DeclaredType = NewType;
                return(SimpleRecResult.Succeeded);
            }

            //------------------------------------------------------------------
            else
            {
                throw new ApplicationException();
            }
        }