summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-10-10 20:41:40 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-10-10 20:41:40 (GMT)
commit27e0842899c6d2a674d95d888e10d0b036e27753 (patch) (side-by-side diff)
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') (more/less context) (ignore whitespace changes)
-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,5 +1,5 @@
/* 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
GNU cflow is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -257,7 +257,6 @@ static struct option_type symbol_optype[] = {
static void
symbol_override(const char *str)
{
- int type;
const char *ptr;
char *name;
Symbol *sp;
@@ -267,19 +266,35 @@ symbol_override(const char *str)
error(0, 0, _("%s: no symbol type supplied"), str);
return;
} 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;
+ }
}
/* Args for --print option */
@@ -736,7 +751,7 @@ const char version_etc_copyright[] =
/* Do *not* mark this string for translation. %s is a copyright
symbol suitable for this locale, and %d is the copyright
year. */
- "Copyright %s 2005, 2006, %d Sergey Poznyakoff";
+ "Copyright %s 2005, 2006, 2009, 2010, 2011 %d Sergey Poznyakoff";
int
main(int argc, char **argv)

Return to:

Send suggestions and report system problems to the System administrator.