Commit b70d052d authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

add gen-introspect from gobject-introspection git

2007-10-26  Juerg Billeter  <j@bitron.ch>

	* configure.ac, gobject-introspection/Makefile.am,
	  gobject-introspection/clexer.l, gobject-introspection/cparser.y,
	  gobject-introspection/gen-introspect.c,
	  gobject-introspection/gen-introspect.h: add gen-introspect from
	  gobject-introspection git

svn path=/trunk/; revision=660
parent 2f09eeba
2007-10-26 Jürg Billeter <j@bitron.ch>
* configure.ac, gobject-introspection/Makefile.am,
gobject-introspection/clexer.l, gobject-introspection/cparser.y,
gobject-introspection/gen-introspect.c,
gobject-introspection/gen-introspect.h: add gen-introspect from
gobject-introspection git
2007-10-19 Jürg Billeter <j@bitron.ch>
* gobject-introspection/gidlnode.c, gobject-introspection/gidlparser.c:
......
......@@ -37,6 +37,11 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GLIB_REQUIRED
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
PKG_CHECK_MODULES(GMODULE, gmodule-2.0 >= $GLIB_REQUIRED)
AC_SUBST(GMODULE_CFLAGS)
AC_SUBST(GMODULE_LIBS)
AC_PATH_PROG([XSLTPROC], [xsltproc], :)
AM_CONDITIONAL(HAVE_XSLTPROC, test "$XSLTPROC" != :)
......
......@@ -22,4 +22,23 @@ libgidl_la_LIBADD = \
$(GLIB_LIBS) \
$(NULL)
pkglibexecdir = $(libdir)/vala
pkglibexec_PROGRAMS = gen-introspect
BUILT_SOURCES = cparser.h
AM_YFLAGS = -d
gen_introspect_SOURCES = \
clexer.l \
cparser.y \
gen-introspect.c \
gen-introspect.h \
$(NULL)
gen_introspect_LDADD = \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
libgidl.la \
$(NULL)
EXTRA_DIST = gidl.vapi
/* GObject introspection: C lexer
*
* Copyright (c) 1997 Sandro Sigala <ssigala@globalnet.it>
* Copyright (c) 2007 Jürg Billeter <j@bitron.ch>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
%{
#include <ctype.h>
#include <stdio.h>
#include "gen-introspect.h"
#include "cparser.h"
int lineno;
static int yywrap (void);
static void skip_comment (void);
static void process_directive (void);
static int check_identifier (const char *);
%}
intsuffix ([uU][lL]?)|([lL][uU]?)
fracconst ([0-9]*\.[0-9]+)|([0-9]+\.)
exppart [eE][-+]?[0-9]+
floatsuffix [fFlL]
chartext ([^'])|(\\.)
stringtext ([^"])|(\\.)
%%
"\n" { ++lineno; }
[\t\f\v\r ]+ { /* Ignore whitespace. */ }
"/*" { skip_comment(); }
"//".* { }
"#define "[a-zA-Z_][a-zA-Z_0-9]*"(" { yyless (yyleng - 1); return FUNCTION_MACRO; }
"#define "[a-zA-Z_][a-zA-Z_0-9]* { return OBJECT_MACRO; }
"#" { process_directive(); }
"{" { return '{'; }
"<%" { return '{'; }
"}" { return '}'; }
"%>" { return '}'; }
"[" { return '['; }
"<:" { return '['; }
"]" { return ']'; }
":>" { return ']'; }
"(" { return '('; }
")" { return ')'; }
";" { return ';'; }
":" { return ':'; }
"..." { return ELLIPSIS; }
"?" { return '?'; }
"." { return '.'; }
"+" { return '+'; }
"-" { return '-'; }
"*" { return '*'; }
"/" { return '/'; }
"%" { return '%'; }
"^" { return '^'; }
"&" { return '&'; }
"|" { return '|'; }
"~" { return '~'; }
"!" { return '!'; }
"=" { return '='; }
"<" { return '<'; }
">" { return '>'; }
"+=" { return ADDEQ; }
"-=" { return SUBEQ; }
"*=" { return MULEQ; }
"/=" { return DIVEQ; }
"%=" { return MODEQ; }
"^=" { return XOREQ; }
"&=" { return ANDEQ; }
"|=" { return OREQ; }
"<<" { return SL; }
">>" { return SR; }
"<<=" { return SLEQ; }
">>=" { return SREQ; }
"==" { return EQ; }
"!=" { return NOTEQ; }
"<=" { return LTEQ; }
">=" { return GTEQ; }
"&&" { return ANDAND; }
"||" { return OROR; }
"++" { return PLUSPLUS; }
"--" { return MINUSMINUS; }
"," { return ','; }
"->" { return ARROW; }
[a-zA-Z_][a-zA-Z_0-9]* { if (the_igenerator->macro_scan) return IDENTIFIER; else REJECT; }
"auto" { return AUTO; }
"break" { return BREAK; }
"case" { return CASE; }
"char" { return CHAR; }
"const" { return CONST; }
"continue" { return CONTINUE; }
"default" { return DEFAULT; }
"do" { return DO; }
"double" { return DOUBLE; }
"else" { return ELSE; }
"enum" { return ENUM; }
"extern" { return EXTERN; }
"float" { return FLOAT; }
"for" { return FOR; }
"goto" { return GOTO; }
"if" { return IF; }
"inline" { return INLINE; }
"int" { return INT; }
"long" { return LONG; }
"register" { return REGISTER; }
"restrict" { return RESTRICT; }
"return" { return RETURN; }
"short" { return SHORT; }
"signed" { return SIGNED; }
"sizeof" { return SIZEOF; }
"static" { return STATIC; }
"struct" { return STRUCT; }
"switch" { return SWITCH; }
"typedef" { return TYPEDEF; }
"union" { return UNION; }
"unsigned" { return UNSIGNED; }
"void" { return VOID; }
"volatile" { return VOLATILE; }
"while" { return WHILE; }
[a-zA-Z_][a-zA-Z_0-9]* { return check_identifier(yytext); }
"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; }
. { fprintf(stderr, "%d: unexpected character `%c'\n", lineno, yytext[0]); }
%%
static int yywrap (void)
{
return 1;
}
static void skip_comment (void)
{
int c1, c2;
c1 = input();
c2 = input();
while (c2 != EOF && !(c1 == '*' && c2 == '/')) {
if (c1 == '\n')
++lineno;
c1 = c2;
c2 = input();
}
}
static int check_identifier (const char *s)
{
/*
* This function checks if `s' is a type name or an
* identifier.
*/
if (g_igenerator_is_typedef (the_igenerator, s)) {
return TYPEDEF_NAME;
} else if (strcmp (s, "__builtin_va_list") == 0) {
return TYPEDEF_NAME;
}
return IDENTIFIER;
}
static void process_directive (void)
{
/* extract current filename from #line directives */
GString *filename_builder;
gboolean in_string;
in_string = FALSE;
filename_builder = g_string_new ("");
int c = input ();
while (c != EOF && c != '\n') {
if (!in_string) {
if (c == '\"') {
in_string = TRUE;
}
} else {
if (c == '\"') {
in_string = FALSE;
} else if (c == '\\') {
g_string_append_c (filename_builder, c);
c = input ();
g_string_append_c (filename_builder, c);
} else {
g_string_append_c (filename_builder, c);
}
}
c = input ();
}
++lineno;
if (filename_builder->len > 0) {
char *filename = g_strcompress (filename_builder->str);
g_free (the_igenerator->current_filename);
the_igenerator->current_filename = g_path_get_basename (filename);
g_free (filename);
}
g_string_free (filename_builder, TRUE);
}
This diff is collapsed.
This diff is collapsed.
/* GObject introspection: gen-introspect
*
* Copyright (C) 2007 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
#ifndef __GEN_INTROSPECT_H__
#define __GEN_INTROSPECT_H__
#include <glib.h>
#include "gidlmodule.h"
G_BEGIN_DECLS
typedef struct _GIGenerator GIGenerator;
typedef struct _CSymbol CSymbol;
typedef struct _CType CType;
struct _GIGenerator {
const char *namespace;
char *lower_case_namespace;
/* specified files to be parsed */
GList *filenames;
GList *libraries;
/* source reference of current lexer position */
char *current_filename;
GList *symbol_list;
GHashTable *typedef_table;
GHashTable *struct_or_union_or_enum_table;
gboolean macro_scan;
GIdlModule *module;
GList *get_type_symbols;
GHashTable *type_map;
GHashTable *type_by_lower_case_prefix;
int indent;
};
GIGenerator *g_igenerator_new (void);
void g_igenerator_parse (GIGenerator *igenerator, FILE *f);
void g_igenerator_add_symbol (GIGenerator *igenerator, CSymbol *symbol);
gboolean g_igenerator_is_typedef (GIGenerator *igenerator, const char *name);
void g_igenerator_generate (GIGenerator *igenerator);
GIGenerator *the_igenerator;
typedef enum {
CSYMBOL_TYPE_INVALID,
CSYMBOL_TYPE_CONST,
CSYMBOL_TYPE_OBJECT,
CSYMBOL_TYPE_FUNCTION,
CSYMBOL_TYPE_STRUCT,
CSYMBOL_TYPE_UNION,
CSYMBOL_TYPE_ENUM,
CSYMBOL_TYPE_TYPEDEF
} CSymbolType;
struct _CSymbol {
CSymbolType type;
int id;
char *ident;
CType *base_type;
gboolean const_int_set;
int const_int;
char *const_string;
};
CSymbol *csymbol_new (CSymbolType type);
gboolean csymbol_get_const_boolean (CSymbol *symbol);
typedef enum {
CTYPE_INVALID,
CTYPE_VOID,
CTYPE_BASIC_TYPE,
CTYPE_TYPEDEF,
CTYPE_STRUCT,
CTYPE_UNION,
CTYPE_ENUM,
CTYPE_POINTER,
CTYPE_ARRAY,
CTYPE_FUNCTION
} CTypeType;
typedef enum {
STORAGE_CLASS_NONE = 0,
STORAGE_CLASS_TYPEDEF = 1 << 1,
STORAGE_CLASS_EXTERN = 1 << 2,
STORAGE_CLASS_STATIC = 1 << 3,
STORAGE_CLASS_AUTO = 1 << 4,
STORAGE_CLASS_REGISTER = 1 << 5
} StorageClassSpecifier;
typedef enum {
TYPE_QUALIFIER_NONE = 0,
TYPE_QUALIFIER_CONST = 1 << 1,
TYPE_QUALIFIER_RESTRICT = 1 << 2,
TYPE_QUALIFIER_VOLATILE = 1 << 3
} TypeQualifier;
typedef enum {
FUNCTION_NONE = 0,
FUNCTION_INLINE = 1 << 1
} FunctionSpecifier;
typedef enum {
UNARY_ADDRESS_OF,
UNARY_POINTER_INDIRECTION,
UNARY_PLUS,
UNARY_MINUS,
UNARY_BITWISE_COMPLEMENT,
UNARY_LOGICAL_NEGATION
} UnaryOperator;
struct _CType {
CTypeType type;
StorageClassSpecifier storage_class_specifier;
TypeQualifier type_qualifier;
FunctionSpecifier function_specifier;
char *name;
CType *base_type;
GList *child_list;
};
CType *ctype_new (CTypeType type);
CType *ctype_copy (CType *type);
CType *cbasic_type_new (const char *name);
CType *ctypedef_new (const char *name);
CType *cstruct_new (const char *name);
CType *cunion_new (const char *name);
CType *cenum_new (const char *name);
CType *cpointer_new (CType *base_type);
CType *carray_new (void);
CType *cfunction_new (void);
G_END_DECLS
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment