Compare commits

...

1 Commits

Author SHA1 Message Date
Emmanuele Bassi d02eb274ae Snapshot/WIP 2012-05-16 12:35:18 +01:00
7 changed files with 415 additions and 0 deletions

139
tools/gidl/GIDL-BNF.txt Normal file
View File

@ -0,0 +1,139 @@
boolean_literal ::= "true" | "false"
scoped_name ::= identifier
| ( "::" identifier )
| ( scoped_name "::" identifier )
literal ::= integer_literal
| string_literal
| character_literal
| floating_point_literal
| boolean_literal
primary_expr ::= scoped_name | literal | "(" const_expr ")"
unary_operator ::= "-" | "+" | "~"
unary_expr ::= unary_operator primary_expr | primary_expr
mult_expr ::= unary_expr
| mult_expr "*" unary_expr
| mult_expr "/" unary_expr
| mult_expr "%" unary_expr
add_expr ::= mult_expr | add_expr "+" mult_expr | add_expr "-" mult_expr
shift_expr ::= add_expr | shift_expr ">>" add_expr | shift_expr "<<" add_expr
and_expr ::= shift_expr | and_expr "ampersand char" shift_expr
xor_expr ::= and_expr | xor_expr "^" and_expr
or_expr ::= xor_expr | or_expr "|" xor_expr
boolean_type ::= "boolean"
signed_integer_type ::= "int" | "int8" | "int16" | "int32" | "int64" | "long"
unsigned_integer_type ::= "uint" | "uint8" | "uint16" | "uint32" | "uint64" | "ulong"
character_type ::= "char" | "unichar"
integer_type ::= signed_integer_type | unsigned_integer_type | character_type
floating_point_type ::= "float" | "double"
string_type ::= "string"
member ::= type_spec declarators ";"
member_list ::= member { member_list }
struct_type ::= "struct" identifier "{" member_list "}"
union_type ::= "union" identifier "{" member_list "}"
enumerator ::= identifier [ "=" const_expr ]
enum_type ::= "enum" identifier "{" enumerator { "," enumerator } "}"
errordomain_type ::= "errordomain" identifier "{" enumerator { "," enumerator } "}"
simple_type_spec ::= base_type_spec | scoped_name
complex_type_spec ::= struct_type | union_type | enum_type | errordomain_type
type_spec ::= simple_type_spec | complex_type_spec
fixed_array_size ::= "[" positive_integer_constant "]" | "[" "]"
array_declarator ::= identifier fixed_array_size { fixed_array_size }
simple_declarator ::= identifier
complex_declarator ::= array_declarator
declarator ::= simple_declarator | complex_declarator
declarators ::= declarator { "," declarator }
type_declarator ::= type_spec declarators
type_decl ::= "typedef" type_declarator
| struct_type
| union_type
| enum_type
| errordomain_type
const_expr ::= or_expr
const_type ::= integer_type
| char_type
| boolean_type
| floating_point_type
| string_type
| scoped_name
const_decl ::= "const" const_type identifier "=" const_expr
annotation_declarator ::= identifier { "=" const_expr }
annotation_decls ::= "[" annotation_declarator { "," annotation_declarator } "]"
param_type_spec ::= base_type_spec | "string" | scoped_name
method_type_spec ::= param_type_spec | "void"
visibility ::= "readonly" | "writeonly" | "readwrite"
memory ::= "copy" | "reference" | "assign"
property_decl ::= "property" [ visibility ] [ memory ] param_type_spec simple_declarator { "," simple_declarator }
parameter_direction ::= "in" | "out" | "inout"
parameter_declarator ::= parameter_direction param_type_spec simple_declarator
parameter_decls ::= "(" parameter_declarator { "," parameter_declarator } ")" | "(" ")"
signal_decl ::= "signal" method_type_spec identifier parameter_decls
raises_expr ::= "raises" scoped_name { "," scoped_name }
method_decl ::= method_type_spec identifier parameter_decls [ raises_expr ]
export ::= [annotation_decls] ( type_decl | const_decl | property_decl | signal_decl | method_decl ) ";"
inheritance_spec ::= ":" scoped_name { "," scoped_name }
interface_header ::= [ annotation_decls ] "interface" identifier [ inheritance_spec ]
interface_body ::= { export }
interface_decl ::= interface_header "{" interface_body "}"
definition ::= ( type_decl | const_decl | interface_decl ) ";"
specification ::= definition { specification }
module_decl ::= [ annotation_decls ] "module" identifier "{" { specification } "}"

