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_y.yy b/hidl-gen_y.yy
new file mode 100644
index 0000000..ae17f92
--- /dev/null
+++ b/hidl-gen_y.yy
@@ -0,0 +1,337 @@
+%{
+
+#include "AST.h"
+#include "ArrayType.h"
+#include "CompoundType.h"
+#include "Constant.h"
+#include "EnumType.h"
+#include "Interface.h"
+#include "Method.h"
+#include "RefType.h"
+#include "TypeDef.h"
+#include "VectorType.h"
+
+#include "hidl-gen_y.h"
+
+#include <stdio.h>
+
+using namespace android;
+
+extern int yylex(YYSTYPE *yylval_param, void *yyscanner);
+extern int column;
+
+int yyerror(AST *ast, const char *s) {
+ fflush(stdout);
+ printf("\n%*s\n%*s\n", column, "^", column, s);
+
+ return 0;
+}
+
+#define scanner ast->scanner()
+
+%}
+
+%parse-param { android::AST *ast }
+%lex-param { void *scanner }
+%pure-parser
+
+%token<str> CONST
+%token<str> ENUM
+%token<str> EXTENDS
+%token<str> GENERATES
+%token<str> IDENTIFIER
+%token<str> IMPORT
+%token<str> INTEGER
+%token<str> INTERFACE
+%token<str> PACKAGE
+%token<str> STRUCT
+%token<str> STRING_LITERAL
+%token<str> TYPEDEF
+%token<str> UNION
+%token<str> VEC
+%token<str> VERSION
+
+%token<type> TYPENAME
+
+%type<str> optIdentifier package
+%type<str> const_value
+
+%type<type> type opt_storage_type
+%type<type> enum_declaration
+%type<type> struct_or_union_declaration
+%type<type> opt_extends
+
+%type<field> field_declaration
+%type<fields> field_declarations struct_or_union_body
+%type<enumValue> enum_value
+%type<enumValues> enum_values
+%type<typedVars> typed_vars
+%type<typedVar> typed_var
+%type<method> method_declaration
+%type<compoundStyle> struct_or_union_keyword
+
+%start program
+
+%union {
+ const char *str;
+ android::Type *type;
+ android::CompoundType *compoundType;
+ android::CompoundField *field;
+ android::Vector<android::CompoundField *> *fields;
+ android::EnumValue *enumValue;
+ android::Vector<android::EnumValue *> *enumValues;
+ android::TypedVar *typedVar;
+ android::Vector<android::TypedVar *> *typedVars;
+ android::Method *method;
+ android::CompoundType::Style compoundStyle;
+}
+
+%%
+
+program
+ : version package imports body
+ ;
+
+version
+ : VERSION INTEGER '.' INTEGER ';'
+
+package
+ : PACKAGE package_path ';'
+
+package_path
+ : IDENTIFIER
+ | package_path '.' IDENTIFIER
+ ;
+
+imports
+ : /* empty */
+ | imports IMPORT package_path ';'
+ ;
+
+opt_extends
+ : /* empty */ { $$ = NULL; }
+ | EXTENDS TYPENAME { $$ = $2; }
+
+body
+ : INTERFACE IDENTIFIER opt_extends
+ {
+ Interface *iface = new Interface($2, $3);
+ ast->enterScope(iface);
+ }
+ '{' interface_declarations '}' ';'
+ {
+ Interface *iface = static_cast<Interface *>(ast->scope());
+
+ ast->leaveScope();
+ ast->scope()->addType(iface);
+ }
+ | type_declarations
+ ;
+
+interface_declarations
+ : /* empty */
+ | interface_declarations type_declaration
+ | interface_declarations method_declaration
+ {
+ Interface *iface = static_cast<Interface *>(ast->scope());
+ iface->addMethod($2);
+ }
+ ;
+
+type_declarations
+ : type_declaration
+ | type_declarations type_declaration
+ ;
+
+type_declaration
+ : named_struct_or_union_declaration ';'
+ | named_enum_declaration ';'
+ | typedef_declaration ';'
+ | const_declaration ';'
+ ;
+
+typedef_declaration
+ : TYPEDEF type IDENTIFIER
+ {
+ TypeDef *def = new TypeDef($3, $2);
+ ast->scope()->addType(def);
+ }
+ ;
+
+const_value
+ : INTEGER
+ | STRING_LITERAL ;
+
+const_declaration
+ : CONST TYPENAME IDENTIFIER '=' const_value
+ {
+ Constant *constant = new Constant($3, $2, $5);
+ ast->scope()->addConstant(constant);
+ }
+ ;
+
+method_declaration
+ : IDENTIFIER '(' typed_vars ')' ';'
+ {
+ $$ = new Method($1, $3);
+ }
+ | IDENTIFIER '(' typed_vars ')' GENERATES '(' typed_vars ')' ';'
+ {
+ $$ = new Method($1, $3, $7);
+ }
+ ;
+
+typed_vars
+ : /* empty */
+ {
+ $$ = new Vector<TypedVar *>;
+ }
+ | typed_var
+ {
+ $$ = new Vector<TypedVar *>;
+ $$->push_back($1);
+ }
+ | typed_vars ',' typed_var
+ {
+ $$ = $1;
+ $$->push_back($3);
+ }
+ ;
+
+typed_var : type IDENTIFIER { $$ = new TypedVar($2, $1); }
+ ;
+
+
+struct_or_union_keyword
+ : STRUCT { $$ = CompoundType::STYLE_STRUCT; }
+ | UNION { $$ = CompoundType::STYLE_UNION; }
+ ;
+
+named_struct_or_union_declaration
+ : struct_or_union_keyword IDENTIFIER
+ {
+ CompoundType *container = new CompoundType($1, $2);
+ ast->enterScope(container);
+ }
+ struct_or_union_body
+ {
+ CompoundType *container = static_cast<CompoundType *>(ast->scope());
+
+ container->setFields($4);
+ ast->leaveScope();
+ ast->scope()->addType(container);
+ }
+ ;
+
+struct_or_union_declaration
+ : struct_or_union_keyword optIdentifier
+ {
+ CompoundType *container = new CompoundType($1, $2);
+ ast->enterScope(container);
+ }
+ struct_or_union_body
+ {
+ CompoundType *container = static_cast<CompoundType *>(ast->scope());
+
+ container->setFields($4);
+ ast->leaveScope();
+ ast->scope()->addType(container);
+
+ $$ = new RefType(container->name().c_str(), container);
+ }
+ ;
+
+struct_or_union_body
+ : '{' field_declarations '}' { $$ = $2; }
+ ;
+
+field_declarations
+ : /* empty */ { $$ = new Vector<CompoundField *>; }
+ | field_declarations field_declaration
+ {
+ $$ = $1;
+
+ if ($2 != NULL) {
+ $$->push_back($2);
+ }
+ }
+ ;
+
+field_declaration
+ : type IDENTIFIER ';' { $$ = new CompoundField($2, $1); }
+ | struct_or_union_declaration ';' { $$ = NULL; }
+ | enum_declaration ';' { $$ = NULL; }
+ ;
+
+opt_storage_type
+ : /* empty */ { $$ = NULL; }
+ | ':' TYPENAME { $$ = $2; }
+ ;
+
+opt_comma
+ : /* empty */
+ | ','
+ ;
+
+named_enum_declaration
+ : ENUM IDENTIFIER opt_storage_type '{' enum_values opt_comma '}'
+ {
+ EnumType *enumType = new EnumType($2, $5, $3);
+ ast->scope()->addType(enumType);
+ }
+ ;
+
+enum_declaration
+ : ENUM '{' enum_values opt_comma '}'
+ {
+ EnumType *enumType = new EnumType(NULL /* name */, $3);
+ ast->scope()->addType(enumType);
+
+ $$ = new RefType(enumType->name().c_str(), enumType);
+ }
+ | ENUM IDENTIFIER opt_storage_type '{' enum_values opt_comma '}'
+ {
+ EnumType *enumType = new EnumType($2, $5, $3);
+ ast->scope()->addType(enumType);
+
+ $$ = new RefType(enumType->name().c_str(), enumType);
+ }
+ ;
+
+enum_value
+ : IDENTIFIER { $$ = new EnumValue($1); }
+ | IDENTIFIER '=' INTEGER { $$ = new EnumValue($1, $3); }
+ | IDENTIFIER '=' IDENTIFIER { $$ = new EnumValue($1, $3); }
+ ;
+
+enum_values
+ : /* empty */
+ {
+ $$ = new Vector<EnumValue *>;
+ }
+ | enum_value
+ {
+ $$ = new Vector<EnumValue *>;
+ $$->push_back($1);
+ }
+ | enum_values ',' enum_value
+ {
+ $$ = $1;
+ $$->push_back($3);
+ }
+ ;
+
+type
+ : TYPENAME { $$ = $1; }
+ | TYPENAME '[' INTEGER ']' { $$ = new ArrayType($1, $3); }
+ | VEC '<' TYPENAME '>' { $$ = new VectorType($3); }
+ | struct_or_union_declaration { $$ = $1; }
+ | enum_declaration { $$ = $1; }
+ ;
+
+optIdentifier
+ : /* empty */ { $$ = NULL; }
+ | IDENTIFIER { $$ = $1; }
+ ;
+
+%%