/// <inheritdoc/> public override void Visit(VariableReferenceExpression variableReferenceExpression) { base.Visit(variableReferenceExpression); var variableDeclaration = variableReferenceExpression.TypeInference.Declaration as Variable; if (variableDeclaration == null) { result.Error("Unable to find variable [{0}]", variableReferenceExpression.Span, variableReferenceExpression); } else if (variableDeclaration.InitialValue == null || !variableDeclaration.Qualifiers.Contains(StorageQualifier.Const)) { result.Error("Variable [{0}] used in expression is not constant", variableReferenceExpression.Span, variableDeclaration); } else { var evaluator = new ExpressionEvaluator(); var subResult = evaluator.Evaluate(variableDeclaration.InitialValue); subResult.CopyTo(result); if (subResult.HasErrors) { values.Push(0.0); } else { values.Push(subResult.Value); } } }
/// <inheritdoc/> public override void Visit(MethodInvocationExpression methodInvocationExpression) { if (methodInvocationExpression.Target is TypeReferenceExpression) { var methodName = (methodInvocationExpression.Target as TypeReferenceExpression).Type.Name.Text; if (hlslScalarTypeNames.Contains(methodName)) { var evaluator = new ExpressionEvaluator(); var subResult = evaluator.Evaluate(methodInvocationExpression.Arguments[0]); values.Push(subResult.Value); return; } } result.Error("Method invocation expression evaluation [{0}] is not supported", methodInvocationExpression.Span, methodInvocationExpression); }