Lexer passes the list of comments to parser

The lexer has been squashing comments into a single string, which makes
it hard to distinguish the type of comments later.

Instead of re-parsing comments, now, the lexer keeps the list of
comments and pass it to the parser.

But note that we still need to parse the contents of the body of block
comments to extract @hide/@deprecated tags.

Bug: 177276676
Test: aidl_unittests
Change-Id: I5f683ba6bf9fa3fbc5e73c4f80237a25eb410f71
diff --git a/aidl_language_l.ll b/aidl_language_l.ll
index 65e8b1f..3ff7c2e 100644
--- a/aidl_language_l.ll
+++ b/aidl_language_l.ll
@@ -43,20 +43,27 @@
 %%
 %{
   /* This happens at every call to yylex (every time we receive one token) */
+  using android::aidl::Comments;
+  using android::aidl::Comment;
   std::string extra_text;
+  Comments comments;
   yylloc->step();
 %}
 
 \/\*                  { extra_text += yytext; BEGIN(LONG_COMMENT); }
-<LONG_COMMENT>\*+\/   { extra_text += yytext; yylloc->step(); BEGIN(INITIAL);  }
+<LONG_COMMENT>\*+\/   { extra_text += yytext; yylloc->step(); BEGIN(INITIAL);
+                        comments.push_back({Comment::Type::BLOCK, extra_text});
+                        extra_text.clear(); }
 <LONG_COMMENT>\*+     { extra_text += yytext; }
 <LONG_COMMENT>\n+     { extra_text += yytext; yylloc->lines(yyleng); }
 <LONG_COMMENT>[^*\n]+ { extra_text += yytext; }
 
-\"[^\"]*\"            { yylval->token = new AidlToken(yytext, extra_text);
+\"[^\"]*\"            { yylval->token = new AidlToken(yytext, comments);
                         return yy::parser::token::C_STR; }
 
-\/\/.*                { extra_text += yytext; extra_text += "\n"; }
+\/\/.*                { extra_text += yytext; extra_text += "\n";
+                        comments.push_back({Comment::Type::LINE, extra_text});
+                        extra_text.clear(); }
 
 \n+                   { yylloc->lines(yyleng); yylloc->step(); }
 {whitespace}          {}
@@ -96,53 +103,53 @@
 "!="                  { return(yy::parser::token::NEQ); }
 
     /* annotations */
-@{identifier}         { yylval->token = new AidlToken(yytext + 1, extra_text);
+@{identifier}         { yylval->token = new AidlToken(yytext + 1, comments);
                         return yy::parser::token::ANNOTATION;
                       }
 
     /* keywords */
-parcelable            { yylval->token = new AidlToken("parcelable", extra_text);
+parcelable            { yylval->token = new AidlToken("parcelable", comments);
                         return yy::parser::token::PARCELABLE;
                       }
-import                { yylval->token = new AidlToken("import", extra_text);
+import                { yylval->token = new AidlToken("import", comments);
                         return yy::parser::token::IMPORT; }
-package               { yylval->token = new AidlToken("package", extra_text);
+package               { yylval->token = new AidlToken("package", comments);
                         return yy::parser::token::PACKAGE; }
 in                    { return yy::parser::token::IN; }
 out                   { return yy::parser::token::OUT; }
 inout                 { return yy::parser::token::INOUT; }
-cpp_header            { yylval->token = new AidlToken("cpp_header", extra_text);
+cpp_header            { yylval->token = new AidlToken("cpp_header", comments);
                         return yy::parser::token::CPP_HEADER; }
-const                 { yylval->token = new AidlToken("const", extra_text);
+const                 { yylval->token = new AidlToken("const", comments);
                         return yy::parser::token::CONST; }
 true                  { return yy::parser::token::TRUE_LITERAL; }
 false                 { return yy::parser::token::FALSE_LITERAL; }
 
-interface             { yylval->token = new AidlToken("interface", extra_text);
+interface             { yylval->token = new AidlToken("interface", comments);
                         return yy::parser::token::INTERFACE;
                       }
-oneway                { yylval->token = new AidlToken("oneway", extra_text);
+oneway                { yylval->token = new AidlToken("oneway", comments);
                         return yy::parser::token::ONEWAY;
                       }
-enum                  { yylval->token = new AidlToken("enum", extra_text);
+enum                  { yylval->token = new AidlToken("enum", comments);
                         return yy::parser::token::ENUM;
                       }
-union                 { yylval->token = new AidlToken("union", extra_text);
+union                 { yylval->token = new AidlToken("union", comments);
                         return yy::parser::token::UNION;
                       }
 
     /* scalars */
-{identifier}          { yylval->token = new AidlToken(yytext, extra_text);
+{identifier}          { yylval->token = new AidlToken(yytext, comments);
                         return yy::parser::token::IDENTIFIER;
                       }
 '.'                   { yylval->character = yytext[1];
                         return yy::parser::token::CHARVALUE;
                       }
-{intvalue}            { yylval->token = new AidlToken(yytext, extra_text);
+{intvalue}            { yylval->token = new AidlToken(yytext, comments);
                         return yy::parser::token::INTVALUE; }
-{floatvalue}          { yylval->token = new AidlToken(yytext, extra_text);
+{floatvalue}          { yylval->token = new AidlToken(yytext, comments);
                         return yy::parser::token::FLOATVALUE; }
-{hexvalue}            { yylval->token = new AidlToken(yytext, extra_text);
+{hexvalue}            { yylval->token = new AidlToken(yytext, comments);
                         return yy::parser::token::HEXVALUE; }
 
   /* lexical error! */