示例#1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="groupNode">StateGroupDeclaration</param>
 internal StateGroupDeclaration(IPSharpProgram program, MachineDeclaration machineNode,
                                StateGroupDeclaration groupNode)
     : base(program)
 {
     this.Machine                = machineNode;
     this.Group                  = groupNode;
     this.StateDeclarations      = new List <StateDeclaration>();
     this.StateGroupDeclarations = new List <StateGroupDeclaration>();
 }
示例#2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="groupNode">StateGroupDeclaration</param>
 /// <param name="isStart">Is start state</param>
 /// <param name="isHot">Is hot state</param>
 /// <param name="isCold">Is cold state</param>
 internal StateDeclaration(IPSharpProgram program, MachineDeclaration machineNode,
                           StateGroupDeclaration groupNode, bool isStart, bool isHot, bool isCold)
     : base(program)
 {
     this.Machine = machineNode;
     this.Group   = groupNode;
     this.IsStart = isStart;
     this.IsHot   = isHot;
     this.IsCold  = isCold;
     this.GotoStateTransitions          = new Dictionary <Token, List <Token> >();
     this.PushStateTransitions          = new Dictionary <Token, List <Token> >();
     this.ActionBindings                = new Dictionary <Token, Token>();
     this.TransitionsOnExitActions      = new Dictionary <Token, BlockSyntax>();
     this.ActionHandlers                = new Dictionary <Token, BlockSyntax>();
     this.DeferredEvents                = new HashSet <Token>();
     this.IgnoredEvents                 = new HashSet <Token>();
     this.ResolvedEventIdentifierTokens = new Dictionary <Token, Tuple <List <Token>, int> >();
     this.RewrittenMethods              = new HashSet <QualifiedMethod>();
 }
示例#3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="groupNode">StateGroupDeclaration</param>
 /// <param name="modSet">Modifier set</param>
 internal StateDeclaration(IPSharpProgram program, MachineDeclaration machineNode,
                           StateGroupDeclaration groupNode, ModifierSet modSet)
     : base(program)
 {
     this.Machine                       = machineNode;
     this.Group                         = groupNode;
     this.AccessModifier                = modSet.AccessModifier;
     this.IsStart                       = modSet.IsStart;
     this.IsHot                         = modSet.IsHot;
     this.IsCold                        = modSet.IsCold;
     this.GotoStateTransitions          = new Dictionary <Token, List <Token> >();
     this.PushStateTransitions          = new Dictionary <Token, List <Token> >();
     this.ActionBindings                = new Dictionary <Token, Token>();
     this.TransitionsOnExitActions      = new Dictionary <Token, AnonymousActionHandler>();
     this.ActionHandlers                = new Dictionary <Token, AnonymousActionHandler>();
     this.DeferredEvents                = new HashSet <Token>();
     this.IgnoredEvents                 = new HashSet <Token>();
     this.ResolvedEventIdentifierTokens = new Dictionary <Token, Tuple <List <Token>, int> >();
     this.RewrittenMethods              = new HashSet <QualifiedMethod>();
 }
示例#4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="groupNode">StateGroupDeclaration</param>
 /// <param name="modSet">Modifier set</param>
 internal StateDeclaration(IPSharpProgram program, MachineDeclaration machineNode,
                           StateGroupDeclaration groupNode, ModifierSet modSet)
     : base(program)
 {
     this.Machine                       = machineNode;
     this.Group                         = groupNode;
     this.AccessModifier                = modSet.AccessModifier;
     this.IsStart                       = modSet.IsStart;
     this.IsHot                         = modSet.IsHot;
     this.IsCold                        = modSet.IsCold;
     this.IsAbstract                    = modSet.InheritanceModifier == InheritanceModifier.Abstract;
     this.GotoStateTransitions          = new Dictionary <Token, List <Token> >();
     this.PushStateTransitions          = new Dictionary <Token, List <Token> >();
     this.ActionBindings                = new Dictionary <Token, Token>();
     this.TransitionsOnExitActions      = new Dictionary <Token, AnonymousActionHandler>();
     this.ActionHandlers                = new Dictionary <Token, AnonymousActionHandler>();
     this.DeferredEvents                = new HashSet <Token>();
     this.IgnoredEvents                 = new HashSet <Token>();
     this.ResolvedEventIdentifierTokens = new Dictionary <Token, Tuple <List <Token>, int> >();
     this.RewrittenMethods              = new HashSet <QualifiedMethod>();
     this.isNameofSupported             = base.Program.GetProject().CompilationContext.Configuration.IsRewriteCSharpVersion(6, 0);
 }
