Skip to content

Commit

Permalink
Clean makefile parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Nov 1, 2009
1 parent a402de3 commit f6c1688
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 628 deletions.
20 changes: 19 additions & 1 deletion libanjuta/anjuta-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,30 @@ anjuta_project_node_all (AnjutaProjectNode *parent, AnjutaProjectNodeType type)
return list;
}

typedef struct
{
AnjutaProjectNodeFunc func;
gpointer data;
} AnjutaProjectNodePacket;

static gboolean
anjuta_project_node_traverse_func (GNode *node, gpointer data)
{
AnjutaProjectNodePacket *pack = (AnjutaProjectNodePacket *)data;

pack->func ((AnjutaProjectNode *)node, pack->data);

return FALSE;
}

void
anjuta_project_node_all_foreach (AnjutaProjectNode *node, AnjutaProjectNodeFunc func, gpointer data)
{
AnjutaProjectNodePacket pack = {func, data};

/* POST_ORDER is important when deleting the node, children has to be
* deleted first */
g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, -1, func, data);
g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, -1, anjuta_project_node_traverse_func, &pack);
}

void
Expand Down
2 changes: 1 addition & 1 deletion libanjuta/anjuta-project.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ typedef GNode AnjutaProjectGroup;
typedef GNode AnjutaProjectTarget;
typedef GNode AnjutaProjectSource;

typedef GNodeTraverseFunc AnjutaProjectNodeFunc;
typedef void (*AnjutaProjectNodeFunc) (AnjutaProjectNode *node, gpointer data);

AnjutaProjectNode *anjuta_project_node_parent (AnjutaProjectNode *node);
AnjutaProjectNode *anjuta_project_node_first_child (AnjutaProjectNode *node);
Expand Down
2 changes: 1 addition & 1 deletion libanjuta/anjuta-token.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ anjuta_token_insert_before (AnjutaToken *sibling, AnjutaToken *baby)
}

void
anjuta_token_foreach (AnjutaToken *token, AnjutaTokenFunc func, gpointer data)
anjuta_token_foreach (AnjutaToken *token, AnjutaTokenTraverseFunc func, gpointer data)
{
g_node_traverse ((GNode *)token, G_PRE_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc)func, data);
}
Expand Down
5 changes: 3 additions & 2 deletions libanjuta/anjuta-token.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ enum AnjutaTokenSearchFlag
ANJUTA_SEARCH_BACKWARD = 1 << 2
};

typedef gboolean (*AnjutaTokenFunc) (AnjutaToken* token, gpointer data);
typedef gboolean (*AnjutaTokenTraverseFunc) (AnjutaToken* token, gpointer data);
typedef gboolean (*AnjutaTokenForeachFunc) (AnjutaToken* token, gpointer data);

