Skip to content

Commit

Permalink
Support $expansion_path and $expansion_line
Browse files Browse the repository at this point in the history
  • Loading branch information
eunovm committed Aug 21, 2019
1 parent b1f2e45 commit 28cd3a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libcpp/include/ldv-aspect-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ typedef struct ldv_info_macro_internal
ldv_list_ptr macro_param_value;
const char *file_path;
unsigned int line;
const char *expansion_file_path;
unsigned int expansion_line;
} ldv_info_macro;
typedef ldv_info_macro *ldv_i_macro_ptr;

Expand Down
4 changes: 4 additions & 0 deletions libcpp/ldv-cpp-advice-weaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ ldv_cpp_evaluate_aspect_pattern (ldv_aspect_pattern_ptr pattern, const char **st
text = ldv_copy_str (ldv_i_match->i_macro->file_path);
else if (!strcmp (pattern->name, "line"))
number = ldv_i_match->i_macro->line;
else if (!strcmp (pattern->name, "expansion_path"))
text = ldv_copy_str (ldv_i_match->i_macro->expansion_file_path);
else if (!strcmp (pattern->name, "expansion_line"))
number = ldv_i_match->i_macro->expansion_line;
else
{
LDV_CPP_FATAL_ERROR ("aspect pattern \"%s\" wasn't weaved", pattern->name);
Expand Down
24 changes: 22 additions & 2 deletions libcpp/ldv-cpp-pointcut-matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ ldv_match_macro (cpp_reader *pfile, cpp_hashnode *node, const cpp_token ***arg_v
ldv_i_match_ptr match = NULL;
ldv_i_macro_ptr macro = NULL;
const line_map_ordinary *map = NULL;
const char *token_file_path = NULL;
unsigned int token_line;
int i, j;
const char *macro_param_name_original = NULL;
char *macro_param_name = NULL;
Expand Down Expand Up @@ -278,9 +280,27 @@ ldv_match_macro (cpp_reader *pfile, cpp_hashnode *node, const cpp_token ***arg_v
macro->macro_name = ldv_create_id ();
ldv_puts_id ((const char *) (NODE_NAME (node)), macro->macro_name);

/* Given token location corresponds to either define or expand location. */
map = LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table);
macro->file_path = ldv_get_realpath (LINEMAP_FILE (map));
macro->line = SOURCE_LINE(map, pfile->cur_token[-1].src_loc);
token_file_path = ldv_get_realpath (LINEMAP_FILE (map));
token_line = SOURCE_LINE(map, pfile->cur_token[-1].src_loc);
if (pp_kind == LDV_PP_DEFINE)
{
macro->file_path = token_file_path;
macro->line = token_line;
}
else
{
macro->expansion_file_path = token_file_path;
macro->expansion_line = token_line;

/* For macro expansions we need to store locations of macros themselves. */
rich_location richloc (pfile->line_table, node->value.macro->line);
expanded_location xloc = richloc.get_expanded_location(0);
macro->file_path = xloc.file;
macro->line = xloc.line;
}

macro->macro_param = NULL;

/* Remember macro parameters. */
Expand Down

0 comments on commit 28cd3a0

Please sign in to comment.