Fix various SkSL errors that don't report a line number.

Change-Id: I1a96060b2e52cddb50948a48520aab30bd097bbd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343577
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-12-11 17:30:47 -05:00 committed by Skia Commit-Bot
parent cbdc261955
commit ea16670e71
11 changed files with 46 additions and 47 deletions

View File

@ -378,7 +378,7 @@ StatementArray IRGenerator::convertVarDeclarations(const ASTNode& decls,
if (iter != varDecl.end()) {
if (varData.fIsArray) {
if (type->isOpaque()) {
fErrors.error(type->fOffset,
fErrors.error(varDecl.fOffset,
"opaque type '" + type->name() + "' may not be used in an array");
}
const ASTNode& rawSize = *iter++;
@ -1472,38 +1472,37 @@ std::unique_ptr<Expression> IRGenerator::coerce(std::unique_ptr<Expression> expr
if (expr->type() == *fContext.fInvalid_Type) {
return nullptr;
}
int offset = expr->fOffset;
if (!expr->coercionCost(type).isPossible(fSettings->fAllowNarrowingConversions)) {
fErrors.error(expr->fOffset, "expected '" + type.displayName() + "', but found '" +
expr->type().displayName() + "'");
fErrors.error(offset, "expected '" + type.displayName() + "', but found '" +
expr->type().displayName() + "'");
return nullptr;
}
if (type.isScalar()) {
ExpressionArray args;
args.push_back(std::move(expr));
std::unique_ptr<Expression> ctor;
if (type == *fContext.fFloatLiteral_Type) {
ctor = this->convertIdentifier(ASTNode(&fFile->fNodes, -1, ASTNode::Kind::kIdentifier,
"float"));
} else if (type == *fContext.fIntLiteral_Type) {
ctor = this->convertIdentifier(ASTNode(&fFile->fNodes, -1, ASTNode::Kind::kIdentifier,
"int"));
} else {
ctor = this->convertIdentifier(ASTNode(&fFile->fNodes, -1, ASTNode::Kind::kIdentifier,
type.name()));
}
if (!ctor) {
printf("error, null identifier: %s\n", String(type.name()).c_str());
}
SkASSERT(ctor);
return this->call(/*offset=*/-1, std::move(ctor), std::move(args));
}
if (expr->kind() == Expression::Kind::kNullLiteral) {
if (expr->is<NullLiteral>()) {
SkASSERT(type.typeKind() == Type::TypeKind::kNullable);
return std::unique_ptr<Expression>(new NullLiteral(expr->fOffset, &type));
return std::make_unique<NullLiteral>(offset, &type);
}
ExpressionArray args;
args.push_back(std::move(expr));
return std::make_unique<Constructor>(/*offset=*/-1, &type, std::move(args));
if (!type.isScalar()) {
return std::make_unique<Constructor>(offset, &type, std::move(args));
}
std::unique_ptr<Expression> ctor;
if (type == *fContext.fFloatLiteral_Type) {
ctor = this->convertIdentifier(ASTNode(&fFile->fNodes, offset, ASTNode::Kind::kIdentifier,
"float"));
} else if (type == *fContext.fIntLiteral_Type) {
ctor = this->convertIdentifier(ASTNode(&fFile->fNodes, offset, ASTNode::Kind::kIdentifier,
"int"));
} else {
ctor = this->convertIdentifier(ASTNode(&fFile->fNodes, offset, ASTNode::Kind::kIdentifier,
type.name()));
}
if (!ctor) {
fErrors.error(offset, "null identifier: " + type.name());
return nullptr;
}
return this->call(offset, std::move(ctor), std::move(args));
}
static bool is_matrix_multiply(const Type& left, Token::Kind op, const Type& right) {

View File

@ -141,9 +141,9 @@ bool MetalCodeGenerator::writeStructDefinition(const Type& type) {
// Flags an error if an array type is found. Meant to be used in places where an array type might
// appear in the SkSL/IR, but can't be represented by Metal.
void MetalCodeGenerator::disallowArrayTypes(const Type& type) {
void MetalCodeGenerator::disallowArrayTypes(const Type& type, int offset) {
if (type.isArray()) {
fErrors.error(type.fOffset, "Metal does not support array types in this context");
fErrors.error(offset, "Metal does not support array types in this context");
}
}
@ -952,7 +952,7 @@ void MetalCodeGenerator::writeConstructor(const Constructor& c, Precedence paren
// Explicitly invoke the constructor, passing in the necessary arguments.
this->writeBaseType(constructorType);
this->disallowArrayTypes(constructorType); // constructors of array types aren't valid exprs
this->disallowArrayTypes(constructorType, c.fOffset);
this->write("(");
const char* separator = "";
int scalarCount = 0;
@ -1377,7 +1377,7 @@ bool MetalCodeGenerator::writeFunctionDeclaration(const FunctionDeclaration& f)
separator = ", ";
} else {
this->writeBaseType(f.returnType());
this->disallowArrayTypes(f.returnType()); // return types can't be arrays in SkSL/GLSL
this->disallowArrayTypes(f.returnType(), f.fOffset);
this->write(" ");
this->writeName(f.name());
this->write("(");
@ -1583,7 +1583,7 @@ void MetalCodeGenerator::writeVarDeclaration(const VarDeclaration& var, bool glo
}
this->writeModifiers(var.var().modifiers(), global);
this->writeBaseType(var.baseType());
this->disallowArrayTypes(var.baseType()); // `float[2] x` shouldn't be possible (invalid SkSL)
this->disallowArrayTypes(var.baseType(), var.fOffset);
this->write(" ");
this->writeName(var.var().name());
if (var.arraySize() > 0) {

View File

@ -171,7 +171,7 @@ protected:
bool writeStructDefinition(const Type& type);
void disallowArrayTypes(const Type& type);
void disallowArrayTypes(const Type& type, int offset);
void writeBaseType(const Type& type);

View File

@ -1,6 +1,6 @@
### Compilation failed:
error: cannot assign to this expression
error: 4: cannot assign to this expression
error: 5: cannot assign to this expression
error: 6: cannot assign to this expression
3 errors

View File

@ -1,7 +1,7 @@
### Compilation failed:
error: opaque type 'sampler' may not be used in an array
error: 1: opaque type 'sampler' may not be used in an array
error: 2: opaque type 'sampler' may not be used in an array
error: opaque type 'sampler' may not be used in an array
error: 3: opaque type 'sampler' may not be used in an array
error: 4: opaque type 'sampler' may not be used in an array
4 errors

View File

@ -1,5 +1,5 @@
### Compilation failed:
error: division by zero
error: 1: division by zero
error: 1: type mismatch: '=' cannot operate on 'half4', 'float4'
2 errors

View File

@ -1,6 +1,6 @@
### Compilation failed:
error: Metal does not support array types in this context
error: Metal does not support array types in this context
error: Metal does not support array types in this context
error: 1: Metal does not support array types in this context
error: 2: Metal does not support array types in this context
error: 3: Metal does not support array types in this context
3 errors

View File

@ -1,7 +1,7 @@
### Compilation failed:
error: Metal does not support array types in this context
error: Metal does not support array types in this context
error: Metal does not support array types in this context
error: Metal does not support array types in this context
error: 2: Metal does not support array types in this context
error: 2: Metal does not support array types in this context
error: 2: Metal does not support array types in this context
error: 2: Metal does not support array types in this context
4 errors

View File

@ -1,5 +1,5 @@
### Compilation failed:
error: Metal does not support array types in this context
error: Metal does not support array types in this context
error: 2: Metal does not support array types in this context
error: 3: Metal does not support array types in this context
2 errors

View File

@ -1,4 +1,4 @@
### Compilation failed:
error: Metal does not support array types in this context
error: 1: Metal does not support array types in this context
1 error

View File

@ -1,4 +1,4 @@
### Compilation failed:
error: opaque type 'sampler' may not be used in an array
error: 1: opaque type 'sampler' may not be used in an array
1 error