Skip to content

Commit

Permalink
Squashed 'wrap/' changes from d6350c214..0ab10c359
Browse files Browse the repository at this point in the history
0ab10c359 Fix pyparsing version and replace `create_symlinks` with `copy_directory` (#128)
230a3c967 Merge pull request #127 from borglab/feature/template-instantiator
cc7d9a8b4 breakdown template instantiator into smaller submodules
59536220a Merge pull request #126 from borglab/feature/instantiation-tests
7ee715ecc add type info to template_instantiator
b367ed93d tests for InstantiationHelper
e41cfd50e tests for InstantiatedGlobalFunction
1837982a7 tests for InstantiatedClass
a7e3678a3 tests for InstantiatedStaticMethod
da06c53f7 tests for InstantiatedMethod
c645c143c tests for InstantiatedConstructor
b8a046267 tests for InstantiatedDeclaration
af80c9d04 finish all tests for namespace level instantiation
d6085c37a add tests for high level template instantiation
f7ae91346 add docs and utility method
d90abb52b Merge pull request #125 from borglab/feature/templated-static
58cdab20d clean up
247cea727 add helper for multilevel instantiation
761f588e4 update tests
81e5d5d19 update pybind wrapper to use new way
96d1575d8 streamlined way of instantiating template for class methods
1e4e88799 add to_cpp method for Method
485d43138 add the test fixtures
8cb943635 support instantiation of static method templates
84ef6679b add template to static method parser

git-subtree-dir: wrap
git-subtree-split: 0ab10c359a6528def20eddc60aced74a04250419
  • Loading branch information
varunagrawal committed Oct 25, 2021
1 parent 4307b84 commit c195bb5
Show file tree
Hide file tree
Showing 30 changed files with 1,758 additions and 918 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ jobs:

- name: Python Dependencies
run: |
pip3 install -U pip setuptools
pip3 install -r requirements.txt
- name: Build and Test
run: |
# Build
cmake .
cd tests
# Use Pytest to run all the tests.
Expand Down
30 changes: 6 additions & 24 deletions cmake/PybindWrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ function(install_python_files source_files dest_directory)
endfunction()

# ~~~
# https://stackoverflow.com/questions/13959434/cmake-out-of-source-build-python-files
# Copy over the directory from source_folder to dest_foler
# ~~~
function(create_symlinks source_folder dest_folder)
function(copy_directory source_folder dest_folder)
if(${source_folder} STREQUAL ${dest_folder})
return()
endif()
Expand All @@ -215,31 +215,13 @@ function(create_symlinks source_folder dest_folder)
# Create REAL folder
file(MAKE_DIRECTORY "${dest_folder}")

# Delete symlink if it exists
# Delete if it exists
file(REMOVE "${dest_folder}/${path_file}")

# Get OS dependent path to use in `execute_process`
file(TO_NATIVE_PATH "${dest_folder}/${path_file}" link)
# Get OS dependent path to use in copy
file(TO_NATIVE_PATH "${source_folder}/${path_file}" target)

# cmake-format: off
if(UNIX)
set(command ln -s ${target} ${link})
else()
set(command cmd.exe /c mklink ${link} ${target})
endif()
# cmake-format: on

execute_process(
COMMAND ${command}
RESULT_VARIABLE result
ERROR_VARIABLE output)

if(NOT ${result} EQUAL 0)
message(
FATAL_ERROR
"Could not create symbolic link for: ${target} --> ${output}")
endif()
file(COPY ${target} DESTINATION ${dest_folder})

endforeach(path_file)
endfunction(create_symlinks)
endfunction(copy_directory)
13 changes: 10 additions & 3 deletions gtwrap/interface_parser/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def __init__(self,

self.parent = parent

def to_cpp(self) -> str:
"""Generate the C++ code for wrapping."""
return self.name

def __repr__(self) -> str:
return "Method: {} {} {}({}){}".format(
self.template,
Expand All @@ -84,24 +88,27 @@ class Hello {
```
"""
rule = (
STATIC #
Optional(Template.rule("template")) #
+ STATIC #
+ ReturnType.rule("return_type") #
+ IDENT("name") #
+ LPAREN #
+ ArgumentList.rule("args_list") #
+ RPAREN #
+ SEMI_COLON # BR
).setParseAction(
lambda t: StaticMethod(t.name, t.return_type, t.args_list))
lambda t: StaticMethod(t.name, t.return_type, t.args_list, t.template))

def __init__(self,
name: str,
return_type: ReturnType,
args: ArgumentList,
template: Union[Template, Any] = None,
parent: Union["Class", Any] = ''):
self.name = name
self.return_type = return_type
self.args = args
self.template = template

self.parent = parent

Expand Down Expand Up @@ -221,8 +228,8 @@ class Members:
Rule for all the members within a class.
"""
rule = ZeroOrMore(Constructor.rule #
^ StaticMethod.rule #
^ Method.rule #
^ StaticMethod.rule #
^ Variable.rule #
^ Operator.rule #
^ Enum.rule #
Expand Down
5 changes: 5 additions & 0 deletions gtwrap/interface_parser/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class Type:
"""
Parsed datatype, can be either a fundamental type or a custom datatype.
E.g. void, double, size_t, Matrix.
Think of this as a high-level type which encodes the typename and other
characteristics of the type.
The type can optionally be a raw pointer, shared pointer or reference.
Can also be optionally qualified with a `const`, e.g. `const int`.
Expand Down Expand Up @@ -240,6 +242,9 @@ def to_cpp(self, use_boost: bool) -> str:
or self.typename.name in ["Matrix", "Vector"]) else "",
typename=typename))

def get_typename(self):
"""Convenience method to get the typename of this type."""
return self.typename.name

class TemplatedType:
"""
Expand Down
4 changes: 2 additions & 2 deletions gtwrap/matlab_wrapper/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _format_type_name(self,

if separator == "::": # C++
templates = []
for idx in range(len(type_name.instantiations)):
for idx, _ in enumerate(type_name.instantiations):
template = '{}'.format(
self._format_type_name(type_name.instantiations[idx],
include_namespace=include_namespace,
Expand All @@ -124,7 +124,7 @@ def _format_type_name(self,
formatted_type_name += '<{}>'.format(','.join(templates))

else:
for idx in range(len(type_name.instantiations)):
for idx, _ in enumerate(type_name.instantiations):
formatted_type_name += '{}'.format(
self._format_type_name(type_name.instantiations[idx],
separator=separator,
Expand Down
7 changes: 5 additions & 2 deletions gtwrap/pybind_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ def _wrap_method(self,
if py_method in self.python_keywords:
py_method = py_method + "_"

is_method = isinstance(method, instantiator.InstantiatedMethod)
is_static = isinstance(method, parser.StaticMethod)
is_method = isinstance(
method, (parser.Method, instantiator.InstantiatedMethod))
is_static = isinstance(
method,
(parser.StaticMethod, instantiator.InstantiatedStaticMethod))
return_void = method.return_type.is_void()
args_names = method.args.names()
py_args_names = self._py_args_names(method.args)
Expand Down
Loading

0 comments on commit c195bb5

Please sign in to comment.