aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-10-10 23:41:40 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-10-10 23:41:40 +0300
commit27e0842899c6d2a674d95d888e10d0b036e27753 (patch)
tree6f9519b8b40747aca8c505b8a7af0c3fcae6a0f5 /src/main.c
parent250d9aab8f79ebd7a2f2535de9db60172df51598 (diff)
downloadcflow-27e0842899c6d2a674d95d888e10d0b036e27753.tar.gz
cflow-27e0842899c6d2a674d95d888e10d0b036e27753.tar.bz2
Improve parser. Allow users to declare aliases to other symbols.
The latter feature is useful for declaring reserved symbols such as __restrict or __inline, e.g. --symbol __restrict:=restrict instructs cflow to treat `__restrict' exactly as `restrict'. * src/Makefile.am: Minor fix in rule for flowgraph. * src/c.l (init_tokens): New function, separated from init_lex. Install qualifiers. * src/cflow.h (symbol_alias): New flag. (symbol)<alias>: New member. (INSTALL_DEFAULT,INSTALL_OVERWRITE) (INSTALL_CHECK_LOCAL,INSTALL_UNIT_LOCAL): New defines. * src/cflow.rc: Rewrite for use with --cpp='gcc -E' * src/main.c (symbol_override): Extend syntax to allow for defining aliases to other tokens (--symbol __inline:=inline). * src/parser.c (print_token): print qualifiers and ops. (file_error): Change signature. All uses changed. (save_token): Improve output spacing. (skip_balanced): Treat LBRACE0 and RBRACE0 as { and }. (is_function): allow for qualifiers and wrappers before defintion. (parse_function_declaration): Remove PARM_WRAPPER case: it is taken care of by the caller. (fake_struct): leave when '(' is encountered. (parse_variable_declaration): Allow for qualifiers before the identifier. (skip_struct): Use skip_balanced. (dcl): Handle wrappers. Leave if a semicolon is encountered. (dirdcl): Optimize handing of wrapper. (maybe_parm_list): Handle qualifiers. (declare): allow for wrappers. (declare_type): Pass INSTALL_UNIT_LOCAL as a flag to install. * src/symbol.c (lookup): Argument is const now. (install): Change semantics of the 2nd argument. (install_ident): Change the call to install accordingly. * tests/nfparg.at: Change spacing to reflect changes to save_token.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/main.c b/src/main.c
index dbb8453..de41689 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,3 +1,3 @@
/* This file is part of GNU cflow
- Copyright (C) 1997, 2005, 2007, 2009, 2010 Sergey Poznyakoff
+ Copyright (C) 1997, 2005, 2007, 2009, 2010, 2011 Sergey Poznyakoff
@@ -259,3 +259,2 @@ symbol_override(const char *str)
{
- int type;
const char *ptr;
@@ -269,15 +268,31 @@ symbol_override(const char *str)
} else {
- type = find_option_type(symbol_optype, ptr+1, 0);
- if (type == 0) {
- error(0, 0, _("unknown symbol type: %s"), ptr+1);
- return;
+ name = strndup(str, ptr - str);
+ if (ptr[1] == '=') {
+ Symbol *alias = lookup(ptr+2);
+ if (!alias) {
+ alias = install(ptr+2, INSTALL_OVERWRITE);
+ alias->type = SymToken;
+ alias->token_type = 0;
+ alias->source = NULL;
+ alias->def_line = -1;
+ alias->ref_line = NULL;
+ }
+ sp = install(name, INSTALL_OVERWRITE);
+ sp->type = SymToken;
+ sp->alias = alias;
+ sp->flag = symbol_alias;
+ } else {
+ int type = find_option_type(symbol_optype, ptr+1, 0);
+ if (type == 0) {
+ error(0, 0, _("unknown symbol type: %s"), ptr+1);
+ return;
+ }
+ sp = install(name, INSTALL_OVERWRITE);
+ sp->type = SymToken;
+ sp->token_type = type;
}
- }
- name = strndup(str, ptr - str);
- sp = install(name, 0);
- sp->type = SymToken;
- sp->token_type = type;
- sp->source = NULL;
- sp->def_line = -1;
- sp->ref_line = NULL;
+ sp->source = NULL;
+ sp->def_line = -1;
+ sp->ref_line = NULL;
+ }
}
@@ -738,3 +753,3 @@ const char version_etc_copyright[] =
year. */
- "Copyright %s 2005, 2006, %d Sergey Poznyakoff";
+ "Copyright %s 2005, 2006, 2009, 2010, 2011 %d Sergey Poznyakoff";

Return to:

Send suggestions and report system problems to the System administrator.