2021-02-26 01:50:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2021-03-09 18:10:59 +00:00
|
|
|
#include "include/private/SkSLIRNode.h"
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/sksl/DSL.h"
|
2021-02-26 01:50:32 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/sksl/SkSLIRGenerator.h"
|
|
|
|
#include "src/sksl/dsl/priv/DSLWriter.h"
|
|
|
|
|
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
using namespace SkSL::dsl;
|
|
|
|
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
|
|
|
|
class ExpectErrorLineNumber : public ErrorHandler {
|
|
|
|
public:
|
|
|
|
ExpectErrorLineNumber(skiatest::Reporter* reporter, const char* msg, int line)
|
|
|
|
: fMsg(msg)
|
|
|
|
, fLine(line)
|
|
|
|
, fReporter(reporter) {
|
|
|
|
SetErrorHandler(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ExpectErrorLineNumber() override {
|
|
|
|
REPORTER_ASSERT(fReporter, !fMsg);
|
|
|
|
SetErrorHandler(nullptr);
|
|
|
|
}
|
|
|
|
|
2021-08-06 13:17:18 +00:00
|
|
|
void handleError(const char* msg, PositionInfo pos) override {
|
2021-02-26 01:50:32 +00:00
|
|
|
REPORTER_ASSERT(fReporter, !strcmp(msg, fMsg),
|
|
|
|
"Error mismatch: expected:\n%sbut received:\n%s", fMsg, msg);
|
2021-08-06 13:17:18 +00:00
|
|
|
REPORTER_ASSERT(fReporter, pos.line() == fLine,
|
|
|
|
"Line number mismatch: expected %d, but received %d\n", fLine, pos.line());
|
2021-02-26 01:50:32 +00:00
|
|
|
fMsg = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* fMsg;
|
|
|
|
int fLine;
|
|
|
|
skiatest::Reporter* fReporter;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLErrorLineNumbers, r, ctxInfo) {
|
|
|
|
Start(ctxInfo.directContext()->priv().getGpu()->shaderCompiler());
|
|
|
|
{
|
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: type mismatch: '+' cannot operate on 'float', 'bool'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
(Float(1) + true).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-04-08 20:56:05 +00:00
|
|
|
Var a(kBool_Type);
|
2021-03-16 20:37:29 +00:00
|
|
|
DSLWriter::MarkDeclared(a);
|
2021-02-26 01:50:32 +00:00
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: type mismatch: '=' cannot operate on 'bool', 'float'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
(a = 5.0f).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-04-08 20:56:05 +00:00
|
|
|
Var a(Array(kInt_Type, 5));
|
2021-03-16 20:37:29 +00:00
|
|
|
DSLWriter::MarkDeclared(a);
|
2021-02-26 01:50:32 +00:00
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: expected 'int', but found 'bool'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
(a[true]).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-04-08 20:56:05 +00:00
|
|
|
Var a(Array(kInt_Type, 5));
|
2021-03-16 20:37:29 +00:00
|
|
|
DSLWriter::MarkDeclared(a);
|
2021-02-26 01:50:32 +00:00
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: '++' cannot operate on 'int[5]'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
(++a).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: expected 'bool', but found 'int'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
Do(Discard(), 5).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: expected 'bool', but found 'int'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
For(DSLStatement(), 5, DSLExpression(), Block()).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: expected 'bool', but found 'int'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
If(5, Discard()).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: expected 'bool', but found 'int'\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
While(5, Discard()).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ExpectErrorLineNumber error(r,
|
|
|
|
"error: no match for abs(bool)\n",
|
2021-03-16 20:37:29 +00:00
|
|
|
__LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
Abs(true).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
End();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(__GNUC__) || defined(__clang__)
|