Exemplo n.º 1
0
        /// <summary>
        ///     Create an <see cref="LSLVariableDeclarationNode" /> by cloning from another.
        /// </summary>
        /// <param name="other">The other node to clone from.</param>
        /// <exception cref="ArgumentNullException"><paramref name="other" /> is <c>null</c>.</exception>
        private LSLVariableDeclarationNode(LSLVariableDeclarationNode other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }


            SourceRangesAvailable = other.SourceRangesAvailable;

            if (SourceRangesAvailable)
            {
                SourceRange         = other.SourceRange;
                SourceRangeType     = other.SourceRangeType;
                SourceRangeName     = other.SourceRangeName;
                SourceRangeOperator = other.SourceRangeOperator;
            }

            VariableNode        = other.VariableNode.Clone();
            VariableNode.Parent = this;


            if (other.HasDeclarationExpression)
            {
                DeclarationExpression        = other.DeclarationExpression.Clone();
                DeclarationExpression.Parent = this;
            }

            LSLStatementNodeTools.CopyStatement(this, other);

            HasErrors = other.HasErrors;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates a global variable declaration node with the given <see cref="LSLType" />, name, and declaration expression.
        /// </summary>
        /// <param name="type">The type of the global variable.</param>
        /// <param name="variableName">The name of the global variable.</param>
        /// <param name="declarationExpression">The declaration expression used in the global variables definition.</param>
        /// <returns>The created variable declaration node.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="variableName" /> or <paramref name="declarationExpression" />
        ///     is <c>null</c>.
        /// </exception>
        /// <exception cref="LSLInvalidSymbolNameException">
        ///     <paramref name="variableName" /> contained characters not allowed in an LSL ID token.
        /// </exception>
        public static LSLVariableDeclarationNode CreateGlobalVar(LSLType type, string variableName,
                                                                 ILSLExprNode declarationExpression)
        {
            if (variableName == null)
            {
                throw new ArgumentNullException("variableName");
            }
            if (declarationExpression == null)
            {
                throw new ArgumentNullException("declarationExpression");
            }

            if (!LSLTokenTools.IDRegexAnchored.IsMatch(variableName))
            {
                throw new LSLInvalidSymbolNameException(
                          "variableName provided contained characters not allowed in an LSL ID token.");
            }

            var n = new LSLVariableDeclarationNode();

            n.VariableNode        = LSLVariableNode.CreateGlobalVarReference(type, variableName, n);
            n.VariableNode.Parent = n;

            n.DeclarationExpression = declarationExpression;

            return(n);
        }
Exemplo n.º 3
0
        /// <exception cref="ArgumentNullException"><paramref name="context" /> is <c>null</c>.</exception>
        internal static LSLVariableDeclarationNode CreateVar(LSLParser.LocalVariableDeclarationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var n = new LSLVariableDeclarationNode();

            n.VariableNode        = LSLVariableNode.CreateVarReference(context, n);
            n.SourceRange         = new LSLSourceCodeRange(context);
            n.VariableNode.Parent = n;

            n.SourceRangeType = new LSLSourceCodeRange(context.variable_type);
            n.SourceRangeName = new LSLSourceCodeRange(context.variable_name);

            n.SourceRangesAvailable = true;

            if (context.operation != null)
            {
                n.SourceRangeOperator = new LSLSourceCodeRange(context.operation);
            }

            return(n);
        }
        public ILSLTreePreePass EnterEventScope(LSLParser.EventHandlerContext context,
                                                LSLParsedEventHandlerSignature eventSig)
        {
            _parameterScopeVariables.Clear();
            CurrentFunctionBodySignature = null;
            CurrentFunctionContext       = null;

            CurrentEventHandlerSignature = eventSig;
            CurrentEventHandlerContext   = context;

            if (eventSig.ParameterListNode != null)
            {
                //define all the parameters in the local scope, they are not considered constant in the analysis
                foreach (var parameter in eventSig.ParameterListNode.Parameters)
                {
                    //parameter references are implicitly not constant
                    var parameterRef = LSLVariableDeclarationNode.CreateParameter(parameter);


                    _parameterScopeVariables.Add(parameter.Name, parameterRef);
                }
            }

            return(DoLabelCollectorPrePass(context));
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Construct an <see cref="LSLVariableDeclarationNode" /> that references a library constant.
        /// </summary>
        /// <param name="type">The type of the library constant.</param>
        /// <param name="constantName">The name of the library constant.</param>
        /// <returns>The created variable declaration node.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="constantName" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="type" /> is <see cref="LSLType.Void" /> or
        ///     <paramref name="constantName" /> is contains characters that are invalid in an LSL ID token.
        /// </exception>
        public static LSLVariableDeclarationNode CreateLibraryConstant(LSLType type, string constantName)
        {
            var n = new LSLVariableDeclarationNode
            {
                VariableNode = LSLVariableNode.CreateLibraryConstantReference(type, constantName)
            };

            n.VariableNode.Parent = n;

            return(n);
        }
 public void DefineVariable(LSLVariableDeclarationNode decl, LSLVariableScope scope)
 {
     //return a clone of the node into the global pool of variables, so if we modify it
     //it does not modify the tree node we put it
     if (scope == LSLVariableScope.Global)
     {
         _globalVariables.Add(decl.Name, decl);
     }
     if (scope == LSLVariableScope.Local)
     {
         _scopeVariables.Peek().Add(decl.Name, decl);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Construct an <see cref="LSLVariableDeclarationNode" /> that represents a parameter.
        /// </summary>
        /// <returns>The created variable declaration node.</returns>
        /// <param name="declarationNode">A parameter node that declares the parameter variable.</param>
        /// <exception cref="ArgumentNullException"><paramref name="declarationNode"/> is <c>null</c>.</exception>
        public static LSLVariableDeclarationNode CreateParameter(ILSLParameterNode declarationNode)
        {
            if (declarationNode == null)
            {
                throw new ArgumentNullException("declarationNode");
            }

            var n = new LSLVariableDeclarationNode
            {
                VariableNode          = LSLVariableNode.CreateParameterReference(declarationNode),
                SourceRange           = declarationNode.SourceRange,
                SourceRangesAvailable = true
            };

            n.VariableNode.Parent = n;

            return(n);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Add a global variable declaration node to this compilation unit node.
        /// </summary>
        /// <param name="declaration">The global variable declaration node to add.</param>
        /// <exception cref="ArgumentNullException">Thrown if the 'declaration' parameter is <c>null</c>.</exception>
        public void Add(LSLVariableDeclarationNode declaration)
        {
            if (declaration == null)
            {
                throw new ArgumentNullException("declaration");
            }

            declaration.Parent                 = this;
            declaration.StatementIndex         = _addCounter;
            declaration.IsLastStatementInScope = true;

            if (_globalVariableDeclarations.Count > 0)
            {
                _globalVariableDeclarations.Last().IsLastStatementInScope = false;
            }

            _addCounter++;
            _globalVariableDeclarations.Add(declaration);
        }