Skip to content

Commit

Permalink
Move to robotpy-cppheaderparser
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Nov 10, 2020
1 parent 0a204d8 commit 9de7bb1
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 178 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hierarchies. It aims at supporting:

- dependency relationships

The package relies on the `CppHeaderParser <http://senexcanis.com/open-source/cppheaderparser/>`_ package for parsing of C++ header
The package relies on the `CppHeaderParser <https://pypi.org/project/robotpy-cppheaderparser/>`_ package for parsing of C++ header
files.


Expand Down
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
# built documents.
#
# The short X.Y version.
version = u'v' + u'0.6'
version = u'v' + u'0.7'
# The full version, including alpha/beta/rc tags.
release = u'v' + u'0.6'
release = u'v' + u'0.7'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -155,7 +155,7 @@
# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#
# html_title = u'hpp2plantuml ' + u'v' + u'0.6'
# html_title = u'hpp2plantuml ' + u'v' + u'0.7'

# A shorter title for the navigation bar. Default is the same as html_title.
#
Expand Down
2 changes: 1 addition & 1 deletion doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ hierarchies. It aims at supporting:

- dependency relationships

The package relies on the `CppHeaderParser <http://senexcanis.com/open-source/cppheaderparser/>`_ package for parsing of C++ header
The package relies on the `CppHeaderParser <https://pypi.org/project/robotpy-cppheaderparser/>`_ package for parsing of C++ header
files.


Expand Down
125 changes: 49 additions & 76 deletions doc/source/org-doc.rst

Large diffs are not rendered by default.

108 changes: 49 additions & 59 deletions hpp2plantuml.org
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ this single org-file.

The current version of the code is:
#+NAME: hpp2plantuml-version
: 0.6
: 0.7

The source code can be found on GitHub:
https://github.com/thibaultmarin/hpp2plantuml.
Expand All @@ -40,7 +40,7 @@ hierarchies. It aims at supporting:
- aggregation relationships (very basic support).
- dependency relationships

