예제 #1
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);
        }
예제 #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);
        }
예제 #3
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);
        }
예제 #4
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);
        }