In VarDeclarations, align constructor parameter type with storage
This moves the type juggling to the callers, but means that we don't have to allocate a second vector in the constructor and copy things over. Change-Id: If017a7d6fe4eaa678679b1506f6c0c241d72a381 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322626 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
05162812fd
commit
347e5dc371
@ -306,7 +306,7 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTNo
|
|||||||
auto declarationsIter = decls.begin();
|
auto declarationsIter = decls.begin();
|
||||||
const Modifiers& modifiers = declarationsIter++->getModifiers();
|
const Modifiers& modifiers = declarationsIter++->getModifiers();
|
||||||
const ASTNode& rawType = *(declarationsIter++);
|
const ASTNode& rawType = *(declarationsIter++);
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> variables;
|
std::vector<std::unique_ptr<Statement>> variables;
|
||||||
const Type* baseType = this->convertType(rawType);
|
const Type* baseType = this->convertType(rawType);
|
||||||
if (!baseType) {
|
if (!baseType) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -562,9 +562,10 @@ std::unique_ptr<Statement> Inliner::inlineStatement(int offset,
|
|||||||
}
|
}
|
||||||
case Statement::Kind::kVarDeclarations: {
|
case Statement::Kind::kVarDeclarations: {
|
||||||
const VarDeclarations& decls = *statement.as<VarDeclarationsStatement>().fDeclaration;
|
const VarDeclarations& decls = *statement.as<VarDeclarationsStatement>().fDeclaration;
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> vars;
|
std::vector<std::unique_ptr<Statement>> vars;
|
||||||
|
vars.reserve(decls.fVars.size());
|
||||||
for (const auto& var : decls.fVars) {
|
for (const auto& var : decls.fVars) {
|
||||||
vars.emplace_back(&stmt(var).release()->as<VarDeclaration>());
|
vars.push_back(stmt(var));
|
||||||
}
|
}
|
||||||
const Type* typePtr = copy_if_needed(&decls.fBaseType, *symbolTableForStatement);
|
const Type* typePtr = copy_if_needed(&decls.fBaseType, *symbolTableForStatement);
|
||||||
return std::unique_ptr<Statement>(new VarDeclarationsStatement(
|
return std::unique_ptr<Statement>(new VarDeclarationsStatement(
|
||||||
@ -645,7 +646,7 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call,
|
|||||||
|
|
||||||
// Prepare the variable declaration (taking extra care with `out` params to not clobber any
|
// Prepare the variable declaration (taking extra care with `out` params to not clobber any
|
||||||
// initial value).
|
// initial value).
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> variables;
|
std::vector<std::unique_ptr<Statement>> variables;
|
||||||
if (initialValue && (modifiers.fFlags & Modifiers::kOut_Flag)) {
|
if (initialValue && (modifiers.fFlags & Modifiers::kOut_Flag)) {
|
||||||
variables.push_back(std::make_unique<VarDeclaration>(
|
variables.push_back(std::make_unique<VarDeclaration>(
|
||||||
variableSymbol, /*sizes=*/std::vector<std::unique_ptr<Expression>>{},
|
variableSymbol, /*sizes=*/std::vector<std::unique_ptr<Expression>>{},
|
||||||
|
@ -315,12 +315,10 @@ std::unique_ptr<ProgramElement> Rehydrator::element() {
|
|||||||
case Rehydrator::kVarDeclarations_Command: {
|
case Rehydrator::kVarDeclarations_Command: {
|
||||||
const Type* baseType = this->type();
|
const Type* baseType = this->type();
|
||||||
int count = this->readU8();
|
int count = this->readU8();
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> vars;
|
std::vector<std::unique_ptr<Statement>> vars;
|
||||||
vars.reserve(count);
|
vars.reserve(count);
|
||||||
for (int i = 0 ; i < count; ++i) {
|
for (int i = 0 ; i < count; ++i) {
|
||||||
std::unique_ptr<Statement> s = this->statement();
|
vars.push_back(this->statement());
|
||||||
SkASSERT(s->kind() == Statement::Kind::kVarDeclaration);
|
|
||||||
vars.emplace_back((VarDeclaration*) s.release());
|
|
||||||
}
|
}
|
||||||
return std::unique_ptr<ProgramElement>(new VarDeclarations(-1, baseType,
|
return std::unique_ptr<ProgramElement>(new VarDeclarations(-1, baseType,
|
||||||
std::move(vars)));
|
std::move(vars)));
|
||||||
@ -438,12 +436,10 @@ std::unique_ptr<Statement> Rehydrator::statement() {
|
|||||||
case Rehydrator::kVarDeclarations_Command: {
|
case Rehydrator::kVarDeclarations_Command: {
|
||||||
const Type* baseType = this->type();
|
const Type* baseType = this->type();
|
||||||
int count = this->readU8();
|
int count = this->readU8();
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> vars;
|
std::vector<std::unique_ptr<Statement>> vars;
|
||||||
vars.reserve(count);
|
vars.reserve(count);
|
||||||
for (int i = 0 ; i < count; ++i) {
|
for (int i = 0 ; i < count; ++i) {
|
||||||
std::unique_ptr<Statement> s = this->statement();
|
vars.push_back(this->statement());
|
||||||
SkASSERT(s->kind() == Statement::Kind::kVarDeclaration);
|
|
||||||
vars.emplace_back((VarDeclaration*) s.release());
|
|
||||||
}
|
}
|
||||||
return std::make_unique<VarDeclarationsStatement>(
|
return std::make_unique<VarDeclarationsStatement>(
|
||||||
std::make_unique<VarDeclarations>(-1, baseType, std::move(vars)));
|
std::make_unique<VarDeclarations>(-1, baseType, std::move(vars)));
|
||||||
|
@ -72,23 +72,25 @@ struct VarDeclaration : public Statement {
|
|||||||
struct VarDeclarations : public ProgramElement {
|
struct VarDeclarations : public ProgramElement {
|
||||||
static constexpr Kind kProgramElementKind = Kind::kVar;
|
static constexpr Kind kProgramElementKind = Kind::kVar;
|
||||||
|
|
||||||
VarDeclarations(int offset, const Type* baseType,
|
// vars must be a vector of unique_ptr<VarDeclaration>, but to simplify the CFG, we store
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> vars)
|
// (and thus are constructed with) Statements.
|
||||||
: INHERITED(offset, kProgramElementKind)
|
VarDeclarations(int offset, const Type* baseType, std::vector<std::unique_ptr<Statement>> vars)
|
||||||
, fBaseType(*baseType) {
|
: INHERITED(offset, kProgramElementKind), fBaseType(*baseType)
|
||||||
for (auto& var : vars) {
|
, fVars(std::move(vars)) {
|
||||||
fVars.push_back(std::unique_ptr<Statement>(var.release()));
|
#if defined(SK_DEBUG)
|
||||||
|
for (auto& var : fVars) {
|
||||||
|
SkASSERT(var->is<VarDeclaration>());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ProgramElement> clone() const override {
|
std::unique_ptr<ProgramElement> clone() const override {
|
||||||
std::vector<std::unique_ptr<VarDeclaration>> cloned;
|
std::vector<std::unique_ptr<Statement>> cloned;
|
||||||
|
cloned.reserve(fVars.size());
|
||||||
for (const auto& v : fVars) {
|
for (const auto& v : fVars) {
|
||||||
cloned.push_back(std::unique_ptr<VarDeclaration>(
|
cloned.push_back(v->clone());
|
||||||
(VarDeclaration*) v->clone().release()));
|
|
||||||
}
|
}
|
||||||
return std::unique_ptr<ProgramElement>(new VarDeclarations(fOffset, &fBaseType,
|
return std::make_unique<VarDeclarations>(fOffset, &fBaseType, std::move(cloned));
|
||||||
std::move(cloned)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String description() const override {
|
String description() const override {
|
||||||
|
Loading…
Reference in New Issue
Block a user