-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #749 from borglab/feature/wrap-update
- Loading branch information
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.