initial commit of reimplementation of hidl-gen
commit 56da787631c17276bc987f19649c6c1ea92200c3
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 12:18:57 2016 -0700
ast.cpp => AST.cpp
commit 095552aba072152d9c87475895cd2e97c43b7b03
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 10:43:04 2016 -0700
TypeContainer => Scope, since it now also holds constants.
commit 89ec1c511e7806037a53e43333c37fdf1b7aa39e
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 10:41:05 2016 -0700
initial support for constants
commit b60b7ae588654b634bfdc5c283a25dd6378e1df7
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 10:01:46 2016 -0700
Support for typedef, maintain ordering inside TypeContainer
commit 8e83034a077ce2309deeb0e2094079cf6f11d8b4
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 09:36:29 2016 -0700
support for optional super interface
commit 9d44b022adb4a68dfca67ba2a6d845b7c8f27b88
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 09:28:18 2016 -0700
ast => AST
commit 48fd7f8a4e8ecf230cfc416aec6c8f6115e410af
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 09:26:44 2016 -0700
Each type in its own source/header file pair.
commit ca1285ecbcbbb1340eec476e3fd4d1334908d8c1
Author: Andreas Huber <andih@google.com>
Date: Thu Jul 28 08:52:24 2016 -0700
added scalar types "char", "bool" and "opaque"
commit fbb351e5f4392fcbbce77402dfe059a1c8d79fb2
Author: Andreas Huber <andih@google.com>
Date: Wed Jul 27 13:47:32 2016 -0700
some fixes to the parser and ast.
commit 78288216b101349e9364c2d4470ecb5b9a942f5c
Author: Andreas Huber <andih@google.com>
Date: Wed Jul 27 12:34:21 2016 -0700
Formatter, AST::dump(), NamedType
commit 4b8cc5d0a8ff5f70cb53e21b56138124259b8bcb
Author: Andreas Huber <andih@google.com>
Date: Wed Jul 27 11:45:10 2016 -0700
revamp of the parser, scoped type containers
commit 0193fbfa5c7ac3ac1ce306dfb9c55d879f8c02b5
Author: Andreas Huber <andih@google.com>
Date: Wed Jul 27 10:13:35 2016 -0700
store output in AST.
commit 7f53022123978cc7c2a05b0c4aba7a4c5deea93b
Author: Andreas Huber <andih@google.com>
Date: Wed Jul 27 10:06:54 2016 -0700
reentrant lexer/parser
commit 3d3e343d6cea2fb127b203071e8aff08a5715011
Author: Andreas Huber <andih@google.com>
Date: Tue Jul 26 15:27:02 2016 -0700
better typename lookup, comments.
commit 39f13ae860dbd9ffd163a5c99f150170525457ef
Author: Andreas Huber <andih@google.com>
Date: Tue Jul 26 14:29:33 2016 -0700
an actual AST.
commit b1f3f1d94a8d1257426da35ace5bc2af04c433b6
Author: Andreas Huber <andih@google.com>
Date: Tue Jul 26 12:51:34 2016 -0700
initial commit
Change-Id: I44d1d928a5f3dcb908e264d53af09bbe25d8c464
diff --git a/hidl-gen_l.ll b/hidl-gen_l.ll
new file mode 100644
index 0000000..cea965a
--- /dev/null
+++ b/hidl-gen_l.ll
@@ -0,0 +1,173 @@
+D [0-9]
+L [a-zA-Z_]
+H [a-fA-F0-9]
+E [Ee][+-]?{D}+
+FS (f|F|l|L)
+IS (u|U|l|L)*
+
+%{
+
+#include "AST.h"
+#include "CompoundType.h"
+#include "EnumType.h"
+#include "HandleType.h"
+#include "Method.h"
+#include "RefType.h"
+#include "ScalarType.h"
+#include "StringType.h"
+
+#include "hidl-gen_y.h"
+
+#include <assert.h>
+
+using namespace android;
+
+void count(struct yyguts_t *yyg);
+void comment(yyscan_t yyscanner, struct yyguts_t *yyg);
+int check_type(yyscan_t yyscanner, struct yyguts_t *yyg);
+
+#define SCALAR_TYPE(kind) \
+ do { \
+ count(yyg); \
+ yylval->type = new ScalarType(ScalarType::kind); \
+ return TYPENAME; \
+ } while (0)
+
+%}
+
+%option reentrant
+%option bison-bridge
+%option extra-type="android::AST *"
+
+%%
+
+"/*" { comment(yyscanner, yyg); }
+"//"[^\r\n]* { /* skip C++ style comment */ }
+
+"const" { count(yyg); return(CONST); }
+"enum" { count(yyg); return(ENUM); }
+"extends" { count(yyg); return(EXTENDS); }
+"generates" { count(yyg); return(GENERATES); }
+"import" { count(yyg); return(IMPORT); }
+"interface" { count(yyg); return(INTERFACE); }
+"package" { count(yyg); return(PACKAGE); }
+"struct" { count(yyg); return(STRUCT); }
+"typedef" { count(yyg); return(TYPEDEF); }
+"union" { count(yyg); return(UNION); }
+"vec" { count(yyg); return(VEC); }
+"version" { count(yyg); return(VERSION); }
+
+"char" { SCALAR_TYPE(KIND_CHAR); }
+"bool" { SCALAR_TYPE(KIND_BOOL); }
+"opaque" { SCALAR_TYPE(KIND_OPAQUE); }
+"int8_t" { SCALAR_TYPE(KIND_INT8); }
+"uint8_t" { SCALAR_TYPE(KIND_UINT8); }
+"int16_t" { SCALAR_TYPE(KIND_INT16); }
+"uint16_t" { SCALAR_TYPE(KIND_UINT16); }
+"int32_t" { SCALAR_TYPE(KIND_INT32); }
+"uint32_t" { SCALAR_TYPE(KIND_UINT32); }
+"int64_t" { SCALAR_TYPE(KIND_INT64); }
+"uint64_t" { SCALAR_TYPE(KIND_UINT64); }
+"float" { SCALAR_TYPE(KIND_FLOAT); }
+"double" { SCALAR_TYPE(KIND_DOUBLE); }
+
+"handle" { count(yyg); yylval->type = new HandleType; return TYPENAME; }
+"string" { count(yyg); yylval->type = new StringType; return TYPENAME; }
+
+"(" { count(yyg); return('('); }
+")" { count(yyg); return(')'); }
+"<" { count(yyg); return('<'); }
+">" { count(yyg); return('>'); }
+"{" { count(yyg); return('{'); }
+"}" { count(yyg); return('}'); }
+"[" { count(yyg); return('['); }
+"]" { count(yyg); return(']'); }
+":" { count(yyg); return(':'); }
+";" { count(yyg); return(';'); }
+"," { count(yyg); return(','); }
+"." { count(yyg); return('.'); }
+"=" { count(yyg); return('='); }
+
+{L}({L}|{D})* { count(yyg); return check_type(yyscanner, yyg); }
+
+0[xX]{H}+{IS}? { count(yyg); yylval->str = strdup(yytext); return(INTEGER); }
+0{D}+{IS}? { count(yyg); yylval->str = strdup(yytext); return(INTEGER); }
+{D}+{IS}? { count(yyg); yylval->str = strdup(yytext); return(INTEGER); }
+L?\"(\\.|[^\\"])*\" { count(yyg); yylval->str = strdup(yytext); return(STRING_LITERAL); }
+
+[ \t\v\n\f] { count(yyg); }
+. { /* ignore bad characters */ }
+
+%%
+
+int yywrap(yyscan_t scanner) {
+ return 1;
+}
+
+void comment(yyscan_t yyscanner, yyguts_t *yyg) {
+ char c, c1;
+
+loop:
+ while ((c = yyinput(yyscanner)) != '*' && c != 0)
+ putchar(c);
+
+ if ((c1 = yyinput(yyscanner)) != '/' && c != 0)
+ {
+ unput(c1);
+ goto loop;
+ }
+
+ if (c != 0) {
+ putchar(c1);
+ }
+}
+
+
+int column = 0;
+
+void count(yyguts_t *yyg) {
+ int i;
+
+ for (i = 0; yytext[i] != '\0'; i++)
+ if (yytext[i] == '\n')
+ column = 0;
+ else if (yytext[i] == '\t')
+ column += 8 - (column % 8);
+ else
+ column++;
+
+ ECHO;
+}
+
+int check_type(yyscan_t yyscanner, yyguts_t *yyg) {
+ AST *ast = yyextra;
+
+ Type *type = ast->lookupType(yytext);
+ if (type != NULL) {
+ yylval->type = new RefType(yytext, type);
+
+ return TYPENAME;
+ }
+
+ yylval->str = strdup(yytext);
+
+ return IDENTIFIER;
+}
+
+void parseFile(AST *ast, const char *path) {
+ FILE *file = fopen(path, "rb");
+
+ yyscan_t scanner;
+ yylex_init_extra(ast, &scanner);
+ ast->setScanner(scanner);
+
+ yyset_in(file, scanner);
+ int res = yyparse(ast);
+ assert(res == 0);
+
+ yylex_destroy(scanner);
+ ast->setScanner(NULL);
+
+ fclose(file);
+ file = NULL;
+}