AnjutaToken *anjuta_token_new_string (AnjutaTokenType type, const gchar *value);
AnjutaToken *anjuta_token_new_with_string (AnjutaTokenType type, gchar *value, gsize length);
Expand Down Expand Up @@ -133,7 +134,7 @@ AnjutaToken *anjuta_token_insert_after (AnjutaToken *token, AnjutaToken *sibling
AnjutaToken *anjuta_token_insert_before (AnjutaToken *token, AnjutaToken *sibling);
gboolean anjuta_token_match (AnjutaToken *token, gint flags, AnjutaToken *sequence, AnjutaToken **end);

void anjuta_token_foreach (AnjutaToken *token, AnjutaTokenFunc, gpointer data);
void anjuta_token_foreach (AnjutaToken *token, AnjutaTokenForeachFunc, gpointer data);


//AnjutaToken *anjuta_token_copy (AnjutaToken *token);
Expand Down
12 changes: 11 additions & 1 deletion src/am-project-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@

G_BEGIN_DECLS

struct _AmpPackage {
gchar *name;
gchar *version;
};

struct _AmpModule {
GList *packages;
AnjutaTokenGroup *module;
};

struct _AmpProperty {
AnjutaToken *ac_init; /* AC_INIT macro */
AnjutaTokenGroup *ac_init; /* AC_INIT macro */
gchar *name;
gchar *version;
gchar *bug_report;
Expand Down
68 changes: 4 additions & 64 deletions src/am-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,8 @@ static const gchar *valid_am_makefiles[] = {"GNUmakefile.am", "makefile.am", "Ma

typedef struct _AmpPackage AmpPackage;

struct _AmpPackage {
gchar *name;
gchar *version;
};

typedef struct _AmpModule AmpModule;

struct _AmpModule {
GList *packages;
AnjutaToken *module;
};

typedef enum {
AM_GROUP_TOKEN_CONFIGURE,
AM_GROUP_TOKEN_SUBDIRS,
Expand Down Expand Up @@ -124,7 +114,7 @@ typedef struct _AmpSourceData AmpSourceData;

struct _AmpSourceData {
AnjutaProjectSourceData base;
AnjutaToken* token;
AnjutaTokenGroup* token;
};

typedef struct _AmpConfigFile AmpConfigFile;
Expand Down Expand Up @@ -578,7 +568,7 @@ amp_package_free (AmpPackage *package)
*---------------------------------------------------------------------------*/

static AmpModule*
amp_module_new (AnjutaToken *token)
amp_module_new (AnjutaTokenGroup *token)
{
AmpModule *module;

Expand Down Expand Up @@ -1084,10 +1074,6 @@ amp_project_load_config (AmpProject *project, AnjutaTokenGroup *arg_list)
AnjutaTokenGroup *arg;
AnjutaToken *list;
AnjutaToken *item;
gchar *value;
AmpModule *mod;
AmpPackage *pack;
gchar *compare;

/* File list */
scanner = amp_ac_scanner_new (project);
Expand Down Expand Up @@ -1384,7 +1370,6 @@ project_load_makefile (AmpProject *project, GFile *file, AnjutaProjectGroup *par
AnjutaToken *arg;
AnjutaTokenFile *tfile;
GFile *makefile = NULL;
gboolean found;

/* Create group */
group = amp_group_new (file, dist_only);
Expand Down Expand Up @@ -1441,51 +1426,6 @@ project_load_makefile (AmpProject *project, GFile *file, AnjutaProjectGroup *par
arg = anjuta_token_file_load (tfile, NULL);
arg = amp_am_scanner_parse_token (scanner, anjuta_token_next_child (arg), NULL);
amp_am_scanner_free (scanner);

/* Find significant token */
//significant_tok = anjuta_token_new_static (ANJUTA_TOKEN_STATEMENT, NULL);

//arg = anjuta_token_file_first (AMP_GROUP_DATA (group)->tfile);
//anjuta_token_old_dump_range (arg, NULL);

#if 0
/* Create hash table for sources list */
orphan_sources = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)free_source_list);

for (found = anjuta_token_match (significant_tok, ANJUTA_SEARCH_INTO, arg, &arg); found; found = anjuta_token_match (significant_tok, ANJUTA_SEARCH_INTO, anjuta_token_next_sibling (arg), &arg))
{
AnjutaToken *name = anjuta_token_next_child (arg);

switch (anjuta_token_get_type (name))
{
case AM_TOKEN_SUBDIRS:
project_load_subdirs (project, name, group, FALSE);
break;
case AM_TOKEN_DIST_SUBDIRS:
project_load_subdirs (project, name, group, TRUE);
break;
case AM_TOKEN__DATA:
case AM_TOKEN__HEADERS:
case AM_TOKEN__LIBRARIES:
case AM_TOKEN__LISP:
case AM_TOKEN__LTLIBRARIES:
case AM_TOKEN__MANS:
case AM_TOKEN__PROGRAMS:
case AM_TOKEN__PYTHON:
case AM_TOKEN__JAVA:
case AM_TOKEN__SCRIPTS:
case AM_TOKEN__TEXINFOS:
project_load_target (project, name, group, orphan_sources);
break;
case AM_TOKEN__SOURCES:
project_load_sources (project, name, group, orphan_sources);
break;
}
}

/* Free unused sources files */
g_hash_table_destroy (orphan_sources);
#endif

return group;
}
Expand Down Expand Up @@ -1545,7 +1485,7 @@ amp_project_reload (AmpProject *project, GError **error)
/* shortcut hash tables */
project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
project->files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, g_object_unref);
project->configs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, amp_config_file_free);
project->configs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, (GDestroyNotify)amp_config_file_free);
amp_project_new_module_hash (project);

/* Initialize list styles */
Expand Down Expand Up @@ -2300,7 +2240,7 @@ amp_project_move (AmpProject *project, const gchar *path)

/* Change all configs */
old_hash = project->configs;
project->configs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, amp_config_file_free);
project->configs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, (GDestroyNotify)amp_config_file_free);
g_hash_table_iter_init (&iter, old_hash);
while (g_hash_table_iter_next (&iter, &key, (gpointer *)&cfg))
{
Expand Down
Loading

0 comments on commit f6c1688

Please sign in to comment.