Reject struct vardecls with modifiers.
These aren't allowed in GLSL, and typically don't make sense. Change-Id: I0afca0df638590466922a809e91ef0be35b13ca8 Bug: skia:10765 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324816 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
61003cde76
commit
13fc260c70
@ -99,6 +99,7 @@ sksl_error_tests = [
|
||||
"$_tests/sksl/errors/InvalidAssignment.sksl",
|
||||
"$_tests/sksl/errors/InvalidOutParams.sksl",
|
||||
"$_tests/sksl/errors/InvalidUnary.sksl",
|
||||
"$_tests/sksl/errors/ModifiersInStruct.sksl",
|
||||
"$_tests/sksl/errors/OpenArray.sksl",
|
||||
"$_tests/sksl/errors/ReturnDifferentType.sksl",
|
||||
"$_tests/sksl/errors/ReturnFromVoid.sksl",
|
||||
|
@ -503,9 +503,18 @@ ASTNode::ID Parser::structDeclaration() {
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
ASTNode& declsNode = getNode(decls);
|
||||
Modifiers modifiers = declsNode.begin()->getModifiers();
|
||||
if (modifiers.fFlags != Modifiers::kNo_Flag) {
|
||||
String desc = modifiers.description();
|
||||
desc.pop_back(); // remove trailing space
|
||||
this->error(declsNode.fOffset,
|
||||
"modifier '" + desc + "' is not permitted on a struct field");
|
||||
}
|
||||
|
||||
const Symbol* symbol = fSymbols[(declsNode.begin() + 1)->getTypeData().fName];
|
||||
SkASSERT(symbol && symbol->kind() == Symbol::Kind::kType);
|
||||
const Type* type = (const Type*) symbol;
|
||||
SkASSERT(symbol);
|
||||
const Type* type = &symbol->as<Type>();
|
||||
|
||||
for (auto iter = declsNode.begin() + 2; iter != declsNode.end(); ++iter) {
|
||||
ASTNode& var = *iter;
|
||||
ASTNode::VarData vd = var.getVarData();
|
||||
@ -521,7 +530,8 @@ ASTNode::ID Parser::structDeclaration() {
|
||||
std::make_unique<Type>(typeName, Type::TypeKind::kArray, *type,
|
||||
(int)columns));
|
||||
}
|
||||
fields.push_back(Type::Field(declsNode.begin()->getModifiers(), vd.fName, type));
|
||||
|
||||
fields.push_back(Type::Field(modifiers, vd.fName, type));
|
||||
if (vd.fSizeCount ? (var.begin() + (vd.fSizeCount - 1))->fNext : var.fFirstChild) {
|
||||
this->error(declsNode.fOffset, "initializers are not permitted on struct fields");
|
||||
}
|
||||
|
7
tests/sksl/errors/ModifiersInStruct.sksl
Normal file
7
tests/sksl/errors/ModifiersInStruct.sksl
Normal file
@ -0,0 +1,7 @@
|
||||
struct S {
|
||||
const float a;
|
||||
uniform int b;
|
||||
flat half4 c;
|
||||
noperspective float4 d;
|
||||
inout volatile restrict varying buffer coherent bool e;
|
||||
};
|
8
tests/sksl/errors/golden/ModifiersInStruct.glsl
Normal file
8
tests/sksl/errors/golden/ModifiersInStruct.glsl
Normal file
@ -0,0 +1,8 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: modifier 'const' is not permitted on a struct field
|
||||
error: 1: modifier 'uniform' is not permitted on a struct field
|
||||
error: 1: modifier 'flat' is not permitted on a struct field
|
||||
error: 1: modifier 'noperspective' is not permitted on a struct field
|
||||
error: 1: modifier 'coherent volatile restrict buffer varying inout' is not permitted on a struct field
|
||||
5 errors
|
Loading…
Reference in New Issue
Block a user