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

View File

@ -86,19 +86,20 @@
encloses this type.") encloses this type.")
(enclosing-class :type (or null symbol string) :initarg :enclosing-class (enclosing-class :type (or null symbol string) :initarg :enclosing-class
:initform nil :accessor cpp-type-enclosing-class :initform nil :accessor cpp-type-enclosing-class
:documentation "A symbol that is a designator for the type :documentation "A symbol or a string that is a designator
of the enclosing class of this type, or NIL if the type has for the type of the enclosing class of this type, or NIL if
no enclosing class.") the type has no enclosing class.")
(name :type (or symbol string) :initarg :name :reader cpp-type-base-name (name :type (or symbol string) :initarg :name :reader cpp-type-base-name
:documentation "Base name of this type.") :documentation "Base name of this type.")
(type-params :type list :initarg :type-params :initform nil (type-params :type list :initarg :type-params :initform nil
:reader cpp-type-type-params :reader cpp-type-type-params
:documentation "List of template parameters that are needed to :documentation "A list of strings naming the template parameters
instantiate a concrete type. For example, in `template that are needed to instantiate a concrete type. For example, in
<TValue> class vector`, 'TValue' is type parameter.") `template <TValue> class vector`, 'TValue' is the type
parameter.")
(type-args :type list :initarg :type-args :initform nil (type-args :type list :initarg :type-args :initform nil
:reader cpp-type-type-args :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 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.")) type argument."))
@ -209,6 +210,8 @@ documentation on `CPP-TYPE' members for function arguments."
(check-type enclosing-class (or null symbol string)) (check-type enclosing-class (or null symbol string))
(check-type type-params list) (check-type type-params list)
(check-type type-args 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 (let ((namespace (if (and namespace
(string= (string-trim +whitespace-chars+ (car namespace)) "")) (string= (string-trim +whitespace-chars+ (car namespace)) ""))
(cdr namespace) (cdr namespace)
@ -420,7 +423,7 @@ CPP-TYPE has no namespace, return an empty string."
(check-type cpp-type cpp-type) (check-type cpp-type cpp-type)
(flet ((enclosing-classes (cpp-type) (flet ((enclosing-classes (cpp-type)
(declare (type cpp-type cpp-type)) (declare (type cpp-type cpp-type))
(let (enclosing) (let ((enclosing '()))
(loop (loop
for class = cpp-type for class = cpp-type
then (find-cpp-class (cpp-type-enclosing-class class)) then (find-cpp-class (cpp-type-enclosing-class class))