View File

@ -0,0 +1,15 @@
AvailableSince
DefaultValue
DeprecatedIn
EmitterName
GetterName
NoEmitter
NoGetter
NoSetter
NotifyProperty
PropertyDescription
PropertyName
RangeMax
RangeMin
SetterName
SignalFlags

0
tools/gidl/__init__.py Normal file
View File

70
tools/gidl/gidlscanner.c Normal file
View File

@ -0,0 +1,70 @@
#include "config.h"
#include "gidlscanner.h"
#include <stdlib.h>
#include <string.h>
struct _GidlScanner
{
char *filename;
GInputStream *stream;
GidlNode *root;
};
struct _GidlNode
{
GidlNodeType type;
int ref_count;
};
struct _GidlModule
{
GidlNode _parent;
char *name;
GPtrArray *annotations;
};
struct _GidlInterface
{
GidlNode _parent;
char *scoped_name;
char **decomposed_name;
GHashTable *inherits;
GHashTable *annotations;
GHashTable *properties;
GHashTable *signals;
GHashTable *methods;
};
struct _GidlProperty
{
GidlNode _parent;
char *name;
GidlNode *type;
GidlPropertyVisibility visibility;
GidlPropertyMemory memory;
GHashTable *annotations;
};
struct _GidlMethod
{
GidlNode _parent;
char *name;
GidlNode *retval;
GHashTable *parameters;
GHashTable *annotations;
GHashTable *exceptions;
};

95
tools/gidl/gidlscanner.h Normal file
View File

@ -0,0 +1,95 @@
#ifndef __G_IDL_SCANNER_H__
#define __G_IDL_SCANNER_H__
#include <glib.h>
#include <gio/gio.h>
G_BEGIN_DECLS
typedef struct _GidlScanner GidlScanner;
typedef struct _GidlNode GidlNode;
typedef struct _GidlModule GidlModule;
typedef struct _GidlInterface GidlInterface;
typedef struct _GidlProperty GidlProperty;
typedef struct _GidlSignal GidlSignal;
typedef struct _GidlMethod GidlMethod;
typedef struct _GidlAnnotation GidlAnnotation;
typedef struct _GidlParameter GidlParameter;
typedef struct _GidlConst GidlConst;
typedef struct _GidlEnum GidlEnum;
typedef struct _GidlErrorDomain GidlErrorDomain;
typedef struct _GidlStruct GidlStruct;
typedef struct _GidlUnion GidlUnion;
typedef struct _GidlMember GidlMember;
typedef struct _GidlValue GidlValue;
typedef enum {
G_IDL_INVALID_NODE,
G_IDL_MODULE,
G_IDL_INTERFACE,
G_IDL_PROPERTY,
G_IDL_SIGNAL,
G_IDL_METHOD,
G_IDL_ANNOTATION,
G_IDL_PARAMETER,
G_IDL_CONST,
G_IDL_ENUM,
G_IDL_ERROR_DOMAIN,
G_IDL_STRUCT,
G_IDL_UNION,
G_IDL_MEMBER,
G_IDL_VALUE
} GidlNodeType;
typedef enum {
G_IDL_PROPERTY_READONLY,
G_IDL_PROPERTY_WRITEONLY,
G_IDL_PROPERTY_READWRITE
} GidlPropertyVisibility;
typedef enum {
G_IDL_PROPERTY_ASSIGN,
G_IDL_PROPERTY_COPY,
G_IDL_PROPERTY_REFERENCE
} GidlPropertyMemory;
typedef enum {
G_IDL_DIRECTION_IN,
G_IDL_DIRECTION_OUT,
G_IDL_DIRECTION_INOUT
} GidlParameterDirection;
GidlScanner * g_idl_scanner_alloc (void);
GidlScanner * g_idl_scanner_init_with_file (GidlScanner *scanner,
const char *filename);
GidlScanner * g_idl_scanner_init_with_data (GidlScanner *scanner,
const char *data,
gssize length);
GidlScanner * g_idl_scanner_init_with_stream (GidlScanner *scanner,
GInputStream *stream);
GidlScanner * g_idl_scanner_free (GidlScanner *scanner);
gboolean g_idl_scanner_parse (GidlScanner *scanner,
GCancellable *cancellable,
GError **error);
void g_idl_scanner_parse_async (GidlScanner *scanner,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer data);
gboolean g_idl_scanner_parse_finish (GidlScanner *scanner,
GAsyncResult *result,
GError **error);
GidlNodeType g_idl_node_type (const GidlNode *node);
GidlNode * g_idl_node_ref (GidlNode *node);
void g_idl_node_unref (GidlNode *node);
G_GNUC_INTERNAL
void g_idl_scanner_add_node (GidlScanner *scanner,
GidlNode *node);
G_END_DECLS
#endif /* __G_IDL_SCANNER_H__ */

