-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'wrap/' changes from 903694b77..b2144a712
b2144a712 Merge pull request #95 from borglab/feature/empty-str-default-arg 9f1e727d8 Merge pull request #96 from borglab/fix/cmake 97ee2ff0c fix CMake typo 64a599827 support empty strings as default args 7b14ed542 Merge pull request #94 from borglab/fix/cmake-messages 0978641fe clean up 5b9272557 Merge pull request #91 from borglab/feature/enums 56e6f48b3 Merge pull request #93 from borglab/feature/better-template 27cc7cebf better cmake messages a6318b567 fix tests b7f60463f remove export_values() 38304fe0a support for class nested enums 348160740 minor fixes 5b6d66a97 use cpp_class and correct module name 2f7ae0676 add newlines and formatting 6e7cecc50 remove support for enum value assignment c1dc925a6 formatting 798732598 better pybind template f6dad2959 pybind_wrapper fixes with formatting 7b4a06560 Merge branch 'master' into feature/enums 1982b7131 more comprehensive tests for enums 3a0eafd66 code for wrapping enums 398780982 tests for enum support git-subtree-dir: wrap git-subtree-split: b2144a712953dcc3e001c97c2ace791149c97278
- Loading branch information
1 parent
56d060b
commit 048666e
Showing
21 changed files
with
399 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, | ||
Atlanta, Georgia 30332-0415 | ||
All Rights Reserved | ||
See LICENSE for the license information | ||
Parser class and rules for parsing C++ enums. | ||
Author: Varun Agrawal | ||
""" | ||
|
||
from pyparsing import delimitedList | ||
|
||
from .tokens import ENUM, IDENT, LBRACE, RBRACE, SEMI_COLON | ||
from .type import Typename | ||
from .utils import collect_namespaces | ||
|
||
|
||
class Enumerator: | ||
""" | ||
Rule to parse an enumerator inside an enum. | ||
""" | ||
rule = ( | ||
IDENT("enumerator")).setParseAction(lambda t: Enumerator(t.enumerator)) | ||
|
||
def __init__(self, name): | ||
self.name = name | ||
|
||
def __repr__(self): | ||
return "Enumerator: ({0})".format(self.name) | ||
|
||
|
||
class Enum: | ||
""" | ||
Rule to parse enums defined in the interface file. | ||
E.g. | ||
``` | ||
enum Kind { | ||
Dog, | ||
Cat | ||
}; | ||
``` | ||
""" | ||
|
||
rule = (ENUM + IDENT("name") + LBRACE + | ||
delimitedList(Enumerator.rule)("enumerators") + RBRACE + | ||
SEMI_COLON).setParseAction(lambda t: Enum(t.name, t.enumerators)) | ||
|
||
def __init__(self, name, enumerators, parent=''): | ||
self.name = name | ||
self.enumerators = enumerators | ||
self.parent = parent | ||
|
||
def namespaces(self) -> list: | ||
"""Get the namespaces which this class is nested under as a list.""" | ||
return collect_namespaces(self) | ||
|
||
def cpp_typename(self): | ||
""" | ||
Return a Typename with the namespaces and cpp name of this | ||
class. | ||
""" | ||
namespaces_name = self.namespaces() | ||
namespaces_name.append(self.name) | ||
return Typename(namespaces_name) | ||
|
||
def __repr__(self): | ||
return "Enum: {0}".format(self.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, | ||
Atlanta, Georgia 30332-0415 | ||
All Rights Reserved | ||
See LICENSE for the license information | ||
Various common utilities. | ||
Author: Varun Agrawal | ||
""" | ||
|
||
|
||
def collect_namespaces(obj): | ||
""" | ||
Get the chain of namespaces from the lowest to highest for the given object. | ||
Args: | ||
obj: Object of type Namespace, Class, InstantiatedClass, or Enum. | ||
""" | ||
namespaces = [] | ||
ancestor = obj.parent | ||
while ancestor and ancestor.name: | ||
namespaces = [ancestor.name] + namespaces | ||
ancestor = ancestor.parent | ||
return [''] + namespaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.