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"
|
2021-08-13 21:29:51 +00:00
|
|
|
#include "src/sksl/SkSLCompiler.h"
|
2021-10-07 14:47:32 +00:00
|
|
|
#include "src/sksl/SkSLThreadContext.h"
|
2021-02-26 01:50:32 +00:00
|
|
|
#include "src/sksl/dsl/priv/DSLWriter.h"
|
|
|
|
|
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
using namespace SkSL::dsl;
|
|
|
|
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
|
2021-08-13 21:29:51 +00:00
|
|
|
class ExpectErrorLineNumber : public SkSL::ErrorReporter {
|
2021-02-26 01:50:32 +00:00
|
|
|
public:
|
|
|
|
ExpectErrorLineNumber(skiatest::Reporter* reporter, const char* msg, int line)
|
|
|
|
: fMsg(msg)
|
|
|
|
, fLine(line)
|
2021-08-13 21:29:51 +00:00
|
|
|
, fReporter(reporter)
|
|
|
|
, fOldReporter(&GetErrorReporter()) {
|
|
|
|
SetErrorReporter(this);
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~ExpectErrorLineNumber() override {
|
|
|
|
REPORTER_ASSERT(fReporter, !fMsg);
|
2021-08-13 21:29:51 +00:00
|
|
|
SetErrorReporter(fOldReporter);
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 20:31:57 +00:00
|
|
|
void handleError(std::string_view msg, SkSL::PositionInfo pos) override {
|
2021-09-07 17:49:07 +00:00
|
|
|
REPORTER_ASSERT(fReporter, msg == fMsg,
|
|
|
|
"Error mismatch: expected:\n%sbut received:\n%.*s", fMsg, (int)msg.length(),
|
|
|
|
msg.data());
|
2021-08-06 13:17:18 +00:00
|
|
|
REPORTER_ASSERT(fReporter, pos.line() == fLine,
|
2021-09-07 17:49:07 +00:00
|
|
|
"Line number mismatch: expected %d, but received %d\n", fLine, pos.line());
|
2021-10-07 14:47:32 +00:00
|
|
|
SkSL::ThreadContext::Compiler().handleError(msg, pos);
|
2021-02-26 01:50:32 +00:00
|
|
|
fMsg = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* fMsg;
|
|
|
|
int fLine;
|
|
|
|
skiatest::Reporter* fReporter;
|
2021-08-13 21:29:51 +00:00
|
|
|
ErrorReporter* fOldReporter;
|
2021-02-26 01:50:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLErrorLineNumbers, r, ctxInfo) {
|
|
|
|
Start(ctxInfo.directContext()->priv().getGpu()->shaderCompiler());
|
|
|
|
{
|
2021-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "type mismatch: '+' cannot operate on 'float', 'bool'",
|
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-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "type mismatch: '=' cannot operate on 'bool', 'float'",
|
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-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "expected 'int', but found 'bool'", __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-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "'++' cannot operate on 'int[5]'", __LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
(++a).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "expected 'bool', but found 'int'", __LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
Do(Discard(), 5).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "expected 'bool', but found 'int'", __LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
For(DSLStatement(), 5, DSLExpression(), Block()).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "expected 'bool', but found 'int'", __LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
If(5, Discard()).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "expected 'bool', but found 'int'", __LINE__ + 1);
|
2021-06-25 16:31:44 +00:00
|
|
|
While(5, Discard()).release();
|
2021-02-26 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-08-13 21:29:51 +00:00
|
|
|
ExpectErrorLineNumber error(r, "no match for abs(bool)", __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__)
|