Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use enum name as constant prefix #364

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cl-protobufs.asd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ and functionality for working with them."
:proto-pathname "google/protobuf/any.proto")
(:protobuf-source-file "source_context"
:proto-pathname "google/protobuf/source_context.proto")
(:protobuf-source-file "descriptor"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add descriptor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not saying not to, just asking why)

Copy link
Contributor

@cgay cgay Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already there on lines 78-79.

:proto-pathname "google/protobuf/descriptor.proto")
#-ccl
(:protobuf-source-file "type"
:proto-pathname "google/protobuf/type.proto"
Expand Down
10 changes: 6 additions & 4 deletions define-proto.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ message, and of +<value_name>+ when the enum is defined at top-level."
(let* ((enum-name (symbol-name type))
(dot (position #\. enum-name :test #'char= :from-end t))
;; Use C/C++ enum scope.
(scope (and dot (subseq enum-name 0 dot)))
(scope enum-name
;; (and dot (subseq enum-name 0 dot))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this just commented?

)
(constants
(loop for v in enum-values
for c = (fintern "+~@[~A.~]~A+" scope (enum-value-descriptor-name v))
collect `(defconstant ,c ,(enum-value-descriptor-value v)))))
(loop for v in enum-values
for c = (fintern "+~@[~A.~]~A+" scope (enum-value-descriptor-name v))
collect `(defconstant ,c ,(enum-value-descriptor-value v)))))
`(progn
,@constants
(export ',(mapcar #'second constants)))))
Expand Down
16 changes: 8 additions & 8 deletions tests/enum-mapping-test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ Parameters
(assert-true (eq :zaphod (pb:my-message.my-enum-int-to-keyword 42)))

;; constants
(assert-eql 1 pb:+my-message.foo+)
(assert-eql 2 pb:+my-message.bar+)
(assert-eql 2 pb:+my-message.baz+)
(assert-eql 42 pb:+my-message.zaphod+)
(assert-eql 1 pb:+my-message.my-enum.foo+)
(assert-eql 2 pb:+my-message.my-enum.bar+)
(assert-eql 2 pb:+my-message.my-enum.baz+)
(assert-eql 42 pb:+my-message.my-enum.zaphod+)

;; Error cases.
(assert-false (pb:my-message.my-enum-int-to-keyword 1234))
Expand All @@ -68,10 +68,10 @@ Parameters
(assert-eq :zaphod (pb:outer-enum-int-to-keyword 142))

;; constants
(assert-eql 11 pb:+foo+)
(assert-eql 12 pb:+bar+)
(assert-eql 12 pb:+baz+)
(assert-eql 142 pb:+zaphod+)
(assert-eql 11 pb:+outer-enum.foo+)
(assert-eql 12 pb:+outer-enum.bar+)
(assert-eql 12 pb:+outer-enum.baz+)
(assert-eql 142 pb:+outer-enum.zaphod+)

;; Error cases.
(assert-false (pb:outer-enum-int-to-keyword 1234))
Expand Down