This can be used later to do better comment matching..
return PyInt_FromLong (self->symbol->type);
}
return PyInt_FromLong (self->symbol->type);
}
+static PyObject *
+symbol_get_line (PyGISourceSymbol *self,
+ void *context)
+{
+ return PyInt_FromLong (self->symbol->line);
+}
+
static PyObject *
symbol_get_ident (PyGISourceSymbol *self,
void *context)
static PyObject *
symbol_get_ident (PyGISourceSymbol *self,
void *context)
{ "const_double", (getter)symbol_get_const_double, NULL, NULL},
{ "const_string", (getter)symbol_get_const_string, NULL, NULL},
{ "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
{ "const_double", (getter)symbol_get_const_double, NULL, NULL},
{ "const_string", (getter)symbol_get_const_string, NULL, NULL},
{ "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
+ { "line", (getter)symbol_get_line, NULL, NULL},
{
$$ = g_hash_table_lookup (const_table, $1);
if ($$ == NULL) {
{
$$ = g_hash_table_lookup (const_table, $1);
if ($$ == NULL) {
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
} else {
$$ = gi_source_symbol_ref ($$);
}
}
| INTEGER
{
} else {
$$ = gi_source_symbol_ref ($$);
}
}
| INTEGER
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
if (g_str_has_prefix (yytext, "0x") && strlen (yytext) > 2) {
$$->const_int = strtol (yytext + 2, NULL, 16);
$$->const_int_set = TRUE;
if (g_str_has_prefix (yytext, "0x") && strlen (yytext) > 2) {
$$->const_int = strtol (yytext + 2, NULL, 16);
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_double_set = TRUE;
$$->const_double = 0.0;
sscanf (yytext, "%lf", &($$->const_double));
$$->const_double_set = TRUE;
$$->const_double = 0.0;
sscanf (yytext, "%lf", &($$->const_double));
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
yytext[strlen (yytext) - 1] = '\0';
$$->const_string = g_strcompress (yytext + 1);
if (!g_utf8_validate ($$->const_string, -1, NULL))
yytext[strlen (yytext) - 1] = '\0';
$$->const_string = g_strcompress (yytext + 1);
if (!g_utf8_validate ($$->const_string, -1, NULL))
: primary_expression
| postfix_expression '[' expression ']'
{
: primary_expression
| postfix_expression '[' expression ']'
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| postfix_expression '(' argument_expression_list ')'
{
}
| postfix_expression '(' argument_expression_list ')'
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| postfix_expression '(' ')'
{
}
| postfix_expression '(' ')'
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| postfix_expression '.' identifier_or_typedef_name
{
}
| postfix_expression '.' identifier_or_typedef_name
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| postfix_expression ARROW identifier_or_typedef_name
{
}
| postfix_expression ARROW identifier_or_typedef_name
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| postfix_expression PLUSPLUS
{
}
| postfix_expression PLUSPLUS
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| postfix_expression MINUSMINUS
{
}
| postfix_expression MINUSMINUS
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
: postfix_expression
| PLUSPLUS unary_expression
{
: postfix_expression
| PLUSPLUS unary_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| MINUSMINUS unary_expression
{
}
| MINUSMINUS unary_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| unary_operator cast_expression
{
}
| unary_operator cast_expression
{
$$->const_int = !gi_source_symbol_get_const_boolean ($2);
break;
default:
$$->const_int = !gi_source_symbol_get_const_boolean ($2);
break;
default:
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
break;
}
}
| SIZEOF unary_expression
{
break;
}
}
| SIZEOF unary_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| SIZEOF '(' type_name ')'
{
ctype_free ($3);
}
| SIZEOF '(' type_name ')'
{
ctype_free ($3);
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
: cast_expression
| multiplicative_expression '*' cast_expression
{
: cast_expression
| multiplicative_expression '*' cast_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int * $3->const_int;
}
| multiplicative_expression '/' cast_expression
{
$$->const_int_set = TRUE;
$$->const_int = $1->const_int * $3->const_int;
}
| multiplicative_expression '/' cast_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
if ($3->const_int != 0) {
$$->const_int = $1->const_int / $3->const_int;
$$->const_int_set = TRUE;
if ($3->const_int != 0) {
$$->const_int = $1->const_int / $3->const_int;
}
| multiplicative_expression '%' cast_expression
{
}
| multiplicative_expression '%' cast_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
if ($3->const_int != 0) {
$$->const_int = $1->const_int % $3->const_int;
$$->const_int_set = TRUE;
if ($3->const_int != 0) {
$$->const_int = $1->const_int % $3->const_int;
: multiplicative_expression
| additive_expression '+' multiplicative_expression
{
: multiplicative_expression
| additive_expression '+' multiplicative_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int + $3->const_int;
}
| additive_expression '-' multiplicative_expression
{
$$->const_int_set = TRUE;
$$->const_int = $1->const_int + $3->const_int;
}
| additive_expression '-' multiplicative_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int - $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int - $3->const_int;
}
: additive_expression
| shift_expression SL additive_expression
{
: additive_expression
| shift_expression SL additive_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int << $3->const_int;
$$->const_int_set = TRUE;
$$->const_int = $1->const_int << $3->const_int;
}
| shift_expression SR additive_expression
{
}
| shift_expression SR additive_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int >> $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int >> $3->const_int;
}
: shift_expression
| relational_expression '<' shift_expression
{
: shift_expression
| relational_expression '<' shift_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int < $3->const_int;
}
| relational_expression '>' shift_expression
{
$$->const_int_set = TRUE;
$$->const_int = $1->const_int < $3->const_int;
}
| relational_expression '>' shift_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int > $3->const_int;
}
| relational_expression LTEQ shift_expression
{
$$->const_int_set = TRUE;
$$->const_int = $1->const_int > $3->const_int;
}
| relational_expression LTEQ shift_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int <= $3->const_int;
}
| relational_expression GTEQ shift_expression
{
$$->const_int_set = TRUE;
$$->const_int = $1->const_int <= $3->const_int;
}
| relational_expression GTEQ shift_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int >= $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int >= $3->const_int;
}
: relational_expression
| equality_expression EQ relational_expression
{
: relational_expression
| equality_expression EQ relational_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int == $3->const_int;
}
| equality_expression NOTEQ relational_expression
{
$$->const_int_set = TRUE;
$$->const_int = $1->const_int == $3->const_int;
}
| equality_expression NOTEQ relational_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int != $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int != $3->const_int;
}
: equality_expression
| and_expression '&' equality_expression
{
: equality_expression
| and_expression '&' equality_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int & $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int & $3->const_int;
}
: and_expression
| exclusive_or_expression '^' and_expression
{
: and_expression
| exclusive_or_expression '^' and_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int ^ $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int ^ $3->const_int;
}
: exclusive_or_expression
| inclusive_or_expression '|' exclusive_or_expression
{
: exclusive_or_expression
| inclusive_or_expression '|' exclusive_or_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int | $3->const_int;
}
$$->const_int_set = TRUE;
$$->const_int = $1->const_int | $3->const_int;
}
: inclusive_or_expression
| logical_and_expression ANDAND inclusive_or_expression
{
: inclusive_or_expression
| logical_and_expression ANDAND inclusive_or_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int =
gi_source_symbol_get_const_boolean ($1) &&
$$->const_int_set = TRUE;
$$->const_int =
gi_source_symbol_get_const_boolean ($1) &&
: logical_and_expression
| logical_or_expression OROR logical_and_expression
{
: logical_and_expression
| logical_or_expression OROR logical_and_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
$$->const_int_set = TRUE;
$$->const_int =
gi_source_symbol_get_const_boolean ($1) ||
$$->const_int_set = TRUE;
$$->const_int =
gi_source_symbol_get_const_boolean ($1) ||
: conditional_expression
| unary_expression assignment_operator assignment_expression
{
: conditional_expression
| unary_expression assignment_operator assignment_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
| expression ',' assignment_expression
| EXTENSION expression
{
| expression ',' assignment_expression
| EXTENSION expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
$$->name = $2;
$$->child_list = $4;
$$->name = $2;
$$->child_list = $4;
- GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
if ($$->type == CTYPE_STRUCT) {
sym->type = CSYMBOL_TYPE_STRUCT;
} else if ($$->type == CTYPE_UNION) {
if ($$->type == CTYPE_STRUCT) {
sym->type = CSYMBOL_TYPE_STRUCT;
} else if ($$->type == CTYPE_UNION) {
struct_declarator
: /* empty, support for anonymous structs and unions */
{
struct_declarator
: /* empty, support for anonymous structs and unions */
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| declarator
| ':' constant_expression
{
}
| declarator
| ':' constant_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
}
| declarator ':' constant_expression
{
}
| declarator ':' constant_expression
{
enumerator
: identifier
{
enumerator
: identifier
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_OBJECT);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_OBJECT, lineno);
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = ++last_enum_value;
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = ++last_enum_value;
}
| identifier '=' constant_expression
{
}
| identifier '=' constant_expression
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_OBJECT);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_OBJECT, lineno);
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = $3->const_int;
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = $3->const_int;
direct_declarator
: identifier
{
direct_declarator
: identifier
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
$$->ident = $1;
}
| '(' declarator ')'
$$->ident = $1;
}
| '(' declarator ')'
}
| declaration_specifiers
{
}
| declaration_specifiers
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
$$->base_type = $1;
}
| ELLIPSIS
{
$$->base_type = $1;
}
| ELLIPSIS
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_ELLIPSIS);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_ELLIPSIS, lineno);
}
;
identifier_list
: identifier
{
}
;
identifier_list
: identifier
{
- GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
sym->ident = $1;
$$ = g_list_append (NULL, sym);
}
| identifier_list ',' identifier
{
sym->ident = $1;
$$ = g_list_append (NULL, sym);
}
| identifier_list ',' identifier
{
- GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
sym->ident = $3;
$$ = g_list_append ($1, sym);
}
sym->ident = $3;
$$ = g_list_append ($1, sym);
}
abstract_declarator
: pointer
{
abstract_declarator
: pointer
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
gi_source_symbol_merge_type ($$, $1);
}
| direct_abstract_declarator
gi_source_symbol_merge_type ($$, $1);
}
| direct_abstract_declarator
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
gi_source_symbol_merge_type ($$, gi_source_array_new (NULL));
}
| '[' assignment_expression ']'
{
gi_source_symbol_merge_type ($$, gi_source_array_new (NULL));
}
| '[' assignment_expression ']'
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
gi_source_symbol_merge_type ($$, gi_source_array_new ($2));
}
| direct_abstract_declarator '[' ']'
gi_source_symbol_merge_type ($$, gi_source_array_new ($2));
}
| direct_abstract_declarator '[' ']'
| '(' ')'
{
GISourceType *func = gi_source_function_new ();
| '(' ')'
{
GISourceType *func = gi_source_function_new ();
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
gi_source_symbol_merge_type ($$, func);
}
| '(' parameter_list ')'
gi_source_symbol_merge_type ($$, func);
}
| '(' parameter_list ')'
if ($2 != NULL && ($2->next != NULL || ((GISourceSymbol *) $2->data)->base_type->type != CTYPE_VOID)) {
func->child_list = $2;
}
if ($2 != NULL && ($2->next != NULL || ((GISourceSymbol *) $2->data)->base_type->type != CTYPE_VOID)) {
func->child_list = $2;
}
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
gi_source_symbol_merge_type ($$, func);
}
| direct_abstract_declarator '(' ')'
gi_source_symbol_merge_type ($$, func);
}
| direct_abstract_declarator '(' ')'
#include <string.h>
GISourceSymbol *
#include <string.h>
GISourceSymbol *
-gi_source_symbol_new (GISourceSymbolType type)
+gi_source_symbol_new (GISourceSymbolType type, int line)
{
GISourceSymbol *s = g_slice_new0 (GISourceSymbol);
s->ref_count = 1;
s->type = type;
{
GISourceSymbol *s = g_slice_new0 (GISourceSymbol);
s->ref_count = 1;
s->type = type;
gboolean const_double_set;
double const_double;
char *source_filename;
gboolean const_double_set;
double const_double;
char *source_filename;
GSList * gi_source_scanner_get_comments (GISourceScanner *scanner);
void gi_source_scanner_free (GISourceScanner *scanner);
GSList * gi_source_scanner_get_comments (GISourceScanner *scanner);
void gi_source_scanner_free (GISourceScanner *scanner);
-GISourceSymbol * gi_source_symbol_new (GISourceSymbolType type);
+GISourceSymbol * gi_source_symbol_new (GISourceSymbolType type, int line);
gboolean gi_source_symbol_get_const_boolean (GISourceSymbol *symbol);
GISourceSymbol * gi_source_symbol_ref (GISourceSymbol *symbol);
void gi_source_symbol_unref (GISourceSymbol *symbol);
gboolean gi_source_symbol_get_const_boolean (GISourceSymbol *symbol);
GISourceSymbol * gi_source_symbol_ref (GISourceSymbol *symbol);
void gi_source_symbol_unref (GISourceSymbol *symbol);