Skip to content

Commit

Permalink
Use #define macros instead of writing CSSPropertyAPI declarations twice
Browse files Browse the repository at this point in the history
This allows easier modification of the CSSPropertyAPI.cpp code, while
still allowing compilation with MSVC.

CSSPropertyAPI.cpp diff:
https://www.diffchecker.com/0sgwYXEK

Bug: 545324
Change-Id: I7c86f1c8e05d41364cec4bc70018b89cf200a3ea
Reviewed-on: https://chromium-review.googlesource.com/631298
Commit-Queue: meade_UTC10 <meade@chromium.org>
Reviewed-by: Renée Wright <rjwright@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496971}
  • Loading branch information
wilddamon authored and Commit Bot committed Aug 24, 2017
1 parent 5bd2a34 commit d3de333
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,28 @@ namespace {
// real builds using MSVC, and this is just to avoid crashing bots that
// still need to use MSVC (e.g. for the dEQP tests, which use exceptions).
// See http://crbug.com/753010.

{% for api_class in api_classnames %}
static const {{api_class}} api_{{api_class.lower()}};
{% endfor %}
#define STATIC_CONSTEXPR static const
#define STATIC_CONSTEXPR_CONST static const
#else
#define STATIC_CONSTEXPR static constexpr
#define STATIC_CONSTEXPR_CONST static constexpr const
#endif

{% for api_class in api_classnames %}
static constexpr {{api_class}} api_{{api_class.lower()}};
STATIC_CONSTEXPR {{api_class}} api_{{api_class.lower()}};
{% endfor %}
#endif

const CSSPropertyAPI& GetAPI(CSSPropertyID id) {
#if defined(OS_WIN) && defined(COMPILER_MSVC)
static const CSSPropertyAPI* const property_apis[] = {
STATIC_CONSTEXPR_CONST CSSPropertyAPI* const property_apis[] = {
{% for api_class_data in api_classes_by_property_id %}
&api_{{api_class_data.classname.lower()}}, // {{api_class_data.property_id}}
{% endfor %}
};
#else
static constexpr const CSSPropertyAPI* const property_apis[] = {
{% for api_class_data in api_classes_by_property_id %}
&api_{{api_class_data.classname.lower()}}, // {{api_class_data.property_id}}
{% endfor %}
};
#endif
// Subtract 1 because CSSPropertyInvalid does not appear in the array.
return *property_apis[id - 1];
}
#undef STATIC_CONSTEXPR
#undef STATIC_CONSTEXPR_CONST

} // namespace

Expand Down

0 comments on commit d3de333

Please sign in to comment.