Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/parser: remove used members and parameters. #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions src/core/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ struct ParamListItem {
double *doubleValues = nullptr;
const char **stringValues = nullptr;
size_t size = 0;
bool isString = false;
};

PBRT_CONSTEXPR int TokenOptional = 0;
Expand Down Expand Up @@ -520,8 +519,7 @@ static const char *paramTypeToName(int type) {
}
}

static void AddParam(ParamSet &ps, const ParamListItem &item,
SpectrumType spectrumType) {
static void AddParam(ParamSet &ps, const ParamListItem &item) {
int type;
std::string name;
if (lookupType(item.name, &type, name)) {
Expand Down Expand Up @@ -709,8 +707,7 @@ static void AddParam(ParamSet &ps, const ParamListItem &item,
}

template <typename Next, typename Unget>
ParamSet parseParams(Next nextToken, Unget ungetToken, MemoryArena &arena,
SpectrumType spectrumType) {
ParamSet parseParams(Next nextToken, Unget ungetToken, MemoryArena &arena) {
ParamSet ps;
while (true) {
string_view decl = nextToken(TokenOptional);
Expand Down Expand Up @@ -773,7 +770,7 @@ ParamSet parseParams(Next nextToken, Unget ungetToken, MemoryArena &arena,
addVal(val);
}

AddParam(ps, item, spectrumType);
AddParam(ps, item);
arena.Reset();
}

Expand Down Expand Up @@ -839,13 +836,12 @@ static void parse(std::unique_ptr<Tokenizer> t) {
// Helper function for pbrt API entrypoints that take a single string
// parameter and a ParamSet (e.g. pbrtShape()).
auto basicParamListEntrypoint = [&](
SpectrumType spectrumType,
std::function<void(const std::string &n, ParamSet p)> apiFunc) {
string_view token = nextToken(TokenRequired);
string_view dequoted = dequoteString(token);
std::string n = toString(dequoted);
ParamSet params =
parseParams(nextToken, ungetToken, arena, spectrumType);
parseParams(nextToken, ungetToken, arena);
apiFunc(n, std::move(params));
};

Expand Down Expand Up @@ -875,11 +871,9 @@ static void parse(std::unique_ptr<Tokenizer> t) {
else
syntaxError(tok);
} else if (tok == "AreaLightSource")
basicParamListEntrypoint(SpectrumType::Illuminant,
pbrtAreaLightSource);
basicParamListEntrypoint(pbrtAreaLightSource);
else if (tok == "Accelerator")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtAccelerator);
basicParamListEntrypoint(pbrtAccelerator);
else
syntaxError(tok);
break;
Expand All @@ -899,22 +893,21 @@ static void parse(std::unique_ptr<Tokenizer> t) {
string_view n = dequoteString(nextToken(TokenRequired));
pbrtCoordSysTransform(toString(n));
} else if (tok == "Camera")
basicParamListEntrypoint(SpectrumType::Reflectance, pbrtCamera);
basicParamListEntrypoint(pbrtCamera);
else
syntaxError(tok);
break;

case 'F':
if (tok == "Film")
basicParamListEntrypoint(SpectrumType::Reflectance, pbrtFilm);
basicParamListEntrypoint(pbrtFilm);
else
syntaxError(tok);
break;

case 'I':
if (tok == "Integrator")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtIntegrator);
basicParamListEntrypoint(pbrtIntegrator);
else if (tok == "Include") {
// Switch to the given file.
std::string filename =
Expand All @@ -939,8 +932,7 @@ static void parse(std::unique_ptr<Tokenizer> t) {

case 'L':
if (tok == "LightSource")
basicParamListEntrypoint(SpectrumType::Illuminant,
pbrtLightSource);
basicParamListEntrypoint(pbrtLightSource);
else if (tok == "LookAt") {
Float v[9];
for (int i = 0; i < 9; ++i)
Expand All @@ -953,14 +945,11 @@ static void parse(std::unique_ptr<Tokenizer> t) {

case 'M':
if (tok == "MakeNamedMaterial")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtMakeNamedMaterial);
basicParamListEntrypoint(pbrtMakeNamedMaterial);
else if (tok == "MakeNamedMedium")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtMakeNamedMedium);
basicParamListEntrypoint(pbrtMakeNamedMedium);
else if (tok == "Material")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtMaterial);
basicParamListEntrypoint(pbrtMaterial);
else if (tok == "MediumInterface") {
string_view n = dequoteString(nextToken(TokenRequired));
std::string names[2];
Expand Down Expand Up @@ -1006,8 +995,7 @@ static void parse(std::unique_ptr<Tokenizer> t) {

case 'P':
if (tok == "PixelFilter")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtPixelFilter);
basicParamListEntrypoint(pbrtPixelFilter);
else
syntaxError(tok);
break;
Expand All @@ -1026,10 +1014,9 @@ static void parse(std::unique_ptr<Tokenizer> t) {

case 'S':
if (tok == "Shape")
basicParamListEntrypoint(SpectrumType::Reflectance, pbrtShape);
basicParamListEntrypoint(pbrtShape);
else if (tok == "Sampler")
basicParamListEntrypoint(SpectrumType::Reflectance,
pbrtSampler);
basicParamListEntrypoint(pbrtSampler);
else if (tok == "Scale") {
Float v[3];
for (int i = 0; i < 3; ++i)
Expand Down Expand Up @@ -1067,9 +1054,7 @@ static void parse(std::unique_ptr<Tokenizer> t) {
n = dequoteString(nextToken(TokenRequired));
std::string type = toString(n);

basicParamListEntrypoint(
SpectrumType::Reflectance,
[&](const std::string &texName, const ParamSet &params) {
basicParamListEntrypoint([&](const std::string &texName, const ParamSet &params) {
pbrtTexture(name, type, texName, params);
});
} else
Expand Down