LCP: Minor fixes

Summary:
- Rename `type` to `cpp-type` for consistency
- Fix docs
- Guard against simultaneous `type-params` and `type-args`
- Explicitly initialize to the empty list
- Fix test

Reviewers: mtomic, teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1806
This commit is contained in:
Lovro Lugovic 2019-01-15 15:15:44 +01:00
parent f09c1254f4
commit 0436bf77ce
2 changed files with 16 additions and 13 deletions

View File

@ -12,9 +12,9 @@
(is (lcp::parse-cpp-type-declaration type-decl) cpp-type
:test #'lcp::cpp-type=))
(defun decl-test (type-decl type &key (type-params t) (namespace t))
"Test whether the C++ type designated by TYPE prints as TYPE-DECL."
(is (lcp::cpp-type-decl type
(defun decl-test (type-decl cpp-type &key (type-params t) (namespace t))
"Test whether the C++ type designated by CPP-TYPE prints as TYPE-DECL."
(is (lcp::cpp-type-decl cpp-type
:type-params type-params
:namespace namespace)
type-decl))
@ -93,7 +93,7 @@
(decl-test "pair"
(lcp::make-cpp-type
"pair" :type-params '("TIntegral1 TIntegral2"))
"pair" :type-params '("TIntegral1" "TIntegral2"))
:type-params nil))
(subtest "finding defined enums"

View File

@ -86,21 +86,22 @@
encloses this type.")
(enclosing-class :type (or null symbol string) :initarg :enclosing-class
:initform nil :accessor cpp-type-enclosing-class
:documentation "A symbol that is a designator for the type
of the enclosing class of this type, or NIL if the type has
no enclosing class.")
:documentation "A symbol or a string that is a designator
for the type of the enclosing class of this type, or NIL if
the type has no enclosing class.")
(name :type (or symbol string) :initarg :name :reader cpp-type-base-name
:documentation "Base name of this type.")
(type-params :type list :initarg :type-params :initform nil
:reader cpp-type-type-params
:documentation "List of template parameters that are needed to
instantiate a concrete type. For example, in `template
<TValue> class vector`, 'TValue' is type parameter.")
:documentation "A list of strings naming the template parameters
that are needed to instantiate a concrete type. For example, in
`template <TValue> class vector`, 'TValue' is the type
parameter.")
(type-args :type list :initarg :type-args :initform nil
:reader cpp-type-type-args
:documentation "List of `CPP-TYPE' instances that represent the
:documentation "A list of `CPP-TYPE' instances that represent the
template type arguments used within the instantiation of the
template. For example in `std::vector<int>`, 'int' is a template
template. For example in `std::vector<int>`, 'int' is a template
type argument."))
(:documentation "Base class for meta information on C++ types."))
@ -209,6 +210,8 @@ documentation on `CPP-TYPE' members for function arguments."
(check-type enclosing-class (or null symbol string))
(check-type type-params list)
(check-type type-args list)
(when (and type-params type-args)
(error "A CPP-TYPE can't have both of TYPE-PARAMS and TYPE-ARGS"))
(let ((namespace (if (and namespace
(string= (string-trim +whitespace-chars+ (car namespace)) ""))
(cdr namespace)
@ -420,7 +423,7 @@ CPP-TYPE has no namespace, return an empty string."
(check-type cpp-type cpp-type)
(flet ((enclosing-classes (cpp-type)
(declare (type cpp-type cpp-type))
(let (enclosing)
(let ((enclosing '()))
(loop
for class = cpp-type
then (find-cpp-class (cpp-type-enclosing-class class))