View File

@ -0,0 +1,66 @@
int lineno;
char linebuf[2000];
#undef YY_BUF_SIZE
#define YY_BUF_SIZE 1048576
extern int yylex (GidlScanner *scanner);
#define YY_DECL int yylex (GidlScanner *scanner)
static int yywrap (void);
%option nounput
intsuffix ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
fracconst ([0-9]*\.[0-9]+)|([0-9]+\.)
exppart [eE][-+]?[0-9]+
floatsuffix [fFlL]
chartext ([^\\\'])|(\\.)
stringtext ([^\\\"])|(\\.)
%%
\n.* { strncpy(linebuf, yytext+1, sizeof(linebuf)); /* save the next line */
linebuf[sizeof(linebuf)-1]='\0';
/* printf("%4d:%s\n",lineno,linebuf); */
yyless(1); /* give back all but the \n to rescan */
++lineno;
}
"\\\n" { ++lineno; }
[\t\f\v\r ]+ { /* Ignore whitespace. */ }
"module" { return MODULE; }
"interface" { return INTERFACE; }
"property" { return PROPERTY; }
"signal" { return SIGNAL; }
"readonly" { return READONLY; }
"readwrite" { return READWRITE; }
"writeonly" { return WRITEONLY; }
"float" { return FLOAT; }
"double" { return DOUBLE; }
"const" { return CONST; }
"struct" { return STRUCT; }
"union" { return UNION; }
"enum" { return ENUM; }
"errordomain" { return ERRORDOMAIN; }
"0"[xX][0-9a-fA-F]+{intsuffix}? { return INTEGER; }
"0"[0-7]+{intsuffix}? { return INTEGER; }
[0-9]+{intsuffix}? { return INTEGER; }
{fracconst}{exppart}?{floatsuffix}? { return FLOATING; }
[0-9]+{exppart}{floatsuffix}? { return FLOATING; }
"'"{chartext}*"'" { return CHARACTER; }
"L'"{chartext}*"'" { return CHARACTER; }
"\""{stringtext}*"\"" { return STRING; }
"L\""{stringtext}*"\"" { return STRING; }
%%
static int
yywrap (void)
{
return 1;
}

View File

@ -0,0 +1,30 @@
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "gidl-scanner.h"
#include "idlscannerparser.h"
extern FILE *yyin;
extern int lineno;
extern char linebuf[2000];
extern char *yytext;
extern int yylex (GidlScanner *scanner);
static void yyerror (GidlScanner *scanner, const char *str);
%}
%error-verbose
%parse-param { GidlScanner* scanner }
%lex-param { GidlScanner* scanner }
%token <str> IDENTIFIER "identifier"
%token <str> TYPEDEF_NAME "typedef-name"
%token INTEGER FLOATING CHARACTER STRING BOOLEAN
%token MODULE INTERFACE PROPERTY SIGNAL DIRECTION VISIBILITY
%token ANNOTATION