Converted DSL APIs to use skstd::string_view.
This is a prerequisite for DSLParser, which will be using string_view. This CL also adds a new string_view-based DSLType constructor which will be used by DSLParser.. Change-Id: I228fba32efb0c680455149712a944489b9168bf4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/414906 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
87fab9f72a
commit
f07b4ce437
@ -45,7 +45,7 @@ public:
|
||||
private:
|
||||
SkSL::Modifiers fModifiers;
|
||||
|
||||
friend DSLType Struct(const char* name, SkTArray<DSLField> fields);
|
||||
friend DSLType Struct(skstd::string_view name, SkTArray<DSLField> fields);
|
||||
friend class DSLFunction;
|
||||
friend class DSLVar;
|
||||
friend class DSLWriter;
|
||||
|
@ -82,6 +82,8 @@ public:
|
||||
DSLType(const SkSL::Type* type)
|
||||
: fSkSLType(type) {}
|
||||
|
||||
DSLType(skstd::string_view name);
|
||||
|
||||
/**
|
||||
* Returns true if this type is a bool.
|
||||
*/
|
||||
@ -171,7 +173,7 @@ private:
|
||||
TypeConstant fTypeConstant;
|
||||
|
||||
friend DSLType Array(const DSLType& base, int count);
|
||||
friend DSLType Struct(const char* name, SkTArray<DSLField> fields);
|
||||
friend DSLType Struct(skstd::string_view name, SkTArray<DSLField> fields);
|
||||
friend class DSLFunction;
|
||||
friend class DSLVar;
|
||||
friend class DSLWriter;
|
||||
@ -219,26 +221,26 @@ DSLType Array(const DSLType& base, int count);
|
||||
|
||||
class DSLField {
|
||||
public:
|
||||
DSLField(const DSLType type, const char* name)
|
||||
DSLField(const DSLType type, skstd::string_view name)
|
||||
: DSLField(DSLModifiers(), type, name) {}
|
||||
|
||||
private:
|
||||
DSLField(DSLModifiers modifiers, const DSLType type, const char* name)
|
||||
DSLField(DSLModifiers modifiers, const DSLType type, skstd::string_view name)
|
||||
: fModifiers(modifiers)
|
||||
, fType(type)
|
||||
, fName(name) {}
|
||||
|
||||
DSLModifiers fModifiers;
|
||||
const DSLType fType;
|
||||
const char* fName;
|
||||
skstd::string_view fName;
|
||||
|
||||
friend DSLType Struct(const char* name, SkTArray<DSLField> fields);
|
||||
friend DSLType Struct(skstd::string_view name, SkTArray<DSLField> fields);
|
||||
};
|
||||
|
||||
DSLType Struct(const char* name, SkTArray<DSLField> fields);
|
||||
DSLType Struct(skstd::string_view name, SkTArray<DSLField> fields);
|
||||
|
||||
template<typename... Field>
|
||||
DSLType Struct(const char* name, Field... fields) {
|
||||
DSLType Struct(skstd::string_view name, Field... fields) {
|
||||
SkTArray<DSLField> fieldTypes;
|
||||
fieldTypes.reserve_back(sizeof...(fields));
|
||||
// in C++17, we could just do:
|
||||
|
@ -15,6 +15,22 @@ namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
|
||||
DSLType::DSLType(skstd::string_view name) {
|
||||
const SkSL::Symbol* symbol = (*DSLWriter::SymbolTable())[name];
|
||||
if (symbol) {
|
||||
if (symbol->is<SkSL::Type>()) {
|
||||
fSkSLType = &symbol->as<SkSL::Type>();
|
||||
} else {
|
||||
DSLWriter::ReportError(String::printf("symbol '%.*s' is not a type",
|
||||
(int) name.length(),
|
||||
name.data()).c_str());
|
||||
}
|
||||
} else {
|
||||
DSLWriter::ReportError(String::printf("no symbol named '%.*s'", (int) name.length(),
|
||||
name.data()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool DSLType::isBoolean() const {
|
||||
return this->skslType().isBoolean();
|
||||
}
|
||||
@ -177,7 +193,7 @@ DSLType Array(const DSLType& base, int count) {
|
||||
return DSLWriter::SymbolTable()->addArrayDimension(&base.skslType(), count);
|
||||
}
|
||||
|
||||
DSLType Struct(const char* name, SkTArray<DSLField> fields) {
|
||||
DSLType Struct(skstd::string_view name, SkTArray<DSLField> fields) {
|
||||
std::vector<SkSL::Type::Field> skslFields;
|
||||
skslFields.reserve(fields.count());
|
||||
for (const DSLField& field : fields) {
|
||||
|
Loading…
Reference in New Issue
Block a user