/// <exception cref="ArgumentNullException"><paramref name="context" /> or <paramref name="jumpTarget" /> is <c>null</c>.</exception>
        internal LSLJumpStatementNode(
            LSLParser.JumpStatementContext context,
            LSLLabelStatementNode jumpTarget
            )
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (jumpTarget == null)
            {
                throw new ArgumentNullException("jumpTarget");
            }

            LabelName = context.jump_target.Text;

            JumpTarget = jumpTarget;
            JumpTarget.AddJumpToHere(this);

            SourceRange = new LSLSourceCodeRange(context);

            SourceRangeLabelName   = new LSLSourceCodeRange(context.jump_target);
            SourceRangeJumpKeyword = new LSLSourceCodeRange(context.jump_keyword);
            SourceRangeSemicolon   = new LSLSourceCodeRange(context.semi_colon);

            SourceRangesAvailable = true;
        }
Esempio n. 2
0
        public override bool VisitLabelStatement(LSLParser.LabelStatementContext context)
        {
            if (context == null || context.label_name == null)
            {
                throw LSLCodeValidatorInternalException.VisitContextInvalidState("VisitLabelStatement", true);
            }


            if (_scopingManager.LabelPreDefinedAnywhere(context.label_name.Text))
            {
                GenSyntaxError().RedefinedLabel(new LSLSourceCodeRange(context), context.label_name.Text);
                return(false);
            }


            var ctx = new LSLLabelStatementNode(context);

            var statementIndexInfo = _statementIndexStack.Peek();

            ctx.ParentScopeId = statementIndexInfo.ScopeId;

            ctx.StatementIndex = statementIndexInfo.Index;

            _scopingManager.PreDefineLabel(context.label_name.Text, ctx);


            return(base.VisitLabelStatement(context));
        }
        /// <summary>
        ///     Creates an <see cref="LSLJumpStatementNode" /> that jumps to a specified <see cref="LSLLabelStatementNode" />, with
        ///     a <see cref="ParentScopeId" /> of zero.
        ///     <paramref name="jumpTarget" /> receives a <see cref="LSLLabelStatementNode.JumpsToHere" /> reference via
        ///     <see cref="LSLLabelStatementNode.AddJumpToHere" />.
        /// </summary>
        /// <param name="jumpTarget">The <see cref="LSLLabelStatementNode" /> to jump to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="jumpTarget" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="jumpTarget" /> does not have a Parent, is not already in the syntax tree.</exception>
        public LSLJumpStatementNode(LSLLabelStatementNode jumpTarget)
        {
            if (jumpTarget == null)
            {
                throw new ArgumentNullException("jumpTarget");
            }

            if (jumpTarget.Parent == null)
            {
                throw new ArgumentException("jumpTarget.Parent is null, must have a parent (be part of the syntax tree) prior to being jumped to.", "jumpTarget");
            }

            LabelName = jumpTarget.LabelName;

            JumpTarget = jumpTarget;

            JumpTarget.AddJumpToHere(this);
        }
Esempio n. 4
0
        /// <summary>
        /// Sets a labels parent to this <see cref="LSLCodeScopeNode"/>, also sets <see cref="LSLLabelStatementNode.ParentScopeId"/> to this nodes <see cref="ScopeId"/>.
        /// </summary>
        /// <param name="label">The label node to take pre define ownership of.</param>
        /// <returns><paramref name="label"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="label"/> is <c>null</c>.</exception>
        public LSLLabelStatementNode PreDefineLabel(LSLLabelStatementNode label)
        {
            if (label == null)
            {
                throw new ArgumentNullException("label");
            }

            if (_preDefinedLabels == null)
            {
                _preDefinedLabels = new HashSet <LSLLabelStatementNode>(
                    new LambdaEqualityComparer <LSLLabelStatementNode>(ReferenceEquals)
                    );
            }

            label.Parent        = this;
            label.ParentScopeId = ScopeId;
            _preDefinedLabels.Add(label);
            return(label);
        }
 public void PreDefineLabel(string name, LSLLabelStatementNode statement)
 {
     _labelScopes[CurrentCodeScopeContext][name] = statement;
 }