Remove ASTNode::TypeData
Pre-cleanup as I start looking at how structs are parsed and handled in the IR. Bug: skia:11228 Change-Id: I6334d1073211cbbdf69ddffa8df420c45fd59fcc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/361059 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
1ff760981d
commit
00fea5b41f
@ -143,6 +143,7 @@ sksl_error_tests = [
|
||||
"/sksl/errors/StaticIfTest.sksl",
|
||||
"/sksl/errors/StaticSwitchConditionalBreak.sksl",
|
||||
"/sksl/errors/StaticSwitchTest.sksl",
|
||||
"/sksl/errors/StructNameWithoutIdentifier.sksl",
|
||||
"/sksl/errors/StructTooDeeplyNested.sksl",
|
||||
"/sksl/errors/SwitchDuplicateCase.sksl",
|
||||
"/sksl/errors/SwitchTypes.sksl",
|
||||
|
2
resources/sksl/errors/StructNameWithoutIdentifier.sksl
Normal file
2
resources/sksl/errors/StructNameWithoutIdentifier.sksl
Normal file
@ -0,0 +1,2 @@
|
||||
struct S { float x; };
|
||||
S;
|
@ -204,7 +204,7 @@ String ASTNode::description() const {
|
||||
return "(" + this->begin()->description() + " ? " + (this->begin() + 1)->description() +
|
||||
" : " + (this->begin() + 2)->description() + ")";
|
||||
case Kind::kType:
|
||||
return String(getTypeData().fName);
|
||||
return getString();
|
||||
case Kind::kVarDeclaration: {
|
||||
VarData vd = getVarData();
|
||||
String result = vd.fName;
|
||||
|
@ -113,7 +113,7 @@ struct ASTNode {
|
||||
kSwitch,
|
||||
// children: test, ifTrue, ifFalse
|
||||
kTernary,
|
||||
// data: TypeData, children: sizes
|
||||
// data: name(StringFragment), children: sizes
|
||||
kType,
|
||||
// data: VarData, children: arraySize1, arraySize2, ..., value?
|
||||
kVarDeclaration,
|
||||
@ -181,17 +181,6 @@ struct ASTNode {
|
||||
friend struct ASTNode;
|
||||
};
|
||||
|
||||
struct TypeData {
|
||||
TypeData() {}
|
||||
|
||||
TypeData(StringFragment name, bool isStructDeclaration)
|
||||
: fName(name)
|
||||
, fIsStructDeclaration(isStructDeclaration) {}
|
||||
|
||||
StringFragment fName;
|
||||
bool fIsStructDeclaration;
|
||||
};
|
||||
|
||||
struct ParameterData {
|
||||
ParameterData() {}
|
||||
|
||||
@ -267,7 +256,6 @@ struct ASTNode {
|
||||
sizeof(SKSL_INT),
|
||||
sizeof(SKSL_FLOAT),
|
||||
sizeof(Modifiers),
|
||||
sizeof(TypeData),
|
||||
sizeof(FunctionData),
|
||||
sizeof(ParameterData),
|
||||
sizeof(VarData),
|
||||
@ -281,7 +269,6 @@ struct ASTNode {
|
||||
kInt,
|
||||
kFloat,
|
||||
kModifiers,
|
||||
kTypeData,
|
||||
kFunctionData,
|
||||
kParameterData,
|
||||
kVarData,
|
||||
@ -321,11 +308,6 @@ struct ASTNode {
|
||||
memcpy(fBytes, &data, sizeof(data));
|
||||
}
|
||||
|
||||
NodeData(TypeData data)
|
||||
: fKind(Kind::kTypeData) {
|
||||
memcpy(fBytes, &data, sizeof(data));
|
||||
}
|
||||
|
||||
NodeData(FunctionData data)
|
||||
: fKind(Kind::kFunctionData) {
|
||||
memcpy(fBytes, &data, sizeof(data));
|
||||
@ -379,6 +361,7 @@ struct ASTNode {
|
||||
case Kind::kField:
|
||||
case Kind::kIdentifier:
|
||||
case Kind::kScope:
|
||||
case Kind::kType:
|
||||
fData.fKind = NodeData::Kind::kStringFragment;
|
||||
break;
|
||||
|
||||
@ -410,10 +393,6 @@ struct ASTNode {
|
||||
fData.fKind = NodeData::Kind::kVarData;
|
||||
break;
|
||||
|
||||
case Kind::kType:
|
||||
fData.fKind = NodeData::Kind::kTypeData;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -461,12 +440,6 @@ struct ASTNode {
|
||||
, fOffset(offset)
|
||||
, fKind(kind) {}
|
||||
|
||||
ASTNode(std::vector<ASTNode>* nodes, int offset, Kind kind, TypeData td)
|
||||
: fNodes(nodes)
|
||||
, fData(td)
|
||||
, fOffset(offset)
|
||||
, fKind(kind) {}
|
||||
|
||||
ASTNode(std::vector<ASTNode>* nodes, int offset, Kind kind, SectionData s)
|
||||
: fNodes(nodes)
|
||||
, fData(s)
|
||||
@ -523,18 +496,6 @@ struct ASTNode {
|
||||
memcpy(fData.fBytes, &m, sizeof(m));
|
||||
}
|
||||
|
||||
TypeData getTypeData() const {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kTypeData);
|
||||
TypeData result;
|
||||
memcpy(&result, fData.fBytes, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTypeData(const ASTNode::TypeData& td) {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kTypeData);
|
||||
memcpy(fData.fBytes, &td, sizeof(td));
|
||||
}
|
||||
|
||||
ParameterData getParameterData() const {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kParameterData);
|
||||
ParameterData result;
|
||||
|
@ -1429,8 +1429,7 @@ void IRGenerator::convertEnum(const ASTNode& e) {
|
||||
SkASSERT(e.fKind == ASTNode::Kind::kEnum);
|
||||
SKSL_INT currentValue = 0;
|
||||
Layout layout;
|
||||
ASTNode enumType(e.fNodes, e.fOffset, ASTNode::Kind::kType,
|
||||
ASTNode::TypeData(e.getString(), /*isStructDeclaration=*/false));
|
||||
ASTNode enumType(e.fNodes, e.fOffset, ASTNode::Kind::kType, e.getString());
|
||||
const Type* type = this->convertType(enumType);
|
||||
Modifiers modifiers(layout, Modifiers::kConst_Flag);
|
||||
std::shared_ptr<SymbolTable> oldTable = fSymbolTable;
|
||||
@ -1489,10 +1488,10 @@ bool IRGenerator::typeContainsPrivateFields(const Type& type) {
|
||||
}
|
||||
|
||||
const Type* IRGenerator::convertType(const ASTNode& type, bool allowVoid) {
|
||||
ASTNode::TypeData td = type.getTypeData();
|
||||
const Symbol* symbol = (*fSymbolTable)[td.fName];
|
||||
StringFragment name = type.getString();
|
||||
const Symbol* symbol = (*fSymbolTable)[name];
|
||||
if (!symbol || !symbol->is<Type>()) {
|
||||
this->errorReporter().error(type.fOffset, "unknown type '" + td.fName + "'");
|
||||
this->errorReporter().error(type.fOffset, "unknown type '" + name + "'");
|
||||
return nullptr;
|
||||
}
|
||||
const Type* result = &symbol->as<Type>();
|
||||
@ -1500,22 +1499,22 @@ const Type* IRGenerator::convertType(const ASTNode& type, bool allowVoid) {
|
||||
if (*result == *fContext.fTypes.fVoid) {
|
||||
if (!allowVoid) {
|
||||
this->errorReporter().error(type.fOffset,
|
||||
"type '" + td.fName + "' not allowed in this context");
|
||||
"type '" + name + "' not allowed in this context");
|
||||
return nullptr;
|
||||
}
|
||||
if (isArray) {
|
||||
this->errorReporter().error(type.fOffset,
|
||||
"type '" + td.fName + "' may not be used in an array");
|
||||
"type '" + name + "' may not be used in an array");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (!fIsBuiltinCode && this->typeContainsPrivateFields(*result)) {
|
||||
this->errorReporter().error(type.fOffset, "type '" + td.fName + "' is private");
|
||||
this->errorReporter().error(type.fOffset, "type '" + name + "' is private");
|
||||
return nullptr;
|
||||
}
|
||||
if (isArray && result->isOpaque()) {
|
||||
this->errorReporter().error(type.fOffset,
|
||||
"opaque type '" + td.fName + "' may not be used in an array");
|
||||
"opaque type '" + name + "' may not be used in an array");
|
||||
return nullptr;
|
||||
}
|
||||
if (isArray) {
|
||||
|
@ -488,10 +488,6 @@ ASTNode::ID Parser::declaration() {
|
||||
if (!type) {
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
if (getNode(type).getTypeData().fIsStructDeclaration &&
|
||||
this->checkNext(Token::Kind::TK_SEMICOLON)) {
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
Token name;
|
||||
if (!this->expectIdentifier(&name)) {
|
||||
return ASTNode::ID::Invalid();
|
||||
@ -593,7 +589,7 @@ ASTNode::ID Parser::structDeclaration() {
|
||||
"modifier '" + desc + "' is not permitted on a struct field");
|
||||
}
|
||||
|
||||
const Symbol* symbol = fSymbols[(declsNode.begin() + 1)->getTypeData().fName];
|
||||
const Symbol* symbol = fSymbols[(declsNode.begin() + 1)->getString()];
|
||||
SkASSERT(symbol);
|
||||
const Type* type = &symbol->as<Type>();
|
||||
if (type->isOpaque()) {
|
||||
@ -636,9 +632,7 @@ ASTNode::ID Parser::structDeclaration() {
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
fSymbols.add(std::move(newType));
|
||||
return this->createNode(name.fOffset, ASTNode::Kind::kType,
|
||||
ASTNode::TypeData(this->text(name),
|
||||
/*isStructDeclaration=*/true));
|
||||
return this->createNode(name.fOffset, ASTNode::Kind::kType, this->text(name));
|
||||
}
|
||||
|
||||
/* structDeclaration ((IDENTIFIER varDeclarationEnd) | SEMICOLON) */
|
||||
@ -1149,8 +1143,7 @@ ASTNode::ID Parser::type() {
|
||||
this->error(type, ("no type named '" + this->text(type) + "'").c_str());
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
ASTNode::ID result = this->createNode(type.fOffset, ASTNode::Kind::kType);
|
||||
ASTNode::TypeData td(this->text(type), /*isStructDeclaration=*/false);
|
||||
ASTNode::ID result = this->createNode(type.fOffset, ASTNode::Kind::kType, this->text(type));
|
||||
bool isArray = false;
|
||||
while (this->checkNext(Token::Kind::TK_LBRACKET)) {
|
||||
if (isArray) {
|
||||
@ -1171,7 +1164,6 @@ ASTNode::ID Parser::type() {
|
||||
isArray = true;
|
||||
this->expect(Token::Kind::TK_RBRACKET, "']'");
|
||||
}
|
||||
getNode(result).setTypeData(td);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
4
tests/sksl/errors/StructNameWithoutIdentifier.glsl
Normal file
4
tests/sksl/errors/StructNameWithoutIdentifier.glsl
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 2: expected an identifier, but found ';'
|
||||
1 error
|
Loading…
Reference in New Issue
Block a user