Remove custom iterators from SkSL::Program

Instead, just expose the vector directly (as elements()).

Change-Id: I9f6a3ae38cd8e6f1b0a1087a42d61452fe883924
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324130
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2020-10-08 16:04:40 -04:00 committed by Skia Commit-Bot
parent 99b1a8b2f8
commit 1179fcf5ed
13 changed files with 110 additions and 154 deletions

View File

@ -151,10 +151,10 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
const SkSL::Context& ctx(compiler->context());
// Go through program elements, pulling out information that we need
for (const auto& elem : *program) {
for (const auto& elem : program->elements()) {
// Variables (uniform, varying, etc.)
if (elem.is<SkSL::GlobalVarDeclaration>()) {
const auto& varDecl = elem.as<SkSL::GlobalVarDeclaration>().fDecl;
if (elem->is<SkSL::GlobalVarDeclaration>()) {
const auto& varDecl = elem->as<SkSL::GlobalVarDeclaration>().fDecl;
const SkSL::Variable& var = *varDecl->fVar;
const SkSL::Type& varType = var.type();
@ -211,8 +211,8 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
}
}
// Functions
else if (elem.is<SkSL::FunctionDefinition>()) {
const auto& func = elem.as<SkSL::FunctionDefinition>();
else if (elem->is<SkSL::FunctionDefinition>()) {
const auto& func = elem->as<SkSL::FunctionDefinition>();
const SkSL::FunctionDeclaration& decl = func.fDeclaration;
if (decl.name() == "main") {
hasMain = true;

View File

@ -341,8 +341,8 @@ bool Analysis::IsAssignable(Expression& expr, VariableReference** assignableVar,
template <typename PROG, typename EXPR, typename STMT, typename ELEM>
bool TProgramVisitor<PROG, EXPR, STMT, ELEM>::visit(PROG program) {
for (ELEM pe : program) {
if (this->visitProgramElement(pe)) {
for (const auto& pe : program.elements()) {
if (this->visitProgramElement(*pe)) {
return true;
}
}

View File

@ -147,20 +147,20 @@ void ByteCodeGenerator::gatherUniforms(const Type& type, const String& name) {
}
bool ByteCodeGenerator::generateCode() {
for (const auto& e : fProgram) {
switch (e.kind()) {
for (const auto& e : fProgram.elements()) {
switch (e->kind()) {
case ProgramElement::Kind::kFunction: {
std::unique_ptr<ByteCodeFunction> f =
this->writeFunction(e.as<FunctionDefinition>());
this->writeFunction(e->as<FunctionDefinition>());
if (!f) {
return false;
}
fOutput->fFunctions.push_back(std::move(f));
fFunctions.push_back(&e.as<FunctionDefinition>());
fFunctions.push_back(&e->as<FunctionDefinition>());
break;
}
case ProgramElement::Kind::kGlobalVar: {
const GlobalVarDeclaration& decl = e.as<GlobalVarDeclaration>();
const GlobalVarDeclaration& decl = e->as<GlobalVarDeclaration>();
const Variable* declVar = decl.fDecl->fVar;
if (declVar->type() == *fContext.fFragmentProcessor_Type) {
fOutput->fChildFPCount++;
@ -454,9 +454,9 @@ ByteCodeGenerator::Location ByteCodeGenerator::getLocation(const Variable& var)
case Variable::kGlobal_Storage: {
if (var.type() == *fContext.fFragmentProcessor_Type) {
int offset = 0;
for (const auto& e : fProgram) {
if (e.is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decl = e.as<GlobalVarDeclaration>();
for (const auto& e : fProgram.elements()) {
if (e->is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decl = e->as<GlobalVarDeclaration>();
const Variable* declVar = decl.fDecl->fVar;
if (declVar->type() != *fContext.fFragmentProcessor_Type) {
continue;
@ -482,9 +482,9 @@ ByteCodeGenerator::Location ByteCodeGenerator::getLocation(const Variable& var)
}
int offset = 0;
bool isUniform = is_uniform(var);
for (const auto& e : fProgram) {
if (e.is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decl = e.as<GlobalVarDeclaration>();
for (const auto& e : fProgram.elements()) {
if (e->is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decl = e->as<GlobalVarDeclaration>();
const Variable* declVar = decl.fDecl->fVar;
if (declVar->modifiers().fLayout.fBuiltin >= 0 || is_in(*declVar)) {
continue;

View File

@ -412,9 +412,9 @@ void CPPCodeGenerator::writeFieldAccess(const FieldAccess& access) {
int CPPCodeGenerator::getChildFPIndex(const Variable& var) const {
int index = 0;
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
if (decl.fVar == &var) {
return index;
} else if (decl.fVar->type().nonnullable() == *fContext.fFragmentProcessor_Type) {
@ -703,9 +703,9 @@ void CPPCodeGenerator::writeInputVars() {
}
void CPPCodeGenerator::writePrivateVars() {
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
if (is_private(*decl.fVar)) {
if (decl.fVar->type() == *fContext.fFragmentProcessor_Type) {
fErrors.error(decl.fOffset,
@ -741,9 +741,9 @@ void CPPCodeGenerator::writePrivateVars() {
}
void CPPCodeGenerator::writePrivateVarValues() {
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
if (is_private(*decl.fVar) && decl.fValue) {
this->writef("%s = ", String(decl.fVar->name()).c_str());
fCPPMode = true;
@ -955,9 +955,9 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) {
this->writef(" const %s& _outer = args.fFp.cast<%s>();\n"
" (void) _outer;\n",
fFullName.c_str(), fFullName.c_str());
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
String nameString(decl.fVar->name());
const char* name = nameString.c_str();
if (SectionAndParameterHelper::IsParameter(*decl.fVar) &&
@ -1068,9 +1068,9 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) {
}
if (section) {
int samplerIndex = 0;
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
const Variable& variable = *decl.fVar;
String nameString(variable.name());
const char* name = nameString.c_str();
@ -1241,9 +1241,9 @@ void CPPCodeGenerator::writeGetKey() {
this->writef("void %s::onGetGLSLProcessorKey(const GrShaderCaps& caps, "
"GrProcessorKeyBuilder* b) const {\n",
fFullName.c_str());
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
const Variable& var = *decl.fVar;
const Type& varType = var.type();
String nameString(var.name());
@ -1315,9 +1315,9 @@ void CPPCodeGenerator::writeGetKey() {
bool CPPCodeGenerator::generateCode() {
std::vector<const Variable*> uniforms;
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
if ((decl.fVar->modifiers().fFlags & Modifiers::kUniform_Flag) &&
decl.fVar->type().typeKind() != Type::TypeKind::kSampler) {
uniforms.push_back(decl.fVar);

View File

@ -1659,9 +1659,9 @@ bool Compiler::optimize(Program& program) {
bool madeChanges = false;
// Scan and optimize based on the control-flow graph for each function.
for (ProgramElement& element : program) {
if (element.is<FunctionDefinition>()) {
madeChanges |= this->scanCFG(element.as<FunctionDefinition>());
for (const auto& element : program.elements()) {
if (element->is<FunctionDefinition>()) {
madeChanges |= this->scanCFG(element->as<FunctionDefinition>());
}
}

View File

@ -1560,8 +1560,8 @@ bool GLSLCodeGenerator::generateCode() {
OutputStream* rawOut = fOut;
StringStream body;
fOut = &body;
for (const auto& e : fProgram) {
this->writeProgramElement(e);
for (const auto& e : fProgram.elements()) {
this->writeProgramElement(*e);
}
fOut = rawOut;

View File

@ -355,9 +355,9 @@ bool HCodeGenerator::generateCode() {
"class %s : public GrFragmentProcessor {\n"
"public:\n",
fFullName.c_str());
for (const auto& p : fProgram) {
if (p.kind() == ProgramElement::Kind::kEnum && !((Enum&) p).isBuiltin()) {
this->writef("%s\n", ((Enum&) p).code().c_str());
for (const auto& p : fProgram.elements()) {
if (p->is<Enum>() && !p->as<Enum>().isBuiltin()) {
this->writef("%s\n", p->as<Enum>().code().c_str());
}
}
this->writeSection(kClassSection);

View File

@ -800,8 +800,8 @@ public:
fCandidateList = candidateList;
fSymbolTableStack.push_back(program.fSymbols.get());
for (ProgramElement& pe : program) {
this->visitProgramElement(&pe);
for (const auto& pe : program.elements()) {
this->visitProgramElement(pe.get());
}
fSymbolTableStack.pop_back();

View File

@ -953,9 +953,9 @@ void MetalCodeGenerator::writeFunction(const FunctionDefinition& f) {
this->write(", constant Uniforms& _uniforms [[buffer(" +
to_string(fUniformBuffer) + ")]]");
}
for (const auto& e : fProgram) {
if (e.is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e.as<GlobalVarDeclaration>();
for (const auto& e : fProgram.elements()) {
if (e->is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e->as<GlobalVarDeclaration>();
const VarDeclaration& var = *decls.fDecl;
if (var.fVar->type().typeKind() == Type::TypeKind::kSampler) {
if (var.fVar->modifiers().fLayout.fBinding < 0) {
@ -980,8 +980,8 @@ void MetalCodeGenerator::writeFunction(const FunctionDefinition& f) {
this->write(to_string(var.fVar->modifiers().fLayout.fBinding));
this->write(")]]");
}
} else if (e.kind() == ProgramElement::Kind::kInterfaceBlock) {
InterfaceBlock& intf = (InterfaceBlock&) e;
} else if (e->is<InterfaceBlock>()) {
const InterfaceBlock& intf = e->as<InterfaceBlock>();
if ("sk_PerVertex" == intf.fTypeName) {
continue;
}
@ -1392,9 +1392,9 @@ void MetalCodeGenerator::writeHeader() {
}
void MetalCodeGenerator::writeUniformStruct() {
for (const auto& e : fProgram) {
if (e.is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e.as<GlobalVarDeclaration>();
for (const auto& e : fProgram.elements()) {
if (e->is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e->as<GlobalVarDeclaration>();
const Variable& var = *decls.fDecl->fVar;
if (var.modifiers().fFlags & Modifiers::kUniform_Flag &&
var.type().typeKind() != Type::TypeKind::kSampler) {
@ -1425,9 +1425,9 @@ void MetalCodeGenerator::writeUniformStruct() {
void MetalCodeGenerator::writeInputStruct() {
this->write("struct Inputs {\n");
for (const auto& e : fProgram) {
if (e.is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e.as<GlobalVarDeclaration>();
for (const auto& e : fProgram.elements()) {
if (e->is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e->as<GlobalVarDeclaration>();
const Variable& var = *decls.fDecl->fVar;
if (var.modifiers().fFlags & Modifiers::kIn_Flag &&
-1 == var.modifiers().fLayout.fBuiltin) {
@ -1458,9 +1458,9 @@ void MetalCodeGenerator::writeOutputStruct() {
} else if (fProgram.fKind == Program::kFragment_Kind) {
this->write(" float4 sk_FragColor [[color(0)]];\n");
}
for (const auto& e : fProgram) {
if (e.is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e.as<GlobalVarDeclaration>();
for (const auto& e : fProgram.elements()) {
if (e->is<GlobalVarDeclaration>()) {
const GlobalVarDeclaration& decls = e->as<GlobalVarDeclaration>();
const Variable& var = *decls.fDecl->fVar;
if (var.modifiers().fFlags & Modifiers::kOut_Flag &&
-1 == var.modifiers().fLayout.fBuiltin) {
@ -1492,9 +1492,9 @@ void MetalCodeGenerator::writeOutputStruct() {
void MetalCodeGenerator::writeInterfaceBlocks() {
bool wroteInterfaceBlock = false;
for (const auto& e : fProgram) {
if (e.kind() == ProgramElement::Kind::kInterfaceBlock) {
this->writeInterfaceBlock(e.as<InterfaceBlock>());
for (const auto& e : fProgram.elements()) {
if (e->is<InterfaceBlock>()) {
this->writeInterfaceBlock(e->as<InterfaceBlock>());
wroteInterfaceBlock = true;
}
}
@ -1510,11 +1510,11 @@ void MetalCodeGenerator::visitGlobalStruct(GlobalStructVisitor* visitor) {
for (const auto& [interfaceType, interfaceName] : fInterfaceBlockNameMap) {
visitor->VisitInterfaceBlock(*interfaceType, interfaceName);
}
for (const ProgramElement& element : fProgram) {
if (!element.is<GlobalVarDeclaration>()) {
for (const auto& element : fProgram.elements()) {
if (!element->is<GlobalVarDeclaration>()) {
continue;
}
const GlobalVarDeclaration& decls = element.as<GlobalVarDeclaration>();
const GlobalVarDeclaration& decls = element->as<GlobalVarDeclaration>();
const VarDeclaration& decl = *decls.fDecl;
const Variable& var = *decl.fVar;
if ((!var.modifiers().fFlags && -1 == var.modifiers().fLayout.fBuiltin) ||
@ -1809,9 +1809,9 @@ MetalCodeGenerator::Requirements MetalCodeGenerator::requirements(const Function
auto found = fRequirements.find(&f);
if (found == fRequirements.end()) {
fRequirements[&f] = kNo_Requirements;
for (const auto& e : fProgram) {
if (e.kind() == ProgramElement::Kind::kFunction) {
const FunctionDefinition& def = e.as<FunctionDefinition>();
for (const auto& e : fProgram.elements()) {
if (e->is<FunctionDefinition>()) {
const FunctionDefinition& def = e->as<FunctionDefinition>();
if (&def.fDeclaration == &f) {
Requirements reqs = this->requirements(def.fBody.get());
fRequirements[&f] = reqs;
@ -1835,8 +1835,8 @@ bool MetalCodeGenerator::generateCode() {
this->writeGlobalStruct();
StringStream body;
fOut = &body;
for (const auto& e : fProgram) {
this->writeProgramElement(e);
for (const auto& e : fProgram.elements()) {
this->writeProgramElement(*e);
}
fOut = rawOut;

View File

@ -44,9 +44,9 @@ void PipelineStageCodeGenerator::writeFunctionCall(const FunctionCall& c) {
SkASSERT(arguments[0]->is<VariableReference>());
int index = 0;
bool found = false;
for (const auto& p : fProgram) {
if (p.is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
for (const auto& p : fProgram.elements()) {
if (p->is<GlobalVarDeclaration>()) {
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
if (decl.fVar == arguments[0]->as<VariableReference>().variable()) {
found = true;
} else if (decl.fVar->type() == *fContext.fFragmentProcessor_Type) {
@ -80,9 +80,9 @@ void PipelineStageCodeGenerator::writeFunctionCall(const FunctionCall& c) {
INHERITED::writeFunctionCall(c);
} else {
int index = 0;
for (const ProgramElement& e : fProgram) {
if (e.kind() == ProgramElement::Kind::kFunction) {
if (&e.as<FunctionDefinition>().fDeclaration == &function) {
for (const auto& e : fProgram.elements()) {
if (e->is<FunctionDefinition>()) {
if (&e->as<FunctionDefinition>().fDeclaration == &function) {
break;
}
++index;
@ -120,12 +120,12 @@ void PipelineStageCodeGenerator::writeVariableReference(const VariableReference&
auto varIndexByFlag = [this, &ref](uint32_t flag) {
int index = 0;
bool found = false;
for (const ProgramElement& e : fProgram) {
for (const auto& e : fProgram.elements()) {
if (found) {
break;
}
if (e.is<GlobalVarDeclaration>()) {
const Variable& var = *e.as<GlobalVarDeclaration>().fDecl->fVar;
if (e->is<GlobalVarDeclaration>()) {
const Variable& var = *e->as<GlobalVarDeclaration>().fDecl->fVar;
if (&var == ref.variable()) {
found = true;
break;

View File

@ -2715,9 +2715,9 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
SpvId typeId;
Modifiers intfModifiers = intf.fVariable->modifiers();
if (intfModifiers.fLayout.fBuiltin == SK_IN_BUILTIN) {
for (const auto& e : fProgram) {
if (e.kind() == ProgramElement::Kind::kModifiers) {
const Modifiers& m = ((ModifiersDeclaration&) e).fModifiers;
for (const auto& e : fProgram.elements()) {
if (e->is<ModifiersDeclaration>()) {
const Modifiers& m = e->as<ModifiersDeclaration>().fModifiers;
update_sk_in_count(m, &fSkInCount);
}
}
@ -3092,9 +3092,9 @@ void SPIRVCodeGenerator::writeReturnStatement(const ReturnStatement& r, OutputSt
void SPIRVCodeGenerator::writeGeometryShaderExecutionMode(SpvId entryPoint, OutputStream& out) {
SkASSERT(fProgram.fKind == Program::kGeometry_Kind);
int invocations = 1;
for (const auto& e : fProgram) {
if (e.kind() == ProgramElement::Kind::kModifiers) {
const Modifiers& m = ((ModifiersDeclaration&) e).fModifiers;
for (const auto& e : fProgram.elements()) {
if (e->is<ModifiersDeclaration>()) {
const Modifiers& m = e->as<ModifiersDeclaration>().fModifiers;
if (m.fFlags & Modifiers::kIn_Flag) {
if (m.fLayout.fInvocations != -1) {
invocations = m.fLayout.fInvocations;
@ -3161,15 +3161,15 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
std::set<SpvId> interfaceVars;
// assign IDs to functions, determine sk_in size
int skInSize = -1;
for (const auto& e : program) {
switch (e.kind()) {
for (const auto& e : program.elements()) {
switch (e->kind()) {
case ProgramElement::Kind::kFunction: {
FunctionDefinition& f = (FunctionDefinition&) e;
const FunctionDefinition& f = e->as<FunctionDefinition>();
fFunctionMap[&f.fDeclaration] = this->nextId();
break;
}
case ProgramElement::Kind::kModifiers: {
Modifiers& m = ((ModifiersDeclaration&) e).fModifiers;
Modifiers& m = e->as<ModifiersDeclaration>().fModifiers;
if (m.fFlags & Modifiers::kIn_Flag) {
switch (m.fLayout.fPrimitive) {
case Layout::kPoints_Primitive: // break
@ -3193,9 +3193,9 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
break;
}
}
for (const auto& e : program) {
if (e.kind() == ProgramElement::Kind::kInterfaceBlock) {
InterfaceBlock& intf = (InterfaceBlock&) e;
for (const auto& e : program.elements()) {
if (e->is<InterfaceBlock>()) {
InterfaceBlock& intf = e->as<InterfaceBlock>();
const Modifiers& modifiers = intf.fVariable->modifiers();
if (SK_IN_BUILTIN == modifiers.fLayout.fBuiltin) {
SkASSERT(skInSize != -1);
@ -3210,14 +3210,14 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
}
}
}
for (const auto& e : program) {
if (e.is<GlobalVarDeclaration>()) {
this->writeGlobalVar(program.fKind, *e.as<GlobalVarDeclaration>().fDecl, body);
for (const auto& e : program.elements()) {
if (e->is<GlobalVarDeclaration>()) {
this->writeGlobalVar(program.fKind, *e->as<GlobalVarDeclaration>().fDecl, body);
}
}
for (const auto& e : program) {
if (e.kind() == ProgramElement::Kind::kFunction) {
this->writeFunction(((FunctionDefinition&) e), body);
for (const auto& e : program.elements()) {
if (e->is<FunctionDefinition>()) {
this->writeFunction(e->as<FunctionDefinition>(), body);
}
}
const FunctionDeclaration* main = nullptr;
@ -3271,9 +3271,9 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
SpvExecutionModeOriginUpperLeft,
out);
}
for (const auto& e : program) {
if (e.kind() == ProgramElement::Kind::kExtension) {
this->writeInstruction(SpvOpSourceExtension, ((Extension&) e).name().c_str(), out);
for (const auto& e : program.elements()) {
if (e->is<Extension>()) {
this->writeInstruction(SpvOpSourceExtension, e->as<Extension>().name().c_str(), out);
}
}

View File

@ -27,17 +27,17 @@ namespace SkSL {
SectionAndParameterHelper::SectionAndParameterHelper(const Program* program, ErrorReporter& errors)
: fProgram(*program) {
for (const auto& p : fProgram) {
switch (p.kind()) {
for (const auto& p : fProgram.elements()) {
switch (p->kind()) {
case ProgramElement::Kind::kGlobalVar: {
const VarDeclaration& decl = *p.as<GlobalVarDeclaration>().fDecl;
const VarDeclaration& decl = *p->as<GlobalVarDeclaration>().fDecl;
if (IsParameter(*decl.fVar)) {
fParameters.push_back(decl.fVar);
}
break;
}
case ProgramElement::Kind::kSection: {
const Section& s = (const Section&) p;
const Section& s = p->as<Section>();
if (IsSupportedSection(s.fName.c_str())) {
if (SectionRequiresArgument(s.fName.c_str()) && !s.fArgument.size()) {
errors.error(s.fOffset,

View File

@ -149,46 +149,6 @@ struct Program {
}
};
class iterator {
public:
ProgramElement& operator*() { return **fIter; }
iterator& operator++() {
++fIter;
return *this;
}
bool operator==(const iterator& other) const { return fIter == other.fIter; }
bool operator!=(const iterator& other) const { return !(*this == other); }
private:
using inner = std::vector<std::unique_ptr<ProgramElement>>::iterator;
iterator(inner iter) : fIter(iter) {}
inner fIter;
friend struct Program;
};
class const_iterator {
public:
const ProgramElement& operator*() { return **fIter; }
const_iterator& operator++() {
++fIter;
return *this;
}
bool operator==(const const_iterator& other) const { return fIter == other.fIter; }
bool operator!=(const const_iterator& other) const { return !(*this == other); }
private:
using inner = std::vector<std::unique_ptr<ProgramElement>>::const_iterator;
const_iterator(inner iter) : fIter(iter) {}
inner fIter;
friend struct Program;
};
enum Kind {
kFragment_Kind,
kVertex_Kind,
@ -215,11 +175,7 @@ struct Program {
, fElements(std::move(elements))
, fModifiers(std::move(modifiers)) {}
iterator begin() { return iterator(fElements.begin()); }
iterator end() { return iterator(fElements.end()); }
const_iterator begin() const { return const_iterator(fElements.begin()); }
const_iterator end() const { return const_iterator(fElements.end()); }
const std::vector<std::unique_ptr<ProgramElement>>& elements() const { return fElements; }
void finish() {
fModifiers->finish();