hidl-gen: understand doc comments

Doc comments were used by hidl-doc in order to
generate documentation. However, because hidl-doc
tokenizes the entire file including the comments
some of the information is lost. Rather than refactor
hidl-doc, we are going to use 3rd party doc generation
tools in order to generate docs from the output of
hidl-gen.

This has a couple of benefits:
- people automatically get the documentation if they are using
  an IDE which pulls the documentation
- hidl-doc/hidl-gen won't get out of sync
- documentation will be closer to actual usage

This will require ABI-safe changes to some HAL interfaces.

Bug: 78135149
Test: manually inspect hidl-gen output.
Test: (sanity) run_all_host_tests.sh
Test: (sanity) run_all_device_tests.sh

Change-Id: I9a09ed48e2e3834fab7e032e29c48f466510e51f
(cherry picked from commit 49bad8df77e1fe1ca3c06fe49790a6e3304e7249)
Merged-In: I9a09ed48e2e3834fab7e032e29c48f466510e51f
diff --git a/hidl-gen_l.ll b/hidl-gen_l.ll
index 40c03b2..c94df01 100644
--- a/hidl-gen_l.ll
+++ b/hidl-gen_l.ll
@@ -35,6 +35,7 @@
 #include "CompoundType.h"
 #include "ConstantExpression.h"
 #include "DeathRecipientType.h"
+#include "DocComment.h"
 #include "EnumType.h"
 #include "HandleType.h"
 #include "MemoryType.h"
@@ -54,6 +55,8 @@
 using namespace android;
 using token = yy::parser::token;
 
+static std::string gCurrentComment;
+
 #define SCALAR_TYPE(kind)                                        \
     {                                                            \
         yylval->type = new ScalarType(ScalarType::kind, *scope); \
@@ -81,13 +84,24 @@
 %option bison-locations
 
 %x COMMENT_STATE
+%x DOC_COMMENT_STATE
 
 %%
 
-"/*"                { BEGIN(COMMENT_STATE); }
-<COMMENT_STATE>"*/" { BEGIN(INITIAL); }
-<COMMENT_STATE>[\n] { yylloc->lines(); }
-<COMMENT_STATE>.    { }
+"/**"                       { gCurrentComment.clear(); BEGIN(DOC_COMMENT_STATE); }
+<DOC_COMMENT_STATE>"*/"     {
+                                BEGIN(INITIAL);
+                                yylval->docComment = new DocComment(gCurrentComment);
+                                return token::DOC_COMMENT;
+                            }
+<DOC_COMMENT_STATE>[^*\n]*                          { gCurrentComment += yytext; }
+<DOC_COMMENT_STATE>[\n]                             { gCurrentComment += yytext; yylloc->lines(); }
+<DOC_COMMENT_STATE>[*]                              { gCurrentComment += yytext; }
+
+"/*"                        { BEGIN(COMMENT_STATE); }
+<COMMENT_STATE>"*/"         { BEGIN(INITIAL); }
+<COMMENT_STATE>[\n]         { yylloc->lines(); }
+<COMMENT_STATE>.            { }
 
 "//"[^\r\n]*        { /* skip C++ style comment */ }