Skip to content

Use lookupYAMLNode to safely check empty config nodes. #301

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions include/chimera/mstch.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class ClangWrapper : public ::mstch::object

virtual ::std::string nameAsString()
{
if (const YAML::Node node = decl_config_["name"])
if (const YAML::Node node
= chimera::util::lookupYAMLNode(decl_config_, "name"))
{
// Convert a `null` to an empty string.
// This helps users semantically mark names that should be
Expand All @@ -108,7 +109,8 @@ class ClangWrapper : public ::mstch::object

virtual ::mstch::node mangledName()
{
if (const YAML::Node node = decl_config_["mangled_name"])
if (const YAML::Node node
= chimera::util::lookupYAMLNode(decl_config_, "mangled_name"))
return node.as<std::string>();

return chimera::util::constructMangledName(decl_);
Expand Down Expand Up @@ -137,7 +139,8 @@ class ClangWrapper : public ::mstch::object

virtual ::mstch::node qualifiedName()
{
if (const YAML::Node node = decl_config_["qualified_name"])
if (const YAML::Node node
= chimera::util::lookupYAMLNode(decl_config_, "qualified_name"))
return node.as<std::string>();

return decl_->getQualifiedNameAsString();
Expand Down
8 changes: 4 additions & 4 deletions include/chimera/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ template <typename... Args>
YAML::Node lookupYAMLNode(const YAML::Node &node, const std::string &key,
Args &&... args)
{
// Return if 'node' is invalid
if (not node)
// Return if 'node' is invalid.
if (!node)
return node;

auto next = node[key];

// Return if failed to find a tag of 'key'
if (not next)
// Return if failed to find a tag of 'key'.
if (!next)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, we don't prefer using not for consistency?

Copy link
Member Author

@psigen psigen Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the not, and, bitand, etc. text versions of the operators are in the c++ spec, but they are not commonly used and IIRC require permissive flags on some compilers like MSVC. So I don't really see a good reason to start using them here.

return next;

// Lookup for the next nested tags
Expand Down
4 changes: 2 additions & 2 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ const std::string &chimera::Configuration::GetOutputModuleName() const
chimera::CompiledConfiguration::CompiledConfiguration(
const chimera::Configuration &parent, CompilerInstance *ci)
: parent_(parent)
, configNode_(parent.GetRoot()) // TODO: do we need this reference?
, bindingNode_(configNode_["template"]) // TODO: is this always ok?
, configNode_(parent.GetRoot()) // TODO: do we need this reference?
, bindingNode_(chimera::util::lookupYAMLNode(configNode_, "template"))
, ci_(ci)
{
// This placeholder will be filled in by the options.strict specified
Expand Down
7 changes: 3 additions & 4 deletions test/examples/01_function/function_boost_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
classes:
'template <typename T> chimera_test::SuppressedTemplateClass': null
'chimera_test::SuppressedClass': null
"template <typename T> chimera_test::SuppressedTemplateClass": null
"chimera_test::SuppressedClass": null
7 changes: 3 additions & 4 deletions test/examples/01_function/function_pybind11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
classes:
'template <typename T> chimera_test::SuppressedTemplateClass': null
'chimera_test::SuppressedClass': null
"template <typename T> chimera_test::SuppressedTemplateClass": null
"chimera_test::SuppressedClass": null
5 changes: 2 additions & 3 deletions test/examples/02_class/class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
'chimera_test::detail': null
"chimera_test": null
"chimera_test::detail": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
classes:
'chimera_test::ExampleShared':
held_type: 'std::shared_ptr<chimera_test::ExampleShared>'
"chimera_test::ExampleShared":
held_type: "std::shared_ptr<chimera_test::ExampleShared>"
7 changes: 3 additions & 4 deletions test/examples/03_smart_pointers/smart_pointers_pybind11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
classes:
'chimera_test::ExampleShared':
held_type: 'std::shared_ptr<chimera_test::ExampleShared>'
"chimera_test::ExampleShared":
held_type: "std::shared_ptr<chimera_test::ExampleShared>"
3 changes: 1 addition & 2 deletions test/examples/04_enumeration/enumeration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
3 changes: 1 addition & 2 deletions test/examples/05_variable/variable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
5 changes: 2 additions & 3 deletions test/examples/20_eigen/eigen_boost_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
# Boost.Python < 1.65.1 doesn't work for Eigen::Map parameter
# Once Boost.Python >= 1.65.1 becomes the minimum required version, remove followings
classes:
'template <typename PlainObjectType, int MapOptions, typename StrideType> class Eigen::Map': null
"template <typename PlainObjectType, int MapOptions, typename StrideType> class Eigen::Map": null
5 changes: 2 additions & 3 deletions test/examples/20_eigen/eigen_pybind11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
template:
file:
header: |
#include <pybind11/eigen.h>
classes:
'template <typename PlainObjectType, int MapOptions, typename StrideType> class Eigen::Map': null
"template <typename PlainObjectType, int MapOptions, typename StrideType> class Eigen::Map": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
"chimera_test":
name: null # TODO: otherwise, import error
"chimera_test": null
types:
"const std::string &":
return_value_policy: copy_const_reference
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
"chimera_test":
name: null # TODO: otherwise, import error
"chimera_test": null
types:
"const std::string &":
return_value_policy: copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
"chimera_test":
name: null # TODO: otherwise, import error
"chimera_test": null
classes:
"chimera_test::Animal":
allow_inheritance: True
3 changes: 1 addition & 2 deletions test/examples/99_dart_example/dart_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'dart':
name: null # TODO: otherwise, import error
"dart":
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ arguments:
- "-extra-arg"
- "-I/usr/lib/clang/3.6/include"
namespaces:
'chimera_test':
name: null # TODO: otherwise, import error
"chimera_test": null