8 struct name
*name_init(struct node
*node
, int flags
)
10 char *name
= node
->data
;
11 struct name
*result
= xmalloc(sizeof(struct name
));
13 result
->flags
= flags
;
17 void name_free(struct name
*name
)
22 static int struct_node(struct node
*node
)
32 return struct_node(node
->parent
);
34 case AST_STRUCTDECLLIST
:
41 int node_isfield(struct node
*node
)
43 struct node
*cur
= node
->parent
;
46 if ((cur
->type
== AST_GETATTR
|| cur
->type
== AST_DEREF
)
47 && cur
->children
[1] == node
)
54 static int node_insidedecl(struct node
*node
)
63 return node
->type
!= AST_FUNCTION
;
70 static int node_isparamdecl(struct node
*node
)
72 struct node
*cur
= node
;
82 return node_insidedecl(cur
->parent
);
90 int guess_name_flags(struct node
*node
)
93 struct node
*parent
= node
->parent
;
95 if (parent
->type
== AST_ENUM
)
97 if (parent
->type
== AST_STRUCT
) {
98 enum nodetype type
= parent
->children
[0]->type
;
99 if (type
== AST_STRUCTKW
)
100 flags
|= NAME_STRUCT
;
104 if (parent
->type
== AST_LABELED
||
105 parent
->type
== AST_GOTO
)
108 if (node_isfield(node
))
110 if (node_isparamdecl(node
))
111 flags
|= NAME_PARAMDECL
;
115 int modifiers_match(struct name
*name
, int flags
)
117 return !((name
->flags
^ flags
) & NAME_MOD_MASK
);
120 static struct name
*name_at(struct project
*project
,
121 struct cfile
*cfile
, long offset
)
127 node
= node_find(cfile
->node
, offset
);
130 block
= block_find(cfile
->block
, offset
);
133 name
= block_lookup(block
, node
);
136 for (i
= 0; i
< project
->count
; i
++) {
137 struct cfile
*cfile
= project
->files
[i
];
138 name
= block_lookup(cfile
->block
, node
);
139 if (name
&& !(name
->flags
& NAME_STATIC
))
145 struct name
*name_find(struct project
*project
,
146 struct cfile
*cfile
, char *location
)
148 if (isdigit(location
[0]))
149 return name_at(project
, cfile
, atoi(location
));
150 return block_find_hier(cfile
->block
, location
);