Skip to content

Commit

Permalink
One write of AC_INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Nov 8, 2009
1 parent b5dcff1 commit b122ff2
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 93 deletions.
88 changes: 88 additions & 0 deletions libanjuta/anjuta-token-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,94 @@ anjuta_token_file_get_file (AnjutaTokenFile *file)
return file->file;
}

/**
* anjuta_token_file_update:
* @file: a #AnjutaTokenFile derived class object.
* @token: Token to update.
*
* Update the file with all changed token starting from @token. The function can
* return an error if the token is not in the file.
*
* Return value: TRUE is the update is done without error.
*/
gboolean
anjuta_token_file_update (AnjutaTokenFile *file, AnjutaToken *token)
{
AnjutaToken *prev;
AnjutaToken *start = NULL;
AnjutaToken *next;
const gchar *pos;
const gchar *ptr;
const gchar *last;
const gchar *end;

/* Find position a token in the file */
for (prev = token; prev != NULL; prev = anjuta_token_previous_sibling (prev))
{
if (anjuta_token_get_string (prev) != NULL)
{
gint flags = anjuta_token_get_flags (prev);
if (!(flags & (ANJUTA_TOKEN_ADDED | ANJUTA_TOKEN_REMOVED))) break;
token = prev;
}
}

/* Find token position */
if (prev != NULL)
{
pos = anjuta_token_get_string (prev);
for (start = file->content; start != NULL; start = anjuta_token_next (start))
{
guint len = anjuta_token_get_length (start);

if (len)
{
ptr = anjuta_token_get_string (start);
end = ptr + len;

if ((pos >= ptr) && (pos < end)) break;
}
}
if (ptr != pos)
{
start = anjuta_token_split (start, ptr - pos);
start = anjuta_token_next (start);
}
}

/* Updated token */
last = pos;
for (next = token; next != NULL; next = anjuta_token_next_sibling (next))
{
gint flags = anjuta_token_get_flags (next);

if (flags & ANJUTA_TOKEN_REMOVED)
{
guint len = anjuta_token_get_length (next);
}
else if (flags & ANJUTA_TOKEN_ADDED)
{
AnjutaToken* copy = anjuta_token_copy_token (next);

if (start == NULL)
{
start = anjuta_token_insert_child (file->content, copy);
}
else
{
start = anjuta_token_insert_after (start, copy);
}
}
else
{
break;
}
}

return TRUE;
}


/* GObject functions
*---------------------------------------------------------------------------*/

Expand Down
2 changes: 2 additions & 0 deletions libanjuta/anjuta-token-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void anjuta_token_file_move (AnjutaTokenFile *file, GFile *new_file);

gboolean anjuta_token_file_get_token_location (AnjutaTokenFile *file, AnjutaTokenFileLocation *location, AnjutaToken *token);

gboolean anjuta_token_file_update (AnjutaTokenFile *file, AnjutaToken *token);

AnjutaToken* anjuta_token_file_get_content (AnjutaTokenFile *file);
GFile *anjuta_token_file_get_file (AnjutaTokenFile *file);

Expand Down
81 changes: 44 additions & 37 deletions libanjuta/anjuta-token-style.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,29 +305,31 @@ anjuta_token_list_first (AnjutaToken *list)
{
AnjutaToken *token;

token = anjuta_token_next_child (list);
if (token == NULL) return token;

if (anjuta_token_get_type (token) == ANJUTA_TOKEN_START)
for (token = list; token != NULL; token = anjuta_token_next (token))
{
token = anjuta_token_next_sibling (token);
if (anjuta_token_get_type (token) == ANJUTA_TOKEN_START)
{
return token;
}
}

return token;
return NULL;
}

AnjutaToken *
anjuta_token_list_last (AnjutaToken *list)
{
AnjutaToken *token;

token = anjuta_token_list_first (list);
for (;;)
for (token = list; token != NULL; token = anjuta_token_next (token))
{
AnjutaToken *next = anjuta_token_list_next (list);
if (next == NULL) return token;
token = next;
if (anjuta_token_get_type (token) == ANJUTA_TOKEN_LAST)
{
return token;
}
}

return NULL;
}

AnjutaToken *
Expand All @@ -347,23 +349,31 @@ anjuta_token_list_next (AnjutaToken *sibling)
}

AnjutaToken *
anjuta_token_list_replace (AnjutaToken *sibling, AnjutaToken *baby)
anjuta_token_list_replace (AnjutaToken *sibling, AnjutaToken *token)
{
AnjutaToken *token;

token = anjuta_token_insert_before (sibling, baby);
if ((anjuta_token_get_type (sibling) != ANJUTA_TOKEN_NEXT) && (anjuta_token_get_type (sibling) != ANJUTA_TOKEN_LAST))
for (;; sibling = anjuta_token_next (sibling))
{
anjuta_token_remove (sibling);
switch (anjuta_token_get_type (sibling))
{
case ANJUTA_TOKEN_NEXT:
case ANJUTA_TOKEN_LAST:
break;
default:
anjuta_token_remove (sibling);
continue;
}
break;
}
token = anjuta_token_insert_before (sibling, token);

return token;
}

