/// <summary> /// Construct an <see cref="LSLVariableNode" /> that references a library constant. /// </summary> /// <param name="type">The constants type.</param> /// <param name="constantName">The constants name.</param> /// <param name="sourceRange">Optional source range for the area the reference exists in.</param> /// <exception cref="ArgumentNullException"><paramref name="constantName" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// <paramref name="type" /> is <see cref="LSLType.Void" />. /// </exception> /// <exception cref="LSLInvalidSymbolNameException"><paramref name="constantName" /> is contains characters that are invalid in an LSL ID token.</exception> internal static LSLVariableNode CreateLibraryConstantReference(LSLType type, string constantName, LSLSourceCodeRange sourceRange = null) { if (constantName == null) { throw new ArgumentNullException("constantName"); } if (type == LSLType.Void) { throw new ArgumentException( typeof(LSLVariableNode).Name + ".CreateLibraryConstant: type cannot be LSLType.Void.", "type"); } if (!LSLTokenTools.IDRegexAnchored.IsMatch(constantName)) { throw new LSLInvalidSymbolNameException( typeof(LSLVariableNode).Name + ".CreateLibraryConstant: name contains invalid ID characters."); } return(new LSLVariableNode { Name = constantName, TypeName = type.ToLSLTypeName(), Type = type, ExpressionType = LSLExpressionType.LibraryConstant, IsConstant = true, SourceRange = sourceRange }); }
/// <summary> /// Construct an <see cref="LSLVariableNode" /> that references a local variable declaration node. /// </summary> /// <param name="declarationNode">A variable declaration node.</param> /// <param name="variableName">The name of the local variable.</param> /// <param name="type">The type of the local variable.</param> /// <param name="sourceRange">Optional source range for the area the reference exists in.</param> /// <returns>A new variable node representing a reference to <paramref name="declarationNode" />.</returns> /// <exception cref="ArgumentNullException"><paramref name="declarationNode" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// <paramref name="type" /> is <see cref="LSLType.Void" /> or /// </exception> /// <exception cref="LSLInvalidSymbolNameException"><paramref name="variableName" /> contains characters that are not valid in an LSL ID token.</exception> internal static LSLVariableNode CreateLocalVarReference(LSLType type, string variableName, ILSLVariableDeclarationNode declarationNode, LSLSourceCodeRange sourceRange = null) { if (declarationNode == null) { throw new ArgumentNullException("declarationNode"); } if (type == LSLType.Void) { throw new ArgumentException("local variable type cannot be LSLType.Void", "type"); } if (!LSLTokenTools.IDRegexAnchored.IsMatch(variableName)) { throw new LSLInvalidSymbolNameException( "variableName provided contained characters not allowed in an LSL ID token."); } return(new LSLVariableNode { Name = variableName, TypeName = type.ToLSLTypeName(), Type = type, IsConstant = false, Declaration = declarationNode, ExpressionType = LSLExpressionType.LocalVariable, SourceRange = sourceRange }); }
/// <summary> /// Construct an <see cref="LSLTypecastExprNode" /> with the given 'cast-to' type and casted expression node. /// </summary> /// <param name="castToType">The <see cref="LSLType" /> to cast to.</param> /// <param name="castedExpression">The expression the cast operator acts on.</param> /// <exception cref="ArgumentNullException"><paramref name="castedExpression" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="castToType" /> is <see cref="LSLType.Void" />.</exception> public LSLTypecastExprNode(LSLType castToType, ILSLExprNode castedExpression) { if (castedExpression == null) { throw new ArgumentNullException("castedExpression"); } if (castToType == LSLType.Void) { throw new ArgumentException("castToType cannot be LSLType.Void."); } CastToTypeName = castToType.ToLSLTypeName(); CastToType = castToType; CastedExpression = castedExpression; CastedExpression.Parent = this; Type = castToType; }
/// <summary> /// Construct a <see cref="LSLParameterNode" /> with the given <see cref="Type" /> and <see cref="Name" />. /// </summary> /// <param name="type">The <see cref="Type" />.</param> /// <param name="parameterName">The <see cref="Name" />.</param> /// <exception cref="ArgumentNullException"><paramref name="parameterName" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// if <paramref name="type" /> is <see cref="LSLType.Void" /> or /// </exception> /// <exception cref="LSLInvalidSymbolNameException"><paramref name="parameterName" /> contains characters that are invalid in an LSL ID token.</exception> public LSLParameterNode(LSLType type, string parameterName) { if (parameterName == null) { throw new ArgumentNullException("parameterName"); } if (type == LSLType.Void) { throw new ArgumentException("parameter type cannot be LSLType.Void.", "type"); } if (!LSLTokenTools.IDRegexAnchored.IsMatch(parameterName)) { throw new LSLInvalidSymbolNameException( "parameterName provided contained characters not allowed in an LSL ID token."); } Name = parameterName; Type = type; TypeName = Type.ToLSLTypeName(); }