Commit 4215c51c authored by Lev Walkin's avatar Lev Walkin

add hidden -debug-type-naming option

parent da672c41
......@@ -64,6 +64,8 @@ main(int ac, char **av) {
int warnings_as_errors = 0; /* Treat warnings as errors */
char *skeletons_dir = NULL; /* Directory with supplementary stuff */
char *destdir = NULL; /* Destination for generated files */
char **debug_type_names = 0; /* Debug stuff */
size_t debug_type_names_count = 0;
asn1p_t *asn = 0; /* An ASN.1 parsed tree */
int ret; /* Return value from misc functions */
int ch; /* Command line character */
......@@ -73,7 +75,34 @@ main(int ac, char **av) {
/*
* Process command-line options.
*/
while((ch = getopt(ac, av, "EFf:g:hn:LPp:RS:D:vW:X")) != -1) switch(ch) {
while((ch = getopt(ac, av, "D:d:EFf:g:hn:LPp:RS:vW:X")) != -1) switch(ch) {
case 'D':
if(optarg && *optarg) {
size_t optarg_len = strlen(optarg);
free(destdir);
destdir = calloc(1, optarg_len + 2); /* + "/\0" */
assert(destdir);
strcpy(destdir, optarg);
if(destdir[optarg_len - 1] != '/') {
destdir[optarg_len] = '/';
}
} else {
free(destdir);
destdir = NULL;
}
break;
case 'd':
if(strncmp(optarg, "ebug-type-naming=", 17) == 0) {
char **p = realloc(debug_type_names,
(debug_type_names_count + 2) * sizeof(*p));
assert(p);
debug_type_names = p;
debug_type_names[debug_type_names_count++] =
strdup(optarg + 17);
debug_type_names[debug_type_names_count] = NULL;
break;
}
usage(av[0]);
case 'E':
print_arg__print_out = 1;
break;
......@@ -184,21 +213,6 @@ main(int ac, char **av) {
case 'S':
skeletons_dir = optarg;
break;
case 'D':
if(optarg && *optarg) {
size_t optarg_len = strlen(optarg);
free(destdir);
destdir = calloc(1, optarg_len + 2); /* + "/\0" */
assert(destdir);
strcpy(destdir, optarg);
if(destdir[optarg_len - 1] != '/') {
destdir[optarg_len] = '/';
}
} else {
free(destdir);
destdir = NULL;
}
break;
case 'v':
fprintf(stderr, "ASN.1 Compiler, v" VERSION "\n" COPYRIGHT);
exit(0);
......@@ -386,6 +400,14 @@ main(int ac, char **av) {
return 0;
}
/*
* -debug-type-naming=Type
*/
if(debug_type_names) {
asn1c_debug_type_naming(asn, asn1_compiler_flags, debug_type_names);
return 0;
}
/*
* Compile the ASN.1 tree into a set of source files
* of another language.
......
......@@ -232,3 +232,55 @@ default_logger_cb(int _severity, const char *fmt, ...) {
fprintf(stderr, "\n");
}
static void
asn1c_debug_expr_naming(arg_t *arg) {
asn1p_expr_t *expr = arg->expr;
printf("%s: ", expr->Identifier);
printf("%s\n", c_names_format(c_name(arg)));
printf("\n");
}
void
asn1c_debug_type_naming(asn1p_t *asn, enum asn1c_flags flags,
char **asn_type_names) {
arg_t arg_s;
arg_t *arg = &arg_s;
asn1p_module_t *mod;
memset(arg, 0, sizeof(*arg));
arg->logger_cb = default_logger_cb;
arg->flags = flags;
arg->asn = asn;
c_name_clash_finder_init();
/*
* Compile each individual top level structure.
*/
TQ_FOR(mod, &(asn->modules), mod_next) {
int namespace_shown = 0;
TQ_FOR(arg->expr, &(mod->members), next) {
arg->ns = asn1_namespace_new_from_module(mod, 0);
for(char **t = asn_type_names; *t; t++) {
if(strcmp(*t, arg->expr->Identifier) == 0) {
if(!namespace_shown) {
namespace_shown = 1;
printf("Namespace %s\n",
asn1_namespace_string(arg->ns));
}
asn1c_debug_expr_naming(arg);
}
}
asn1_namespace_free(arg->ns);
arg->ns = 0;
}
}
c_name_clash_finder_destroy();
}
......@@ -100,6 +100,9 @@ enum asn1c_flags {
int asn1_compile(asn1p_t *asn, const char *datadir, const char *destdir, enum asn1c_flags,
int argc, int optc, char **argv);
void asn1c_debug_type_naming(asn1p_t *asn, enum asn1c_flags,
char **asn_type_names);
void asn1c__add_pdu_type(const char *typename);
#endif /* ASN1_COMPILER_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment