From 9de7bb1e65940e997fd425bf6b9ebc4f42b6c54d Mon Sep 17 00:00:00 2001 From: thibault Date: Tue, 10 Nov 2020 00:07:09 -0500 Subject: [PATCH] Move to robotpy-cppheaderparser --- README.rst | 2 +- doc/source/conf.py | 6 +- doc/source/index.rst | 2 +- doc/source/org-doc.rst | 125 ++++++++++++------------------- hpp2plantuml.org | 108 ++++++++++++-------------- setup.py | 2 +- src/hpp2plantuml/__init__.py | 2 +- src/hpp2plantuml/hpp2plantuml.py | 41 +++------- tests/simple_classes_1_2.hpp | 1 + tests/test_hpp2plantuml.py | 15 ++-- 10 files changed, 126 insertions(+), 178 deletions(-) diff --git a/README.rst b/README.rst index 8e6d1f2..60a29e5 100644 --- a/README.rst +++ b/README.rst @@ -25,7 +25,7 @@ hierarchies. It aims at supporting: - dependency relationships -The package relies on the `CppHeaderParser `_ package for parsing of C++ header +The package relies on the `CppHeaderParser `_ package for parsing of C++ header files. diff --git a/doc/source/conf.py b/doc/source/conf.py index abbf66b..2d8710a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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. @@ -155,7 +155,7 @@ # The name for this set of Sphinx documents. # " v 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. # diff --git a/doc/source/index.rst b/doc/source/index.rst index 49ac472..024f4bb 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -30,7 +30,7 @@ hierarchies. It aims at supporting: - dependency relationships -The package relies on the `CppHeaderParser `_ package for parsing of C++ header +The package relies on the `CppHeaderParser `_ package for parsing of C++ header files. diff --git a/doc/source/org-doc.rst b/doc/source/org-doc.rst index 42c2c62..c33c7a9 100644 --- a/doc/source/org-doc.rst +++ b/doc/source/org-doc.rst @@ -13,7 +13,7 @@ The current version of the code is: :: :name: hpp2plantuml-version - 0.6 + 0.7 The source code can be found on GitHub: @@ -43,7 +43,7 @@ hierarchies. It aims at supporting: - dependency relationships -The package relies on the `CppHeaderParser `_ package for parsing of C++ header +The package relies on the `CppHeaderParser `_ package for parsing of C++ header files. License @@ -82,18 +82,18 @@ Requirements ------------ This module has mostly standard dependencies; the only exception is the -`CppHeaderParser `_ module used to parse header files. +`CppHeaderParser `_ module used to parse header files. .. table:: List of dependencies. :name: py-dependency-list - +-----------------+ - | 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`_): @@ -104,7 +104,7 @@ block (returning either imports or a dependency list used in `sec-package-setup- (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 @@ -190,7 +190,6 @@ of elementary properties and links. # - 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)] ] @@ -216,7 +215,8 @@ Base 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, @@ -274,7 +274,7 @@ The ``Container`` class is abstract and contains: Parameters ---------- - header_container : CppClass, CppStruct or CppEnum + header_container : CppClass or CppEnum Parsed header for container """ namespace = header_container.get('namespace', None) @@ -290,7 +290,7 @@ The ``Container`` class is abstract and contains: Parameters ---------- - header_container : CppClass, CppStruct or CppEnum + header_container : CppClass or CppEnum Parsed header for container """ raise NotImplementedError( @@ -439,7 +439,7 @@ which is used to determine aggregation relationships between classes. 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]: @@ -467,8 +467,9 @@ which is used to determine aggregation relationships between classes. 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 @@ -730,38 +731,6 @@ implemented in the future. return method_str -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. - -.. code:: python - :name: py-render-structs - - # %% 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') - Enumeration lists ^^^^^^^^^^^^^^^^^ @@ -1618,8 +1587,9 @@ variable types by eliminating spaces around ``\*`` characters. 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))) The ``_cleanup_single_line`` function transforms a multiline input string into a single string version. @@ -1864,7 +1834,7 @@ to parse input arguments. The function passes the command line arguments to the 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, @@ -2129,7 +2099,7 @@ the representation of variables. 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) @@ -2174,7 +2144,7 @@ supported by PlantUML. 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) @@ -2192,19 +2162,21 @@ TableĀ `tbl-unittest-class`_. It includes templates and abstract classes. .. table:: List of test segments and corresponding PlantUML strings. :name: tbl-unittest-class - +-----------------------------------------------------------------------+----------------------------------------------------------------------------------------+ - | 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 class Test{\nT* func(T& arg); };" | "class Test