The package relies on the [[http://senexcanis.com/open-source/cppheaderparser/][CppHeaderParser]] package for parsing of C++ header
The package relies on the [[https://pypi.org/project/robotpy-cppheaderparser/][CppHeaderParser]] package for parsing of C++ header
files.


Expand Down Expand Up @@ -79,13 +79,13 @@ THE SOFTWARE.
* DONE Requirements

This module has mostly standard dependencies; the only exception is the
[[http://senexcanis.com/open-source/cppheaderparser/][CppHeaderParser]] module used to parse header files.
[[https://pypi.org/project/robotpy-cppheaderparser/][CppHeaderParser]] module used to parse header files.

#+NAME: py-dependency-list
#+CAPTION: List of dependencies.
| argparse |
| CppHeaderParser |
| jinja2 |
| argparse | argparse |
| robotpy-cppheaderparser | CppHeaderParser |
| jinja2 | jinja2 |

The full list of non-standard dependencies is produced by the following source
block (returning either imports or a dependency list used in [[#sec-package-setup-py][=setup.py=]]):
Expand All @@ -95,7 +95,7 @@ block (returning either imports or a dependency list used in [[#sec-package-setu
(cond
((string= output "import")
(mapconcat
(lambda (el) (concat "import " (car el))) dep-list "\n"))
(lambda (el) (concat "import " (cadr el))) dep-list "\n"))
((string= output "requirements")
(concat "["
(mapconcat
Expand Down Expand Up @@ -178,7 +178,6 @@ LINK_TYPE_MAP = {
# - The third element is a function returning the corresponding internal object
CONTAINER_TYPE_MAP = [
['classes', lambda objs: objs.items(), lambda obj: Class(obj)],
['structs', lambda objs: objs.items(), lambda obj: Struct(obj)],
['enums', lambda objs: objs, lambda obj: Enum(obj)]
]
#+END_SRC
Expand All @@ -203,7 +202,8 @@ class.

C++ objects are represented by objects derived from the base ~Container~ class.
The ~Container~ class is abstract and contains:
- the container type (~class~, ~enum~, ~struct~),
- the container type (~class~, ~enum~, ~struct~ objects are handled as ~class~
objects),
- the object name,
- a list of members (e.g. class variable or method for a class object),
- a ~parse_members~ method which can build the list of members from a parsed
Expand Down Expand Up @@ -256,7 +256,7 @@ class Container(object):

Parameters
----------
header_container : CppClass, CppStruct or CppEnum
header_container : CppClass or CppEnum
Parsed header for container
"""
namespace = header_container.get('namespace', None)
Expand All @@ -272,7 +272,7 @@ class Container(object):

Parameters
----------
header_container : CppClass, CppStruct or CppEnum
header_container : CppClass or CppEnum
Parsed header for container
"""
raise NotImplementedError(
Expand Down Expand Up @@ -421,7 +421,7 @@ class Class(Container):
element is the class name and the second element is a CppClass
object)
"""
super().__init__('class', header_class[0])
super().__init__(header_class[1]['declaration_method'], header_class[0])
self._abstract = header_class[1]['abstract']
self._template_type = None
if 'template' in header_class[1]:
Expand Down Expand Up @@ -449,8 +449,9 @@ class Class(Container):
for member_prop in MEMBER_PROP_MAP.keys():
member_list = header_class[member_type][member_prop]
for header_member in member_list:
self._member_list.append(
member_type_handler(header_member, member_prop))
if not header_member.get('deleted', False):
self._member_list.append(
member_type_handler(header_member, member_prop))

def build_variable_type_list(self):
"""Get type of member variables
Expand Down Expand Up @@ -717,38 +718,6 @@ class ClassMethod(ClassMember):
#+END_SRC


*** DONE Structures

While ~struct~ objects are currently not supported, their addition should be
relatively straightforward and the ~Struct~ class may simply inherit from the
~Class~ class. The following should give a starting point.

#+NAME: py-render-structs
#+BEGIN_SRC python
# %% Struct object


class Struct(Class):
"""Representation of C++ struct objects

This class derived is almost identical to `Class`, the only difference
being the container type name ("struct" instead of "class").
"""
def __init__(self, header_struct):
"""Class constructor

Parameters
----------
header_struct : list (str, CppStruct)
Parsed header for struct object (two-element list where the first
element is the structure name and the second element is a CppStruct
object)
"""
super().__init__(header_struct[0])
super(Class).__init__('struct')
#+END_SRC


*** DONE Enumeration lists

The ~Enum~ class representing enumeration object is a trivial extension of the
Expand Down Expand Up @@ -1594,8 +1563,9 @@ def _cleanup_type(type_str):
str
The type string after cleanup
"""
return re.sub(r'[ ]+([*&])', r'\1',
re.sub(r'(\s)+', r'\1', type_str))
return re.sub('\s*([<>])\s*', r'\1',
re.sub(r'[ ]+([*&])', r'\1',
re.sub(r'(\s)+', r'\1', type_str)))
#+END_SRC

The ~_cleanup_single_line~ function transforms a multiline input string into a
Expand Down Expand Up @@ -2094,7 +2064,7 @@ class TestClassVariable:
for test_idx, (input_str, output_ref_str) in \
enumerate(fix_test_list_def(test_list_classvar)):
p = get_parsed_element(input_str)
class_name = re.sub(r'.*class\s*(\w+).*', r'\1',
class_name = re.sub(r'.*(class|struct)\s*(\w+).*', r'\2',
input_str.replace('\n', ' '))
class_input = [class_name, p.classes[class_name]]
obj_c = hpp2plantuml.hpp2plantuml.Class(class_input)
Expand Down Expand Up @@ -2132,7 +2102,7 @@ class TestClassMethod:
for test_idx, (input_str, output_ref_str) in \
enumerate(fix_test_list_def(test_list_classmethod)):
p = get_parsed_element(input_str)
class_name = re.sub(r'.*class\s*(\w+).*', r'\1',
class_name = re.sub(r'.*(class|struct)\s*(\w+).*', r'\2',
input_str.replace('\n', ' '))
class_input = [class_name, p.classes[class_name]]
obj_c = hpp2plantuml.hpp2plantuml.Class(class_input)
Expand All @@ -2150,13 +2120,14 @@ Table{{{tt}}}[[tbl-unittest-class]]. It includes templates and abstract classes

#+NAME: tbl-unittest-class
#+CAPTION: List of test segments and corresponding PlantUML strings.
| C++ | plantuml |
|-----------------------------------------------------------------------+---------------------------------------------------------------------------------------|
| "class Test {\nprotected:\nint & member; };" | "class Test {\n\t#member : int&\n}\n" |
| "class Test\n{\npublic:\nvirtual int func() = 0; };" | "abstract class Test {\n\t+{abstract} func() : int\n}\n" |
| "template <typename T> class Test{\nT* func(T& arg); };" | "class Test <template <typename T>> {\n\t-func(T& arg) : T*\n}\n" |
| "template <typename T> class Test{\nvirtual T* func(T& arg)=0; };" | "abstract class Test <template <typename T>> {\n\t-{abstract} func(T& arg) : T*\n}\n" |
| "namespace Interface {\nclass Test {\nprotected:\nint & member; };};" | "namespace Interface {\n\tclass Test {\n\t\t#member : int&\n\t}\n}\n" |
| C++ | plantuml |
|-----------------------------------------------------------------------+--------------------------------------------------------------------------------------|
| "class Test {\nprotected:\nint & member; };" | "class Test {\n\t#member : int&\n}\n" |
| "struct Test {\nprotected:\nint & member; };" | "struct Test {\n\t#member : int&\n}\n" |
| "class Test\n{\npublic:\nvirtual int func() = 0; };" | "abstract class Test {\n\t+{abstract} func() : int\n}\n" |
| "template <typename T> class Test{\nT* func(T& arg); };" | "class Test <template<typename T>> {\n\t-func(T& arg) : T*\n}\n" |
| "template <typename T> class Test{\nvirtual T* func(T& arg)=0; };" | "abstract class Test <template<typename T>> {\n\t-{abstract} func(T& arg) : T*\n}\n" |
| "namespace Interface {\nclass Test {\nprotected:\nint & member; };};" | "namespace Interface {\n\tclass Test {\n\t\t#member : int&\n\t}\n}\n" |

#+NAME: test-unit-class
#+BEGIN_SRC python :var test_list_class=tbl-unittest-class
Expand All @@ -2168,7 +2139,7 @@ class TestClass:
for test_idx, (input_str, output_ref_str) in \
enumerate(fix_test_list_def(test_list_class)):
p = get_parsed_element(input_str)
class_name = re.sub(r'.*class\s*(\w+).*', r'\1',
class_name = re.sub(r'.*(class|struct)\s*(\w+).*', r'\2',
input_str.replace('\n', ' '))
class_input = [class_name, p.classes[class_name]]
obj_c = hpp2plantuml.hpp2plantuml.Class(class_input)
Expand Down Expand Up @@ -2284,6 +2255,7 @@ protected:
static bool _StaticProtectedMethod(bool param);
virtual bool _AbstractMethod(int param) = 0;
public:
Class01& operator=(const Class01&) & = delete;
int public_var;
bool PublicMethod(int param) const;
static bool StaticPublicMethod(bool param);
Expand Down Expand Up @@ -3598,7 +3570,7 @@ encapsulated in the following source block.

- [-] Add tests
- [ ] Add test coverage report to documentation (full test from within org-mode?)
- [ ] Test structs
- [X] Test structs
- [X] Unit tests
- [X] Full diagram test
- [ ] Extra files for package
Expand All @@ -3620,6 +3592,24 @@ encapsulated in the following source block.
- [X] creates documentation rst (and README.rst)
- [X] Link to org-mode rst documentation from index.rst -> Use only org-mode rst?

** v0.7

*** DONE Handle =delete= keyword
CLOSED: [2020-11-10 Tue 00:03]

https://github.com/thibaultmarin/hpp2plantuml/issues/8

*** DONE Use CppHeaderParser fork with support for C++11
CLOSED: [2020-11-10 Tue 00:03]

https://github.com/thibaultmarin/hpp2plantuml/issues/7

*** Notes

The change of parser (from =CppHeaderParser= to =robotpy-cppheaderparser=)
results in minor whitespace changes in the rendered plantuml content
(e.g. ~<template <typename T>>~ becomes ~<template<typename T>>~).

** v0.6

*** DONE Rename =do_parsed_member=
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
]
INSTALL_REQUIRES = ['argparse', 'CppHeaderParser', 'jinja2']
INSTALL_REQUIRES = ['argparse', 'robotpy-cppheaderparser', 'jinja2']
INSTALL_REQUIRES += ['sphinx', ]
SETUP_REQUIRES = ['sphinx', 'numpydoc']
###################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/hpp2plantuml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

__title__ = "hpp2plantuml"
__description__ = "Convert C++ header files to PlantUML"
__version__ = '0.6'
__version__ = '0.7'
__uri__ = "https://github.com/thibaultmarin/hpp2plantuml"
__doc__ = __description__ + " <" + __uri__ + ">"
__author__ = "Thibault Marin"
Expand Down
41 changes: 10 additions & 31 deletions src/hpp2plantuml/hpp2plantuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# - The third element is a function returning the corresponding internal object
CONTAINER_TYPE_MAP = [
['classes', lambda objs: objs.items(), lambda obj: Class(obj)],
['structs', lambda objs: objs.items(), lambda obj: Struct(obj)],
['enums', lambda objs: objs, lambda obj: Enum(obj)]
]

Expand Down Expand Up @@ -77,7 +76,7 @@ def parse_members(self, header_container):
Parameters
----------
header_container : CppClass, CppStruct or CppEnum
header_container : CppClass or CppEnum
Parsed header for container
"""
namespace = header_container.get('namespace', None)
Expand All @@ -93,7 +92,7 @@ def _do_parse_members(self, header_container):
Parameters
----------
header_container : CppClass, CppStruct or CppEnum
header_container : CppClass or CppEnum
Parsed header for container
"""
raise NotImplementedError(
Expand Down Expand Up @@ -223,7 +222,7 @@ def __init__(self, header_class):
element is the class name and the second element is a CppClass
object)
"""
super().__init__('class', header_class[0])
super().__init__(header_class[1]['declaration_method'], header_class[0])
self._abstract = header_class[1]['abstract']
self._template_type = None
if 'template' in header_class[1]:
Expand Down Expand Up @@ -251,8 +250,9 @@ def _do_parse_members(self, header_class):
for member_prop in MEMBER_PROP_MAP.keys():
member_list = header_class[member_type][member_prop]
for header_member in member_list:
self._member_list.append(
member_type_handler(header_member, member_prop))
if not header_member.get('deleted', False):
self._member_list.append(
member_type_handler(header_member, member_prop))

def build_variable_type_list(self):
"""Get type of member variables
Expand Down Expand Up @@ -467,28 +467,6 @@ def _render_name(self):

return method_str

# %% Struct object


class Struct(Class):
"""Representation of C++ struct objects
This class derived is almost identical to `Class`, the only difference
being the container type name ("struct" instead of "class").
"""
def __init__(self, header_struct):
"""Class constructor
Parameters
----------
header_struct : list (str, CppStruct)
Parsed header for struct object (two-element list where the first
element is the structure name and the second element is a CppStruct
object)
"""
super().__init__(header_struct[0])
super(Class).__init__('struct')

# %% Enum object


Expand Down Expand Up @@ -1190,8 +1168,9 @@ def _cleanup_type(type_str):
str
The type string after cleanup
"""
return re.sub(r'[ ]+([*&])', r'\1',
re.sub(r'(\s)+', r'\1', type_str))
return re.sub('\s*([<>])\s*', r'\1',
re.sub(r'[ ]+([*&])', r'\1',
re.sub(r'(\s)+', r'\1', type_str)))

# %% Single line version of string

Expand Down Expand Up @@ -1319,7 +1298,7 @@ def main():
required=False, default=None, metavar='JINJA-FILE',
help='path to jinja2 template file')
parser.add_argument('--version', action='version',
version='%(prog)s ' + '0.6')
version='%(prog)s ' + '0.7')
args = parser.parse_args()
if len(args.input_files) > 0:
CreatePlantUMLFile(args.input_files, args.output_file,
Expand Down
Loading

0 comments on commit 9de7bb1

Please sign in to comment.