[anjuta] am-project: Place new PKG_CHECK_MODULES at the right place
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] am-project: Place new PKG_CHECK_MODULES at the right place
- Date: Fri, 28 Jan 2011 22:03:12 +0000 (UTC)
commit 09257c66ce03c0b3814631a221212b502f32d4ef
Author: Sébastien Granjoux <seb sfo free fr>
Date: Fri Jan 28 22:59:05 2011 +0100
am-project: Place new PKG_CHECK_MODULES at the right place
plugins/am-project/ac-parser.y | 163 ++++++++++++++++++++++++++++++++---
plugins/am-project/ac-scanner.h | 54 +++++++++++-
plugins/am-project/ac-scanner.l | 70 +++++++++++++++-
plugins/am-project/ac-writer.c | 147 +++++++++++++++++++-------------
plugins/am-project/tests/module.at | 10 +--
5 files changed, 357 insertions(+), 87 deletions(-)
---
diff --git a/plugins/am-project/ac-parser.y b/plugins/am-project/ac-parser.y
index a41d5fd..0b3f400 100644
--- a/plugins/am-project/ac-parser.y
+++ b/plugins/am-project/ac-parser.y
@@ -69,12 +69,43 @@
%token AC_MACRO_WITH_ARG
%token AC_MACRO_WITHOUT_ARG
-%token PKG_CHECK_MODULES
-%token OBSOLETE_AC_OUTPUT
-%token AC_OUTPUT
+%token AC_ARG_ENABLE
+%token AC_C_CONST
+%token AC_CHECK_FUNCS
+%token AC_CHECK_HEADERS
+%token AC_CHECK_LIB
+%token AC_CHECK_PROG
%token AC_CONFIG_FILES
-%token AC_SUBST
+%token AC_CONFIG_HEADERS
+%token AC_CONFIG_MACRO_DIR
+%token AC_CONFIG_SRCDIR
+%token AC_EGREP_HEADER
+%token AC_EXEEXT
+%token AC_HEADER_STDC
%token AC_INIT
+%token AC_OBJEXT
+%token AC_OUTPUT
+%token OBSOLETE_AC_OUTPUT
+%token AC_PREREQ
+%token AC_PROG_CC
+%token AC_PROG_CPP
+%token AC_PROG_CXX
+%token IT_PROG_INTLTOOL
+%token AC_PROG_LEX
+%token AC_PROG_RANLIB
+%token AC_PROG_YACC
+%token AC_SUBST
+%token AC_TYPE_SIZE_T
+%token AC_TYPE_OFF_T
+%token AM_INIT_AUTOMAKE
+%token AM_GLIB_GNU_GETTEXT
+%token AM_MAINTAINER_MODE
+%token AM_PROG_LIBTOOL
+%token LT_INIT
+%token LT_PREREQ
+%token PKG_CHECK_MODULES
+%token PKG_PROG_PKG_CONFIG
+
%defines
@@ -93,6 +124,54 @@
%debug
+%{
+
+static gint
+amp_ac_autoconf_macro (AnjutaToken *token)
+{
+ switch (anjuta_token_get_type (token))
+ {
+ case AC_ARG_ENABLE: return AC_TOKEN_AC_ARG_ENABLE;
+ case AC_C_CONST: return AC_TOKEN_AC_C_CONST;
+ case AC_CHECK_FUNCS: return AC_TOKEN_AC_CHECK_FUNCS;
+ case AC_CHECK_HEADERS: return AC_TOKEN_AC_CHECK_HEADERS;
+ case AC_CHECK_LIB: return AC_TOKEN_AC_CHECK_LIB;
+ case AC_CHECK_PROG: return AC_TOKEN_AC_CHECK_PROG;
+ case AC_CONFIG_FILES: return AC_TOKEN_AC_CONFIG_FILES;
+ case AC_CONFIG_HEADERS: return AC_TOKEN_AC_CONFIG_HEADERS;
+ case AC_CONFIG_MACRO_DIR: return AC_TOKEN_AC_CONFIG_MACRO_DIR;
+ case AC_CONFIG_SRCDIR: return AC_TOKEN_AC_CONFIG_SRCDIR;
+ case AC_EGREP_HEADER: return AC_TOKEN_AC_EGREP_HEADER;
+ case AC_EXEEXT: return AC_TOKEN_AC_EXEEXT;
+ case AC_HEADER_STDC: return AC_TOKEN_AC_HEADER_STDC;
+ case AC_INIT: return AC_TOKEN_AC_INIT;
+ case AC_OBJEXT: return AC_TOKEN_AC_OBJEXT;
+ case AC_OUTPUT: return AC_TOKEN_AC_OUTPUT;
+ case OBSOLETE_AC_OUTPUT: return AC_TOKEN_OBSOLETE_AC_OUTPUT;
+ case AC_PREREQ: return AC_TOKEN_AC_PREREQ;
+ case AC_PROG_CC: return AC_TOKEN_AC_PROG_CC;
+ case AC_PROG_CPP: return AC_TOKEN_AC_PROG_CPP;
+ case AC_PROG_CXX: return AC_TOKEN_AC_PROG_CXX;
+ case IT_PROG_INTLTOOL: return AC_TOKEN_IT_PROG_INTLTOOL;
+ case AC_PROG_LEX: return AC_TOKEN_AC_PROG_LEX;
+ case AC_PROG_RANLIB: return AC_TOKEN_AC_PROG_RANLIB;
+ case AC_PROG_YACC: return AC_TOKEN_AC_PROG_YACC;
+ case AC_TYPE_SIZE_T: return AC_TOKEN_AC_TYPE_SIZE_T;
+ case AC_TYPE_OFF_T: return AC_TOKEN_AC_TYPE_OFF_T;
+ case AM_INIT_AUTOMAKE: return AC_TOKEN_AM_INIT_AUTOMAKE;
+ case AM_GLIB_GNU_GETTEXT: return AC_TOKEN_AM_GLIB_GNU_GETTEXT;
+ case AM_MAINTAINER_MODE: return AC_TOKEN_AM_MAINTAINER_MODE;
+ case AM_PROG_LIBTOOL: return AC_TOKEN_AM_PROG_LIBTOOL;
+ case LT_INIT: return AC_TOKEN_LT_INIT;
+ case LT_PREREQ: return AC_TOKEN_LT_PREREQ;
+ case PKG_CHECK_MODULES: return AC_TOKEN_PKG_CHECK_MODULES;
+ case PKG_PROG_PKG_CONFIG: return AC_TOKEN_PKG_PROG_PKG_CONFIG;
+ default: return anjuta_token_get_type (token);
+ }
+}
+
+%}
+
%%
input:
@@ -178,7 +257,12 @@ name:
*----------------------------------------------------------------------------*/
dnl:
- DNL not_eol_list EOL
+ DNL not_eol_list EOL {
+ $$ = anjuta_token_new_static (ANJUTA_TOKEN_COMMENT, NULL);
+ anjuta_token_merge ($$, $1);
+ anjuta_token_merge ($$, $2);
+ anjuta_token_merge ($$, $3);
+ }
;
@@ -191,18 +275,23 @@ pkg_check_modules:
}
;
-ac_macro_without_arg:
- AC_MACRO_WITHOUT_ARG
- ;
-
optional_arg:
/* empty */ %prec EMPTY
| COMMA NAME %prec ARG
;
ac_macro_with_arg:
- AC_MACRO_WITH_ARG optional_arg RIGHT_PAREN
+ ac_macro_with_arg_token arg_list {
+ $$ = anjuta_token_new_static (amp_ac_autoconf_macro ($1), NULL);
+ anjuta_token_merge ($$, $1);
+ anjuta_token_merge ($$, $2);
+ }
;
+
+ac_macro_without_arg:
+ ac_macro_without_arg_token {
+ anjuta_token_set_type ($1, amp_ac_autoconf_macro ($1));
+ }
ac_init:
AC_INIT arg_list {
@@ -276,7 +365,12 @@ arg_list_body:
;
comment:
- HASH not_eol_list EOL
+ HASH not_eol_list EOL {
+ $$ = anjuta_token_new_static (ANJUTA_TOKEN_COMMENT, NULL);
+ anjuta_token_merge ($$, $1);
+ anjuta_token_merge ($$, $2);
+ anjuta_token_merge ($$, $3);
+ }
;
not_eol_list:
@@ -533,7 +627,9 @@ not_brace_token:
space_token:
SPACE
- | EOL
+ | EOL {
+ anjuta_token_set_type ($1, ANJUTA_TOKEN_EOL);
+ }
;
args_token:
@@ -574,13 +670,52 @@ word_token:
any_macro:
AC_CONFIG_FILES
- | AC_MACRO_WITH_ARG
- | AC_MACRO_WITHOUT_ARG
| AC_OUTPUT
| DNL
| OBSOLETE_AC_OUTPUT
| PKG_CHECK_MODULES
| AC_INIT
+ | ac_macro_with_arg_token
+ | ac_macro_without_arg_token
;
+ac_macro_without_arg_token:
+ AC_MACRO_WITHOUT_ARG
+ | AC_C_CONST
+ | AC_EXEEXT
+ | AC_HEADER_STDC
+ | AC_OBJEXT
+ | AC_PROG_CC
+ | AC_PROG_CPP
+ | AC_PROG_CXX
+ | AC_PROG_LEX
+ | AC_PROG_RANLIB
+ | AC_PROG_YACC
+ | AC_TYPE_SIZE_T
+ | AC_TYPE_OFF_T
+ | AM_MAINTAINER_MODE
+ | AM_PROG_LIBTOOL
+ ;
+
+ac_macro_with_arg_token:
+ AC_MACRO_WITH_ARG
+ | AC_ARG_ENABLE
+ | AC_CHECK_FUNCS
+ | AC_CHECK_HEADERS
+ | AC_CHECK_LIB
+ | AC_CHECK_PROG
+ | AC_CONFIG_HEADERS
+ | AC_CONFIG_MACRO_DIR
+ | AC_CONFIG_SRCDIR
+ | AC_EGREP_HEADER
+ | AC_PREREQ
+ | IT_PROG_INTLTOOL
+ | AC_SUBST
+ | AM_INIT_AUTOMAKE
+ | AM_GLIB_GNU_GETTEXT
+ | LT_INIT
+ | LT_PREREQ
+ | PKG_PROG_PKG_CONFIG
+ ;
+
%%
diff --git a/plugins/am-project/ac-scanner.h b/plugins/am-project/ac-scanner.h
index 48b5f75..f81d40c 100644
--- a/plugins/am-project/ac-scanner.h
+++ b/plugins/am-project/ac-scanner.h
@@ -48,15 +48,63 @@ void amp_ac_yyerror (YYLTYPE *loc, AmpAcScanner *scanner, char const *s);
enum
{
- AC_TOKEN_AC_INIT = ANJUTA_TOKEN_USER,
+ /* Order is important as the backend will try to follow it */
+ AC_TOKEN_FIRST_ORDERED_MACRO = ANJUTA_TOKEN_USER,
+ /* requirements & informations */
+ AC_TOKEN_AC_PREREQ,
+ AC_TOKEN_AC_INIT,
+ AC_TOKEN_AC_CONFIG_HEADERS,
+ AC_TOKEN_AC_CONFIG_SRCDIR,
+ AC_TOKEN_AC_CONFIG_MACRO_DIR,
+ AC_TOKEN_AM_INIT_AUTOMAKE,
+
+ /* Options */
+ AC_TOKEN_AM_MAINTAINER_MODE,
+ AC_TOKEN_AC_ARG_ENABLE,
+
+ /* Check for programs */
+ AC_TOKEN_AC_PROG_CC,
+ AC_TOKEN_AC_PROG_CPP,
+ AC_TOKEN_AC_PROG_CXX,
+ AC_TOKEN_AC_PROG_LEX,
+ AC_TOKEN_AC_PROG_YACC,
+ AC_TOKEN_AC_PROG_RANLIB,
+ AC_TOKEN_IT_PROG_INTLTOOL,
+ AC_TOKEN_LT_PREREQ,
+ AC_TOKEN_AM_PROG_LIBTOOL,
+ AC_TOKEN_LT_INIT,
+ AC_TOKEN_PKG_PROG_PKG_CONFIG,
+ AC_TOKEN_AC_CHECK_PROG,
+ AC_TOKEN_AM_GLIB_GNU_GETTEXT,
+
+ /* Check for libraries */
AC_TOKEN_PKG_CHECK_MODULES,
+ AC_TOKEN_AC_CHECK_LIB,
+
+ /* Check for headers */
+ AC_TOKEN_AC_HEADER_STDC,
+ AC_TOKEN_AC_CHECK_HEADERS,
+ AC_TOKEN_AC_EGREP_HEADER,
+
+ /* Check for types & structures */
+ AC_TOKEN_AC_C_CONST,
+ AC_TOKEN_AC_OBJEXT,
+ AC_TOKEN_AC_EXEEXT,
+ AC_TOKEN_AC_TYPE_SIZE_T,
+ AC_TOKEN_AC_TYPE_OFF_T,
+
+ /* Check for functions */
+ AC_TOKEN_AC_CHECK_FUNCS,
+
+ /* Output files */
AC_TOKEN_AC_CONFIG_FILES,
AC_TOKEN_OBSOLETE_AC_OUTPUT,
AC_TOKEN_AC_OUTPUT,
+ AC_TOKEN_LAST_ORDERED_MACRO,
+
AC_TOKEN_SPACE_LIST,
AC_TOKEN_OPEN_STRING,
- AC_TOKEN_CLOSE_STRING,
- AC_TOKEN_AC_PREREQ,
+ AC_TOKEN_CLOSE_STRING
};
enum
diff --git a/plugins/am-project/ac-scanner.l b/plugins/am-project/ac-scanner.l
index 09c1294..162cbc6 100644
--- a/plugins/am-project/ac-scanner.l
+++ b/plugins/am-project/ac-scanner.l
@@ -120,15 +120,77 @@ OTHER [^ \t\r\v\n#\[\]\\(),=><$_A-Za-z_]+
dnl { RETURN (DNL); }
-PKG_CHECK_MODULES\( { RETURN (PKG_CHECK_MODULES); }
+AC_ARG_ENABLE\( { RETURN (AC_ARG_ENABLE);}
+
+AC_C_CONST { RETURN (AC_C_CONST);}
+
+AC_CHECK_FUNCS\( { RETURN (AC_CHECK_FUNCS);}
+
+AC_CHECK_HEADERS\( { RETURN (AC_CHECK_HEADERS);}
+
+AC_CHECK_LIB\( { RETURN (AC_CHECK_LIB);}
+
+AC_CHECK_PROG\( { RETURN (AC_CHECK_PROG);}
+
+AC_CONFIG_FILES\( { RETURN (AC_CONFIG_FILES); }
+
+AC_CONFIG_HEADERS\( { RETURN (AC_CONFIG_HEADERS); }
+
+AC_CONFIG_MACRO_DIR\( { RETURN (AC_CONFIG_MACRO_DIR); }
+
+AC_CONFIG_SRCDIR\( { RETURN (AC_CONFIG_SRCDIR); }
+
+AC_EGREP_HEADER\( { RETURN (AC_EGREP_HEADER); }
+
+AC_EXEEXT { RETURN (AC_EXEEXT); }
+
+AC_HEADER_STDC { RETURN (AC_HEADER_STDC); }
+
+AC_INIT\( { RETURN (AC_INIT); }
+
+AC_OBJEXT { RETURN (AC_OBJEXT); }
AC_OUTPUT\( { RETURN (OBSOLETE_AC_OUTPUT); }
AC_OUTPUT { RETURN (AC_OUTPUT); }
-AC_INIT\( { RETURN (AC_INIT); }
-
-AC_CONFIG_FILES\( { RETURN (AC_CONFIG_FILES); }
+AC_PREREQ\( { RETURN (AC_PREREQ); }
+
+AC_PROG_CC { RETURN (AC_PROG_CC);}
+
+AC_PROG_CPP { RETURN (AC_PROG_CPP);}
+
+AC_PROG_CXX { RETURN (AC_PROG_CXX);}
+
+IT_PROG_INTLTOOL\( { RETURN (IT_PROG_INTLTOOL);}
+
+AC_PROG_LEX { RETURN (AC_PROG_LEX);}
+
+AC_PROG_RANLIB { RETURN (AC_PROG_RANLIB);}
+
+AC_PROG_YACC { RETURN (AC_PROG_YACC);}
+
+AC_SUBST\( { RETURN (AC_SUBST);}
+
+AC_TYPE_SIZE_T { RETURN (AC_TYPE_SIZE_T);}
+
+AC_TYPE_OFF_T { RETURN (AC_TYPE_OFF_T);}
+
+AM_INIT_AUTOMAKE\( { RETURN (AM_INIT_AUTOMAKE);}
+
+AM_GLIB_GNU_GETTEXT\( { RETURN (AM_GLIB_GNU_GETTEXT);}
+
+AM_MAINTAINER_MODE { RETURN (AM_MAINTAINER_MODE);}
+
+AM_PROG_LIBTOOL { RETURN (AM_PROG_LIBTOOL);}
+
+LT_INIT\( { RETURN (LT_INIT);}
+
+LT_PREREQ\( { RETURN (LT_PREREQ);}
+
+PKG_CHECK_MODULES\( { RETURN (PKG_CHECK_MODULES); }
+
+PKG_PROG_PKG_CONFIG\( { RETURN (PKG_PROG_PKG_CONFIG);}
{NAME} { RETURN (NAME); }
diff --git a/plugins/am-project/ac-writer.c b/plugins/am-project/ac-writer.c
index 1c137a0..f3972ff 100644
--- a/plugins/am-project/ac-writer.c
+++ b/plugins/am-project/ac-writer.c
@@ -47,6 +47,79 @@
/* Private functions
*---------------------------------------------------------------------------*/
+static AnjutaToken *
+anjuta_token_find_position (AnjutaToken *list, gboolean after, AnjutaTokenType type, AnjutaToken *sibling)
+{
+ AnjutaToken *tok;
+ AnjutaToken *pos = sibling;
+
+ if (sibling == NULL)
+ {
+ AnjutaToken *last = NULL;
+ gboolean found = FALSE;
+
+ for (tok = list; tok != NULL; tok = anjuta_token_next (tok))
+ {
+ AnjutaTokenType current = anjuta_token_get_type (tok);
+
+ if ((current >= AC_TOKEN_FIRST_ORDERED_MACRO) && (current <= AC_TOKEN_LAST_ORDERED_MACRO))
+ {
+ /* Find a valid position */
+ if (after)
+ {
+ /* 1. After the last similar macro
+ * 2. After the last macro with a higher priority
+ * 3. At the end of the file
+ */
+ if (current == type)
+ {
+ pos = tok;
+ found = TRUE;
+ }
+ else if (!found && (current < type))
+ {
+ pos = tok;
+ }
+ }
+ else
+ {
+ /* 1. Before the first similar macro
+ * 2. Before the first macro with an lower priority
+ * 3. At the beginning of the file
+ */
+ if (current == type)
+ {
+ pos = tok;
+ break;
+ }
+ else if (!found && (current > type))
+ {
+ pos = tok;
+ found = TRUE;
+ }
+ }
+ }
+ last = tok;
+ }
+
+
+ if (after && (pos == NULL)) pos = last;
+ }
+
+ if (after)
+ {
+ for (; pos != NULL; pos = anjuta_token_next (pos))
+ {
+ AnjutaTokenType current = anjuta_token_get_type (pos);
+
+ if (current == ANJUTA_TOKEN_EOL) break;
+ }
+ }
+
+
+ return pos;
+}
+
static AnjutaToken*
find_tokens (AnjutaToken *list, AnjutaTokenType* types)
{
@@ -68,21 +141,6 @@ find_tokens (AnjutaToken *list, AnjutaTokenType* types)
}
static AnjutaToken *
-find_next_eol (AnjutaToken *token)
-{
- if (token == NULL) return NULL;
-
- for (;;)
- {
- AnjutaToken *next = anjuta_token_next (token);
-
- if (next == NULL) return token;
- token = next;
- if (anjuta_token_get_type (token) == EOL) return token;
- }
-}
-
-static AnjutaToken *
skip_comment (AnjutaToken *token)
{
if (token == NULL) return NULL;
@@ -191,56 +249,15 @@ amp_project_write_module_list (AmpProject *project, const gchar *name, gboolean
{
AnjutaToken *pos;
AnjutaToken *token;
- static gint pkg_type[] = {AC_TOKEN_PKG_CHECK_MODULES, 0};
- static gint eol_type[] = {ANJUTA_TOKEN_EOL, ANJUTA_TOKEN_SPACE, ANJUTA_TOKEN_COMMENT, 0};
AnjutaToken *configure;
configure = amp_project_get_configure_token (project);
-
- if (sibling == NULL)
- {
- pos = anjuta_token_find_type (configure, 0, pkg_type);
- if (pos == NULL)
- {
- gint other_type[] = {AC_TOKEN_AC_INIT,
- AC_TOKEN_PKG_CHECK_MODULES,
- AC_TOKEN_AC_PREREQ,
- 0};
-
- pos = anjuta_token_find_type (configure, ANJUTA_TOKEN_SEARCH_LAST, other_type);
- if (pos == NULL)
- {
- pos = anjuta_token_skip_comment (configure);
- }
- else
- {
- AnjutaToken* next;
- next = anjuta_token_find_type (pos, ANJUTA_TOKEN_SEARCH_NOT, eol_type);
- }
- }
-
- }
- else
- {
- pos = sibling;
- }
+ pos = anjuta_token_find_position (configure, after, AC_TOKEN_PKG_CHECK_MODULES, sibling);
- if (after && (pos != NULL))
- {
- token = anjuta_token_find_type (pos, 0, eol_type);
- if (token != NULL)
- {
- pos = token;
- }
- else
- {
- pos = anjuta_token_insert_token_list (after, pos,
- ANJUTA_TOKEN_EOL, "\n",
- NULL);
- amp_project_update_configure (project, pos);
- }
- }
+ pos = anjuta_token_insert_token_list (after, pos,
+ ANJUTA_TOKEN_EOL, "\n",
+ NULL);
pos = anjuta_token_insert_token_list (after, pos,
ANJUTA_TOKEN_EOL, "\n",
@@ -323,6 +340,16 @@ amp_module_node_delete_token (AmpProject *project, AmpModuleNode *module, GErro
{
token = anjuta_token_list (token);
anjuta_token_set_flags (token, ANJUTA_TOKEN_REMOVED);
+ token = anjuta_token_next_item (token);
+ if (anjuta_token_get_type (token) == ANJUTA_TOKEN_EOL)
+ {
+ anjuta_token_set_flags (token, ANJUTA_TOKEN_REMOVED);
+ }
+ token = anjuta_token_next_item (token);
+ if (anjuta_token_get_type (token) == ANJUTA_TOKEN_EOL)
+ {
+ anjuta_token_set_flags (token, ANJUTA_TOKEN_REMOVED);
+ }
amp_project_update_configure (project, token);
}
diff --git a/plugins/am-project/tests/module.at b/plugins/am-project/tests/module.at
index 042df30..d8547b0 100644
--- a/plugins/am-project/tests/module.at
+++ b/plugins/am-project/tests/module.at
@@ -14,6 +14,7 @@ AT_DATA([expect],
]])
AT_DATA([reference.ac],
[[PKG_CHECK_MODULES(MODULE1,)
+
AC_CONFIG_FILES(Makefile)
]])
AT_PARSER_CHECK([load empty \
@@ -36,6 +37,7 @@ AT_DATA([expect],
]])
AT_DATA([reference.ac],
[[PKG_CHECK_MODULES(MODULE1,)
+
PKG_CHECK_MODULES(MODULE2,)
AC_CONFIG_FILES(Makefile)
@@ -58,8 +60,7 @@ AT_DATA([expect],
GROUP (): empty3
]])
AT_DATA([reference.ac],
-[[
-PKG_CHECK_MODULES(MODULE2,)
+[[PKG_CHECK_MODULES(MODULE2,)
AC_CONFIG_FILES(Makefile)
]])
@@ -80,10 +81,7 @@ AT_DATA([expect],
[[ GROUP (): empty4
]])
AT_DATA([reference.ac],
-[[
-
-
-AC_CONFIG_FILES(Makefile)
+[[AC_CONFIG_FILES(Makefile)
]])
AT_PARSER_CHECK([load empty3 \
move empty4 \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]