/// <summary> /// Validates the format of a string is acceptable for assigning to <see cref="ValueString" /> when <see cref="Type" /> /// is equal to the <see cref="LSLType" /> passed in <paramref name="type" />. /// </summary> /// <param name="type">The <see cref="LSLType" /> <paramref name="valueString" /> must be valid for.</param> /// <param name="valueString">The value string to validate.</param> /// <param name="formated">The re-formated version of <paramref name="valueString" /> if the parse was successful.</param> /// <returns> /// <c>true</c> if <paramref name="valueString" /> can successfully be parsed for the given <see cref="LSLType" /> /// . /// </returns> /// <exception cref="ArgumentException">if <paramref name="type" /> is <see cref="LSLType.Void" />.</exception> public static bool TryParseValueString(LSLType type, string valueString, out string formated) { if (type == LSLType.Void) { throw new ArgumentException("type must not be LSLType.Void", "type"); } formated = null; switch (type) { case LSLType.Float: return(TryParseFloatValueString(valueString, out formated)); case LSLType.Integer: return(TryParseIntegerValueString(valueString, out formated)); case LSLType.List: return(TryParseListValueString(valueString, out formated)); case LSLType.Vector: return(TryParseVectorValueString(valueString, out formated)); case LSLType.Rotation: return(TryParseRotationValueString(valueString, out formated)); case LSLType.String: case LSLType.Key: formated = valueString; return(true); } return(false); }
/// <exception cref="ArgumentNullException"> /// <paramref name="context" /> or <paramref name="castedExpression" /> is /// <c>null</c>. /// </exception> internal LSLTypecastExprNode(LSLParser.Expr_TypeCastContext context, LSLType result, ILSLExprNode castedExpression) { if (context == null) { throw new ArgumentNullException("context"); } if (castedExpression == null) { throw new ArgumentNullException("castedExpression"); } CastToTypeName = context.cast_type.Text; CastToType = LSLTypeTools.FromLSLTypeName(CastToTypeName); CastedExpression = castedExpression; CastedExpression.Parent = this; Type = result; SourceRange = new LSLSourceCodeRange(context); SourceRangeCloseParenth = new LSLSourceCodeRange(context.close_parenth); SourceRangeOpenParenth = new LSLSourceCodeRange(context.open_parenth); SourceRangeCastToType = new LSLSourceCodeRange(context.cast_type); SourceRangesAvailable = true; }
private static bool Convert(Type inType, out LSLType outType) { if (typeof(string) == inType) { outType = LSLType.String; return(true); } if (typeof(int) == inType) { outType = LSLType.Integer; return(true); } if (typeof(float) == inType) { outType = LSLType.Float; return(true); } if (typeof(object[]) == inType) { outType = LSLType.List; return(true); } if (typeof(void) == inType) { outType = LSLType.Void; return(true); } outType = LSLType.Void; return(false); }
/// <exception cref="ArgumentNullException"> /// <paramref name="context" /> or <paramref name="leftExpression" /> is /// <c>null</c>. /// </exception> internal LSLPostfixOperationNode(LSLParser.Expr_PostfixOperationContext context, LSLType resultType, ILSLExprNode leftExpression) { if (context == null) { throw new ArgumentNullException("context"); } if (leftExpression == null) { throw new ArgumentNullException("leftExpression"); } Type = resultType; LeftExpression = leftExpression; LeftExpression.Parent = this; ParseAndSetOperation(context.operation.Text); SourceRange = new LSLSourceCodeRange(context); SourceRangeOperation = new LSLSourceCodeRange(context.operation); SourceRangesAvailable = true; }
/// <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="LSLBinaryOperationSignature" /> from the source code string representation of the binary /// operation, /// the operations return type, the return type of the expression on the left and the return type of the expression on /// the right. /// </summary> /// <param name="operation">Source code string representation of the operator.</param> /// <param name="returns">The return type of the binary operation.</param> /// <param name="left">The return type of the expression on the left side of the binary operation.</param> /// <param name="right">The return type of the expression on the right side of the binary operation.</param> public LSLBinaryOperationSignature(string operation, LSLType returns, LSLType left, LSLType right) { Returns = returns; Left = left; Right = right; Operation = LSLBinaryOperationTypeTools.ParseFromOperator(operation); }
/// <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> /// Create a constant literal node using the ANTLR context of the expression atom that represents the source literal. /// </summary> /// <param name="rawText">The raw text of the constant literal.</param> /// <param name="type">The <see cref="LSLType" /> that the source code literal represents.</param> /// <param name="sourceRange"> /// The source code range of the constant literal, or <c>null</c> if source code ranges are not /// available. /// </param> protected internal LSLConstantLiteralNode(string rawText, LSLType type, LSLSourceCodeRange sourceRange) { RawText = rawText; Type = type; SourceRange = sourceRange; SourceRangesAvailable = sourceRange != null; }
/// <summary> /// Construct a parameter signature object. /// </summary> /// <param name="type">The parameter type</param> /// <param name="name">The parameter name</param> /// <param name="variadic">Is the parameter variadic</param> /// <param name="parameterIndex">The parameter index.</param> /// <exception cref="LSLInvalidSymbolNameException"> /// Thrown if the parameter name does not follow LSL symbol naming /// conventions for parameters. /// </exception> /// <exception cref="ArgumentException">Thrown if type is <see cref="LSLType.Void" /> and variadic is false.</exception> public LSLParameterSignature(LSLType type, string name, bool variadic, int parameterIndex) { if (type == LSLType.Void && variadic == false) { throw new ArgumentException(GetType().FullName + ": Type cannot be LSLType.Void unless the parameter it is variadic."); } if (string.IsNullOrWhiteSpace(name)) { throw new LSLInvalidSymbolNameException(GetType().FullName + ": Parameter name was null or whitespace."); } if (!LSLTokenTools.IDRegexAnchored.IsMatch(name)) { throw new LSLInvalidSymbolNameException( string.Format( GetType().FullName + ": Parameter name '{0}' contained invalid characters or formatting.", name)); } Type = type; Name = name; Variadic = variadic; ParameterIndex = parameterIndex; }
/// <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); }
/// <summary> /// Create a <see cref="LSLBinaryExpressionNode" /> from two <see cref="ILSLExprNode" />'s and an operator description. /// </summary> /// <param name="resultType"> /// The resulting type of the binary operation between <paramref name="leftExpression" /> and /// <paramref name="rightExpression" />. /// </param> /// <param name="leftExpression">The left expression.</param> /// <param name="operation">The operator.</param> /// <param name="rightExpression">The right expression.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="leftExpression" /> or <paramref name="rightExpression" /> is /// <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="resultType" /> is equal to <see cref="LSLType.Void" /> or /// <paramref name="operation" /> is equal to <see cref="LSLBinaryOperationType.Error" /> /// </exception> public LSLBinaryExpressionNode(LSLType resultType, ILSLExprNode leftExpression, LSLBinaryOperationType operation, ILSLExprNode rightExpression) { if (leftExpression == null) { throw new ArgumentNullException("leftExpression"); } if (rightExpression == null) { throw new ArgumentNullException("rightExpression"); } if (resultType == LSLType.Void) { throw new ArgumentException("Binary operation resultType cannot be LSLType.Void.", "resultType"); } Type = resultType; LeftExpression = leftExpression; LeftExpression.Parent = this; Operation = operation; OperationString = operation.ToOperatorString(); RightExpression = rightExpression; RightExpression.Parent = this; }
/// <summary> /// Construct an <see cref="LSLBinaryOperationSignature" /> from an <see cref="LSLBinaryOperationType" />, the /// operations return type, /// the return type of the expression on the left and the return type of the expression on the right. /// </summary> /// <param name="operation">The <see cref="LSLBinaryOperationType" /> of the binary operation signature.</param> /// <param name="returns">The return type of the binary operation.</param> /// <param name="left">The return type of the expression on the left side of the binary operation.</param> /// <param name="right">The return type of the expression on the right side of the binary operation.</param> public LSLBinaryOperationSignature(LSLBinaryOperationType operation, LSLType returns, LSLType left, LSLType right) { Returns = returns; Left = left; Right = right; Operation = operation; }
/// <summary> /// Convert an <see cref="LSLType" /> to an LSL type name string. /// </summary> /// <param name="type"><see cref="LSLType" /> to convert.</param> /// <returns>LSL type string representation.</returns> /// <exception cref="ArgumentException">If <see cref="LSLType" /> is <see cref="LSLType.Void" />.</exception> public static string ToLSLTypeName(this LSLType type) { if (type == LSLType.Void) { throw new ArgumentException("Cannot convert LSLType.Void to a valid LSL type string", "type"); } return(type.ToString().ToLower()); }
void ILSLSyntaxErrorListener.RedefinedStandardLibraryConstant(LSLSourceCodeRange location, LSLType redefinitionType, ILSLConstantSignature originalSignature) { _errorActionQueue.Enqueue(location.StartIndex, () => SyntaxErrorListener.RedefinedStandardLibraryConstant(location, redefinitionType, originalSignature)); }
/// <summary> /// Construct the <see cref="ILSLConstantSignature" /> by cloning another one. /// </summary> /// <param name="other">The other <see cref="ILSLConstantSignature" />.</param> /// <exception cref="ArgumentNullException"><paramref name="other" /> is <c>null</c>.</exception> public LSLConstantSignature(ILSLConstantSignature other) { if (other == null) { throw new ArgumentNullException("other"); } _type = other.Type; _valueString = other.ValueString; }
/// <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); }
/// <summary> /// Validates that an expression of some type can be returned from a function given the /// functions return type. /// </summary> /// <param name="returnType">The return type of the function the expression is being returned from.</param> /// <param name="returnedExpression">The expression attempting to be returned.</param> /// <returns>True if the expression is allowed to be returned from the function given the expression type and return type.</returns> public bool ValidateReturnTypeMatch(LSLType returnType, ILSLReadOnlyExprNode returnedExpression) { var left = new LSLDummyExpr { Type = returnType, ExpressionType = LSLExpressionType.LocalVariable }; return (ValidateBinaryOperation(left, LSLBinaryOperationType.Assign, returnedExpression).IsValid); }
/// <summary> /// Construct an <see cref="LSLPreDefinedFunctionSignature" /> from an <see cref="LSLType" /> representing the return /// type, a function name and an <see cref="LSLParameterListNode" /> /// from an LSL Syntax tree. /// </summary> /// <param name="returnType">The return type of the function signature.</param> /// <param name="name">The name of the function.</param> /// <param name="parameters"> /// The <see cref="LSLParameterListNode" /> from an LSL syntax tree that represents the function /// signatures parameters. /// </param> /// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null" />.</exception> /// <exception cref="LSLInvalidSymbolNameException"> /// Thrown if the function name does not follow LSL symbol naming conventions. /// </exception> public LSLPreDefinedFunctionSignature(LSLType returnType, string name, LSLParameterListNode parameters) : base(returnType, name) { if (parameters == null) { throw new ArgumentNullException("parameters"); } foreach (var param in parameters) { AddParameter(param.CreateSignature()); } ParameterListNode = parameters; }
/// <summary> /// Construct a function signature by providing an associated <see cref="LSLType" /> for the return type, a function /// Name and an optional enumerable of <see cref="LSLParameterSignature" /> objects. /// </summary> /// <param name="returnType"></param> /// <param name="name"></param> /// <param name="parameters"></param> /// <exception cref="ArgumentException">Thrown if more than one variadic parameter is added to the function signature.</exception> /// <exception cref="LSLInvalidSymbolNameException"> /// Thrown if the function name does not follow LSL symbol naming conventions. /// </exception> public LSLFunctionSignature(LSLType returnType, string name, IEnumerable <LSLParameterSignature> parameters = null) { ReturnType = returnType; Name = name; VariadicParameterIndex = -1; if (parameters == null) { _parameters = new GenericArray <LSLParameterSignature>(); } else { _parameters = new GenericArray <LSLParameterSignature>(); foreach (var lslParameter in parameters) { AddParameter(lslParameter); } } }
/// <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 an <see cref="LSLPostfixOperationNode" /> from a given <see cref="ILSLExprNode" /> and /// <see cref="LSLPostfixOperationType" />. /// </summary> /// <param name="resultType">The return type of the postfix operation on the given expression.</param> /// <param name="rightExpression">The expression the postfix operation occurs on.</param> /// <param name="operationType">The postfix operation type.</param> /// <exception cref="ArgumentNullException"><paramref name="rightExpression" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="operationType" /> is <see cref="LSLPrefixOperationType.Error" />.</exception> public LSLPrefixOperationNode(LSLType resultType, LSLPrefixOperationType operationType, ILSLExprNode rightExpression) { if (rightExpression == null) { throw new ArgumentNullException("rightExpression"); } if (operationType == LSLPrefixOperationType.Error) { throw new ArgumentException("operationType cannot be LSLPrefixOperationType.Error."); } Type = resultType; RightExpression = rightExpression; RightExpression.Parent = this; Operation = operationType; OperationString = Operation.ToOperatorString(); }
/// <summary> /// Construct an <see cref="LSLPostfixOperationNode" /> from a given <see cref="ILSLExprNode" /> and /// <see cref="LSLPostfixOperationType" />. /// </summary> /// <param name="resultType">The return type of the postfix operation on the given expression.</param> /// <param name="leftExpression">The expression the postfix operation occurs on.</param> /// <param name="operationType">The postfix operation type.</param> /// <exception cref="ArgumentNullException"><paramref name="leftExpression" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="operationType" /> is <see cref="LSLPostfixOperationType.Error" />.</exception> public LSLPostfixOperationNode(LSLType resultType, ILSLExprNode leftExpression, LSLPostfixOperationType operationType) { if (leftExpression == null) { throw new ArgumentNullException("leftExpression"); } if (operationType == LSLPostfixOperationType.Error) { throw new ArgumentException("operationType cannot be LSLPostfixOperationType.Error."); } Type = resultType; LeftExpression = leftExpression; LeftExpression.Parent = this; Operation = operationType; OperationString = Operation.ToOperatorString(); }
/// <summary> /// Construct the LSLLibraryConstantSignature from a given <see cref="LSLType" /> and constant name. /// <see cref="ValueString" /> is given the default /// value for the given <see cref="LSLType" /> passed in <paramref name="type" /> /// </summary> /// <param name="type">The constant type.</param> /// <param name="name">The constant name.</param> /// <exception cref="LSLInvalidSymbolNameException">If <paramref name="name" /> is an invalid LSL ID token.</exception> /// <exception cref="LSLInvalidConstantTypeException"> /// if <paramref name="type" /> is /// <see cref="LSLType.Void" />. /// </exception> public LSLConstantSignature(LSLType type, string name) { Name = name; Type = type; //use _valueString to bypass validation, since its faster //and we know what is required by the class. switch (type) { case LSLType.Key: _valueString = "00000000-0000-0000-0000-000000000000"; break; case LSLType.Integer: _valueString = "0"; break; case LSLType.String: _valueString = ""; break; case LSLType.Float: _valueString = "0.0"; break; case LSLType.List: _valueString = ""; //empty list break; case LSLType.Vector: _valueString = "0,0,0"; break; case LSLType.Rotation: _valueString = "0,0,0,0"; break; default: throw new ArgumentOutOfRangeException("type", type, null); } }
/// <summary> /// Validates and returns the type resulting from a cast operation. /// </summary> /// <param name="castedExpression">The expression to preform the cast on.</param> /// <param name="castTo">The type that is being casted to.</param> /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns> /// <exception cref="ArgumentNullException"><paramref name="castedExpression"/> is <c>null</c>.</exception> public LSLExpressionValidatorResult ValidateCastOperation(LSLType castTo, ILSLReadOnlyExprNode castedExpression) { if (castedExpression == null) { throw new ArgumentNullException("castedExpression"); } if (castedExpression.HasErrors) { return(LSLExpressionValidatorResult.Error); } LSLType t; if (_operations.TryGetValue("(" + castTo + ")" + castedExpression.Type, out t)) { return(new LSLExpressionValidatorResult(t, true)); } return(LSLExpressionValidatorResult.Error); }
/// <exception cref="ArgumentNullException"> /// <paramref name="context" /> or /// <paramref name="leftExpression" /> or /// <paramref name="rightExpression" /> is <c>null</c>. /// </exception> internal LSLBinaryExpressionNode( LSLParser.ExpressionContext context, IToken operationToken, ILSLExprNode leftExpression, ILSLExprNode rightExpression, LSLType returns, string operationString) { if (context == null) { throw new ArgumentNullException("context"); } if (leftExpression == null) { throw new ArgumentNullException("leftExpression"); } if (rightExpression == null) { throw new ArgumentNullException("rightExpression"); } Type = returns; LeftExpression = leftExpression; RightExpression = rightExpression; leftExpression.Parent = this; rightExpression.Parent = this; ParseAndSetOperation(operationString); SourceRange = new LSLSourceCodeRange(context); SourceRangeOperation = new LSLSourceCodeRange(operationToken); SourceRangesAvailable = true; }
/// <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(); }
/// <summary> /// Construct an <see cref="LSLFunctionDeclarationNode" /> with the given return type, parameter list, and code body. /// </summary> /// <param name="returnType">The return type of the function.</param> /// <param name="functionName">The name of the function.</param> /// <param name="parameterList">The parameter list node representing the list of parameter definitions for the function.</param> /// <param name="code">The code scope that makes up the function's code body.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="functionName" /> or <paramref name="parameterList" /> or <paramref name="code" /> is <c>null</c>. /// </exception> /// <exception cref="LSLInvalidSymbolNameException"> /// if <paramref name="functionName" /> contains invalid characters for an LSL ID /// token. /// </exception> public LSLFunctionDeclarationNode(LSLType returnType, string functionName, LSLParameterListNode parameterList, LSLCodeScopeNode code) { if (parameterList == null) { throw new ArgumentNullException("parameterList"); } if (code == null) { throw new ArgumentNullException("code"); } if (functionName == null) { throw new ArgumentNullException("functionName"); } if (!LSLTokenTools.IDRegexAnchored.IsMatch(functionName)) { throw new LSLInvalidSymbolNameException( "functionName provided contained characters not allowed in an LSL ID token."); } Name = functionName; ReturnTypeName = returnType == LSLType.Void ? "" : LSLTypeTools.ToLSLTypeName(returnType); ReturnType = returnType; ParameterList = parameterList; ParameterList.Parent = this; Code = code; Code.Parent = this; Code.CodeScopeType = LSLCodeScopeType.Function; }
/* * /// <summary> * /// Create an <see cref="LSLFunctionDeclarationNode" /> 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 LSLFunctionDeclarationNode(LSLFunctionDeclarationNode other) * { * if (other == null) throw new ArgumentNullException("other"); * * * SourceRangesAvailable = other.SourceRangesAvailable; * * if (SourceRangesAvailable) * { * SourceRange = other.SourceRange; * SourceRangeName = other.SourceRangeName; * SourceRangeReturnType = other.SourceRangeReturnType; * SourceRangesAvailable = other.SourceRangesAvailable; * } * * * Name = other.Name; * * ParameterList = other.ParameterList.Clone(); * ParameterList.Parent = this; * * Code = other.Code.Clone(); * Code.Parent = this; * * * HasErrors = other.HasErrors; * }*/ /// <summary> /// Construct an <see cref="LSLFunctionDeclarationNode" /> with the given return type, and code body. /// The function declaration will have an empty parameter list node. /// </summary> /// <param name="returnType">The return type of the function.</param> /// <param name="functionName">The name of the function.</param> /// <param name="code">The code scope that makes up the function's code body.</param> /// <exception cref="ArgumentException"> /// if <paramref name="functionName" /> contains invalid characters for an LSL ID /// token. /// </exception> public LSLFunctionDeclarationNode(LSLType returnType, string functionName, LSLCodeScopeNode code) : this(returnType, functionName, new LSLParameterListNode(), code) { }
private void AddCastOperation(LSLType castTo, LSLType from, LSLType result) { _operations.Add("(" + castTo + ")" + @from, result); }
/// <summary> /// Construct the LSLLibraryConstantSignature from a given <see cref="LSLType" /> and constant name. /// <see cref="LSLConstantSignature.ValueString" /> is given the default /// value for the given <see cref="LSLType" /> passed in <paramref name="type" /> /// </summary> /// <param name="type">The constant type.</param> /// <param name="name">The constant name.</param> /// <exception cref="LSLInvalidSymbolNameException">If <paramref name="name" /> is an invalid LSL ID token.</exception> /// <exception cref="LSLInvalidConstantTypeException"> /// if <paramref name="type" /> is /// <see cref="LSLType.Void" />. /// </exception> public LSLLibraryConstantSignature(LSLType type, string name) : base(type, name) { DocumentationString = ""; }