Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Now that expression operator name is stored in the signature, don't p…
Browse files Browse the repository at this point in the history
…ass name into `makeExpression`.
  • Loading branch information
ChrisLoer committed Feb 9, 2018
1 parent 621e235 commit a3cc7b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
5 changes: 2 additions & 3 deletions include/mbgl/style/expression/compound_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct SignatureBase {
name(std::move(name_))
{}
virtual ~SignatureBase() = default;
virtual std::unique_ptr<Expression> makeExpression(const std::string& name, std::vector<std::unique_ptr<Expression>>) const = 0;
virtual std::unique_ptr<Expression> makeExpression(std::vector<std::unique_ptr<Expression>>) const = 0;
type::Type result;
variant<std::vector<type::Type>, VarargsType> params;
std::string name;
Expand Down Expand Up @@ -134,8 +134,7 @@ struct CompoundExpressionRegistry {

ParseResult parseCompoundExpression(const std::string name, const mbgl::style::conversion::Convertible& value, ParsingContext& ctx);

ParseResult createCompoundExpression(const std::string& name,
const CompoundExpressionRegistry::Definition& definition,
ParseResult createCompoundExpression(const CompoundExpressionRegistry::Definition& definition,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx);

Expand Down
22 changes: 9 additions & 13 deletions src/mbgl/style/expression/compound_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ struct Signature<R (Params...)> : SignatureBase {
return applyImpl(evaluationParameters, args, std::index_sequence_for<Params...>{});
}

std::unique_ptr<Expression> makeExpression(const std::string& name_,
std::vector<std::unique_ptr<Expression>> args) const override {
std::unique_ptr<Expression> makeExpression(std::vector<std::unique_ptr<Expression>> args) const override {
typename Signature::Args argsArray;
std::copy_n(std::make_move_iterator(args.begin()), sizeof...(Params), argsArray.begin());
return std::make_unique<CompoundExpression<Signature>>(name_, *this, std::move(argsArray));
return std::make_unique<CompoundExpression<Signature>>(name, *this, std::move(argsArray));
}

R (*evaluate)(Params...);
Expand Down Expand Up @@ -89,8 +88,7 @@ struct Signature<R (const Varargs<T>&)> : SignatureBase {
evaluate(evaluate_)
{}

std::unique_ptr<Expression> makeExpression(const std::string& name,
std::vector<std::unique_ptr<Expression>> args) const override {
std::unique_ptr<Expression> makeExpression(std::vector<std::unique_ptr<Expression>> args) const override {
return std::make_unique<CompoundExpression<Signature>>(name, *this, std::move(args));
};

Expand Down Expand Up @@ -125,11 +123,10 @@ struct Signature<R (const EvaluationContext&, Params...)> : SignatureBase {
evaluate(evaluate_)
{}

std::unique_ptr<Expression> makeExpression(const std::string& name_, // TODO: Is this different from what we store locally?
std::vector<std::unique_ptr<Expression>> args) const override {
std::unique_ptr<Expression> makeExpression(std::vector<std::unique_ptr<Expression>> args) const override {
typename Signature::Args argsArray;
std::copy_n(std::make_move_iterator(args.begin()), sizeof...(Params), argsArray.begin());
return std::make_unique<CompoundExpression<Signature>>(name_, *this, std::move(argsArray));
return std::make_unique<CompoundExpression<Signature>>(name, *this, std::move(argsArray));
}

EvaluationResult apply(const EvaluationContext& evaluationParameters, const Args& args) const {
Expand Down Expand Up @@ -463,20 +460,19 @@ ParseResult parseCompoundExpression(const std::string name, const Convertible& v
}
args.push_back(std::move(*parsed));
}
return createCompoundExpression(name, definition, std::move(args), ctx);
return createCompoundExpression(definition, std::move(args), ctx);
}


ParseResult createCompoundExpression(const std::string& name,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx)
{
return createCompoundExpression(name, CompoundExpressionRegistry::definitions.at(name), std::move(args), ctx);
return createCompoundExpression(CompoundExpressionRegistry::definitions.at(name), std::move(args), ctx);
}


ParseResult createCompoundExpression(const std::string& name,
const Definition& definition,
ParseResult createCompoundExpression(const Definition& definition,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx)
{
Expand Down Expand Up @@ -514,7 +510,7 @@ ParseResult createCompoundExpression(const std::string& name,
}

if (signatureContext.getErrors().size() == 0) {
return ParseResult(signature->makeExpression(name, std::move(args)));
return ParseResult(signature->makeExpression(std::move(args)));
}
}

Expand Down

0 comments on commit a3cc7b4

Please sign in to comment.