AnjutaToken *
anjuta_token_list_replace_nth (AnjutaToken *list, guint n, AnjutaToken *baby)
anjuta_token_list_replace_nth (AnjutaToken *list, guint n, AnjutaToken *item)
{
AnjutaToken *token;
gboolean no_item = TRUE;

token = anjuta_token_list_first (list);
if (token == NULL)
Expand All @@ -372,31 +382,28 @@ anjuta_token_list_replace_nth (AnjutaToken *list, guint n, AnjutaToken *baby)
token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
}

for (; n != 0; n--)
for (n++; n == 0;)
{
AnjutaToken *next;

switch (anjuta_token_get_type (token))
{
case ANJUTA_TOKEN_LAST:
anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
continue;
case ANJUTA_TOKEN_NEXT:
break;
default:
token = anjuta_token_next_sibling (token);
if (token == NULL)
{
token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
}
else if (anjuta_token_get_type (token) == ANJUTA_TOKEN_LAST)
{
token = anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
}
break;
case ANJUTA_TOKEN_LAST:
anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
continue;
case ANJUTA_TOKEN_NEXT:
if (no_item) n--;
no_item = TRUE;
break;
case ANJUTA_TOKEN_ITEM:
n--;
no_item = FALSE;
break;
default:
break;
}

next = anjuta_token_next_sibling (token);
next = anjuta_token_next (token);
if (next == NULL)
{
token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
Expand All @@ -407,7 +414,7 @@ anjuta_token_list_replace_nth (AnjutaToken *list, guint n, AnjutaToken *baby)
}
}

return anjuta_token_list_replace (token, baby);
return anjuta_token_list_replace (token, item);
}

AnjutaToken *
Expand Down
11 changes: 10 additions & 1 deletion libanjuta/anjuta-token.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,16 @@ anjuta_token_insert_after (AnjutaToken *sibling, AnjutaToken *token)
AnjutaToken *
anjuta_token_insert_before (AnjutaToken *sibling, AnjutaToken *baby)
{
return (AnjutaToken *)g_node_insert_before ((GNode *)sibling->parent, (GNode *)sibling, (GNode *)baby);
AnjutaToken *next = NULL;
AnjutaToken *token;

for (token = baby; token != NULL; token = next)
{
next = anjuta_token_next (token);
g_node_insert_before ((GNode *)sibling->parent, (GNode *)sibling, (GNode *)token);
}

return baby;
}

void
Expand Down
6 changes: 4 additions & 2 deletions src/ac-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
/* Token location is found directly from token value, there is no need to
* maintain a separate location variable */
#define YYLLOC_DEFAULT(Current, Rhs, N) ((Current) = YYRHSLOC(Rhs, (N) ? 1 : 0))

%}

%union {
Expand All @@ -52,7 +53,8 @@
%token <token> COMMA ','
%token <token> LOWER '<'
%token <token> GREATER '>'


%token <token> COMMENT
%token <token> NAME
%token <token> VARIABLE
%token <token> MACRO
Expand Down Expand Up @@ -221,7 +223,7 @@ ac_macro_with_arg:

ac_init:
AC_INIT arg_list {
amp_ac_scanner_load_properties (scanner, $2);
amp_ac_scanner_load_properties (scanner, $1, $2);
}

ac_output:
Expand Down
5 changes: 3 additions & 2 deletions src/ac-scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AnjutaToken* amp_ac_scanner_parse_token (AmpAcScanner *scanner, AnjutaToken *tok

void amp_ac_scanner_load_module (AmpAcScanner *scanner, AnjutaTokenGroup *module);
void amp_ac_scanner_load_config (AmpAcScanner *scanner, AnjutaTokenGroup *list);
void amp_ac_scanner_load_properties (AmpAcScanner *scanner, AnjutaTokenGroup *list);
void amp_ac_scanner_load_properties (AmpAcScanner *scanner, AnjutaToken *macro, AnjutaTokenGroup *args);

void amp_ac_yyerror (YYLTYPE *loc, AmpAcScanner *scanner, char const *s);

Expand All @@ -52,7 +52,8 @@ enum
AC_TOKEN_AC_OUTPUT,
AC_TOKEN_SPACE_LIST,
AC_TOKEN_OPEN_STRING,
AC_TOKEN_CLOSE_STRING
AC_TOKEN_CLOSE_STRING,
AC_TOKEN_AC_PREREQ,
};

enum
Expand Down
4 changes: 2 additions & 2 deletions src/ac-scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ amp_ac_scanner_load_config (AmpAcScanner *scanner, AnjutaTokenGroup *list)
}

void
amp_ac_scanner_load_properties (AmpAcScanner *scanner, AnjutaTokenGroup *list)
amp_ac_scanner_load_properties (AmpAcScanner *scanner, AnjutaToken *macro, AnjutaTokenGroup *list)
{
amp_project_load_properties (scanner->project, list);
amp_project_load_properties (scanner->project, macro, list);
}


Expand Down
Loading

0 comments on commit b122ff2

Please sign in to comment.