示例#5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="groupNode">StateGroupDeclaration</param>
 /// <param name="isStart">Is start state</param>
 /// <param name="isHot">Is hot state</param>
 /// <param name="isCold">Is cold state</param>
 internal StateDeclaration(IPSharpProgram program, MachineDeclaration machineNode,
     StateGroupDeclaration groupNode, bool isStart, bool isHot, bool isCold)
     : base(program)
 {
     this.Machine = machineNode;
     this.Group = groupNode;
     this.IsStart = isStart;
     this.IsHot = isHot;
     this.IsCold = isCold;
     this.GotoStateTransitions = new Dictionary<Token, List<Token>>();
     this.PushStateTransitions = new Dictionary<Token, List<Token>>();
     this.ActionBindings = new Dictionary<Token, Token>();
     this.TransitionsOnExitActions = new Dictionary<Token, BlockSyntax>();
     this.ActionHandlers = new Dictionary<Token, BlockSyntax>();
     this.DeferredEvents = new HashSet<Token>();
     this.IgnoredEvents = new HashSet<Token>();
     this.ResolvedEventIdentifierTokens = new Dictionary<Token, Tuple<List<Token>, int>>();
     this.RewrittenMethods = new HashSet<QualifiedMethod>();
 }
示例#6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="program">Program</param>
 /// <param name="machineNode">MachineDeclarationNode</param>
 /// <param name="groupNode">StateGroupDeclaration</param>
 internal StateGroupDeclaration(IPSharpProgram program, MachineDeclaration machineNode,
     StateGroupDeclaration groupNode)
     : base(program)
 {
     this.Machine = machineNode;
     this.Group = groupNode;
     this.StateDeclarations = new List<StateDeclaration>();
     this.StateGroupDeclarations = new List<StateGroupDeclaration>();
 }
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Containing machine</param>
        /// <param name="groupNode">Containing group</param>
        /// <param name="accMod">Access modifier</param>
        internal void Visit(MachineDeclaration parentNode, StateGroupDeclaration groupNode, AccessModifier accMod)
        {
            var node = new StateGroupDeclaration(base.TokenStream.Program, parentNode, groupNode);
            node.AccessModifier = accMod;
            node.StateGroupKeyword = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected state group identifier.",
                    new List<TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.StateGroupIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                    new List<TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.StateGroupLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraGroupDeclaration(node);

            if (groupNode == null)
            {
                parentNode.StateGroupDeclarations.Add(node);
            }
            else
            {
                groupNode.StateGroupDeclarations.Add(node);
            }

            var stateDeclarations = node.GetAllStateDeclarations();
            if (stateDeclarations.Count == 0)
            {
                throw new ParsingException("A state group must declare at least one state.",
                    new List<TokenType>());
            }
        }
        /// <summary>
        /// Visits the next intra-group declaration.
        /// </summary>
        /// <param name="node">Node</param>
        private void VisitNextPSharpIntraGroupDeclaration(StateGroupDeclaration node)
        {
            bool fixpoint = false;
            while (!fixpoint)
            {
                var token = base.TokenStream.Peek();
                switch (token.Type)
                {
                    case TokenType.WhiteSpace:
                    case TokenType.Comment:
                    case TokenType.NewLine:
                        base.TokenStream.Index++;
                        break;

                    case TokenType.CommentLine:
                    case TokenType.Region:
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        break;

                    case TokenType.CommentStart:
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        break;

                    case TokenType.StartState:
                    case TokenType.HotState:
                    case TokenType.ColdState:
                    case TokenType.StateDecl:
                    case TokenType.StateGroupDecl:
                    case TokenType.Private:
                    case TokenType.Protected:
                    case TokenType.Internal:
                    case TokenType.Public:
                        this.VisitGroupLevelDeclaration(node);
                        base.TokenStream.Index++;
                        break;

                    case TokenType.LeftSquareBracket:
                        base.TokenStream.Index++;
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        new AttributeListVisitor(base.TokenStream).Visit();
                        base.TokenStream.Index++;
                        break;

                    case TokenType.RightCurlyBracket:
                        base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                            TokenType.MachineRightCurlyBracket));
                        node.RightCurlyBracketToken = base.TokenStream.Peek();
                        fixpoint = true;
                        break;

                    default:
                        throw new ParsingException("Unexpected token '" + base.TokenStream.Peek().TextUnit.Text + "'.",
                            new List<TokenType>());
                }

                if (base.TokenStream.Done)
                {
                    throw new ParsingException("Expected \"}\".",
                        new List<TokenType>
                    {
                            TokenType.Private,
                            TokenType.Protected,
                            TokenType.StartState,
                            TokenType.HotState,
                            TokenType.ColdState,
                            TokenType.StateDecl,
                            TokenType.StateGroupDecl,
                            TokenType.LeftSquareBracket,
                            TokenType.RightCurlyBracket
                    });
                }
            }
        }
        /// <summary>
        /// Visits a group level declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        private void VisitGroupLevelDeclaration(StateGroupDeclaration parentNode)
        {
            AccessModifier am = AccessModifier.None;
            InheritanceModifier im = InheritanceModifier.None;
            bool isStart = false;
            bool isHot = false;
            bool isCold = false;
            bool isAsync = false;
            bool isPartial = false;

            while (!base.TokenStream.Done &&
                base.TokenStream.Peek().Type != TokenType.StateDecl &&
                base.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                base.TokenStream.Peek().Type != TokenType.MachineDecl)
            {
                if (am != AccessModifier.None &&
                    (base.TokenStream.Peek().Type == TokenType.Public ||
                    base.TokenStream.Peek().Type == TokenType.Private ||
                    base.TokenStream.Peek().Type == TokenType.Protected ||
                    base.TokenStream.Peek().Type == TokenType.Internal))
                {
                    throw new ParsingException("More than one protection modifier.",
                        new List<TokenType>());
                }
                else if (im != InheritanceModifier.None &&
                    base.TokenStream.Peek().Type == TokenType.Abstract)
                {
                    throw new ParsingException("Duplicate abstract modifier.",
                        new List<TokenType>());
                }
                else if (isStart &&
                    base.TokenStream.Peek().Type == TokenType.StartState)
                {
                    throw new ParsingException("Duplicate start state modifier.",
                        new List<TokenType>());
                }
                else if (isHot &&
                    base.TokenStream.Peek().Type == TokenType.HotState)
                {
                    throw new ParsingException("Duplicate hot state modifier.",
                        new List<TokenType>());
                }
                else if (isCold &&
                    base.TokenStream.Peek().Type == TokenType.ColdState)
                {
                    throw new ParsingException("Duplicate cold state modifier.",
                        new List<TokenType>());
                }
                else if ((isCold &&
                    base.TokenStream.Peek().Type == TokenType.HotState) ||
                    (isHot &&
                    base.TokenStream.Peek().Type == TokenType.ColdState))
                {
                    throw new ParsingException("State cannot be both hot and cold.",
                        new List<TokenType>());
                }
                else if (isAsync &&
                    base.TokenStream.Peek().Type == TokenType.Async)
                {
                    throw new ParsingException("Duplicate async method modifier.",
                        new List<TokenType>());
                }
                else if (isPartial &&
                    base.TokenStream.Peek().Type == TokenType.Partial)
                {
                    throw new ParsingException("Duplicate partial method modifier.",
                        new List<TokenType>());
                }

                if (base.TokenStream.Peek().Type == TokenType.Public)
                {
                    am = AccessModifier.Public;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Private)
                {
                    am = AccessModifier.Private;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Protected)
                {
                    am = AccessModifier.Protected;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Internal)
                {
                    am = AccessModifier.Internal;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Abstract)
                {
                    im = InheritanceModifier.Abstract;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Virtual)
                {
                    im = InheritanceModifier.Virtual;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Override)
                {
                    im = InheritanceModifier.Override;
                }
                else if (base.TokenStream.Peek().Type == TokenType.StartState)
                {
                    isStart = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.HotState)
                {
                    isHot = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.ColdState)
                {
                    isCold = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Async)
                {
                    isAsync = true;
                }
                else if (base.TokenStream.Peek().Type == TokenType.Partial)
                {
                    isPartial = true;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.StateDecl &&
                base.TokenStream.Peek().Type != TokenType.StateGroupDecl))
            {
                throw new ParsingException("Expected state or group declaration.",
                    new List<TokenType>
                {
                    TokenType.StateDecl,
                    TokenType.StateGroupDecl
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                if (am == AccessModifier.Public)
                {
                    throw new ParsingException("A state cannot be public.",
                        new List<TokenType>());
                }
                else if (am == AccessModifier.Internal)
                {
                    throw new ParsingException("A state cannot be internal.",
                        new List<TokenType>());
                }

                if (im == InheritanceModifier.Abstract)
                {
                    throw new ParsingException("A state cannot be abstract.",
                        new List<TokenType>());
                }
                else if (im == InheritanceModifier.Virtual)
                {
                    throw new ParsingException("A state cannot be virtual.",
                        new List<TokenType>());
                }
                else if (im == InheritanceModifier.Override)
                {
                    throw new ParsingException("A state cannot be overriden.",
                        new List<TokenType>());
                }

                if (isAsync)
                {
                    throw new ParsingException("A state cannot be async.",
                        new List<TokenType>());
                }

                if (isPartial)
                {
                    throw new ParsingException("A state cannot be partial.",
                        new List<TokenType>());
                }

                new StateDeclarationVisitor(base.TokenStream).Visit(parentNode.Machine,
                    parentNode, isStart, isHot, isCold, am);
            }
            else if (base.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                if (am == AccessModifier.Public)
                {
                    throw new ParsingException("A state group cannot be public.",
                        new List<TokenType>());
                }
                else if (am == AccessModifier.Internal)
                {
                    throw new ParsingException("A state group cannot be internal.",
                        new List<TokenType>());
                }

                if (im == InheritanceModifier.Abstract)
                {
                    throw new ParsingException("A state group cannot be abstract.",
                        new List<TokenType>());
                }
                else if (im == InheritanceModifier.Virtual)
                {
                    throw new ParsingException("A state group cannot be virtual.",
                        new List<TokenType>());
                }
                else if (im == InheritanceModifier.Override)
                {
                    throw new ParsingException("A state group cannot be overriden.",
                        new List<TokenType>());
                }

                if (isAsync)
                {
                    throw new ParsingException("A state group cannot be async.",
                        new List<TokenType>());
                }

                if (isPartial)
                {
                    throw new ParsingException("A state group cannot be partial.",
                        new List<TokenType>());
                }

                if (isStart)
                {
                    throw new ParsingException("A state group cannot be marked start.",
                        new List<TokenType>());
                }
                else if (isHot)
                {
                    throw new ParsingException("A state group cannot be hot.",
                        new List<TokenType>());
                }
                else if (isCold)
                {
                    throw new ParsingException("A state group cannot be cold.",
                        new List<TokenType>());
                }

                new StateGroupDeclarationVisitor(base.TokenStream).Visit(parentNode.Machine, parentNode, am);
            }
        }
示例#10
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="groupNode">Parent state group</param>
        /// <param name="isStart">Is start state</param>
        /// <param name="isHot">Is start state</param>
        /// <param name="isCold">Is start state</param>
        /// <param name="accMod">Access modifier</param>
        internal void Visit(MachineDeclaration parentNode, StateGroupDeclaration groupNode,
            bool isStart, bool isHot, bool isCold, AccessModifier accMod)
        {
            var node = new StateDeclaration(base.TokenStream.Program, parentNode,
                groupNode, isStart, isHot, isCold);
            node.AccessModifier = accMod;
            node.StateKeyword = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected state identifier.",
                    new List<TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.StateIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                    new List<TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                TokenType.StateLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                this.VisitNextPSharpIntraStateDeclaration(node);
            }
            else
            {
                this.VisitNextPIntraStateDeclaration(node);
            }

            // Insert into (immediately) containing group or machine declaration.
            if (groupNode != null)
            {
                groupNode.StateDeclarations.Add(node);
            }
            else
            {
                parentNode.StateDeclarations.Add(node);
            }
        }