Commit 781af821 authored by Denis Filatov's avatar Denis Filatov Committed by v0-e

WITH SUCCESSORS support

parent 84d3a59c
...@@ -42,7 +42,7 @@ asn1f_lookup_module_ex(asn1p_t *asn, const char *module_name, ...@@ -42,7 +42,7 @@ asn1f_lookup_module_ex(asn1p_t *asn, const char *module_name,
arg.asn = asn; arg.asn = asn;
arg.eh = a1f_replace_me_with_proper_interface_arg.eh; arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug; arg.debug = a1f_replace_me_with_proper_interface_arg.debug;
return asn1f_lookup_module(&arg, module_name, oid); return asn1f_lookup_module(&arg, module_name, oid, 0);
} }
asn1p_expr_t * asn1p_expr_t *
......
...@@ -53,7 +53,7 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) { ...@@ -53,7 +53,7 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) {
*/ */
TQ_FOR(xp, &(mod->imports), xp_next) { TQ_FOR(xp, &(mod->imports), xp_next) {
asn1p_module_t *fromModule = asn1p_module_t *fromModule =
asn1f_lookup_module(arg, xp->fromModuleName, NULL); asn1f_lookup_module(arg, xp->fromModuleName, NULL, 0);
asn1p_expr_t *tc = (asn1p_expr_t *)0; asn1p_expr_t *tc = (asn1p_expr_t *)0;
TQ_FOR(tc, &(xp->xp_members), next) { TQ_FOR(tc, &(xp->xp_members), next) {
...@@ -78,7 +78,7 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) { ...@@ -78,7 +78,7 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) {
* Okay, right now we have a module name and, hopefully, an OID. * Okay, right now we have a module name and, hopefully, an OID.
* Search the arg->asn for the specified module. * Search the arg->asn for the specified module.
*/ */
mod = asn1f_lookup_module(arg, xp->fromModuleName, xp->identifier.oid); mod = asn1f_lookup_module(arg, xp->fromModuleName, xp->identifier.oid, xp->option);
if(mod == NULL) { if(mod == NULL) {
/* Conditional debug */ /* Conditional debug */
if(!(arg->expr->_mark & TM_BROKEN)) { if(!(arg->expr->_mark & TM_BROKEN)) {
...@@ -106,8 +106,8 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) { ...@@ -106,8 +106,8 @@ asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const char *name) {
} }
asn1p_module_t * asn1p_module_t *
asn1f_lookup_module(arg_t *arg, const char *module_name, const asn1p_oid_t *oid) { asn1f_lookup_module(arg_t *arg, const char *module_name, const asn1p_oid_t *oid, int oid_option) {
asn1p_module_t *mod; asn1p_module_t *mod, *ret = NULL;
assert(module_name); assert(module_name);
...@@ -149,27 +149,25 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, const asn1p_oid_t *oid) ...@@ -149,27 +149,25 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, const asn1p_oid_t *oid)
TQ_FOR(mod, &(arg->asn->modules), mod_next) { TQ_FOR(mod, &(arg->asn->modules), mod_next) {
if(oid) { if(oid) {
if(mod->module_oid) { if(mod->module_oid) {
if(asn1p_oid_compare(oid, if(0 == asn1p_oid_compare_opt(oid,
mod->module_oid)) { mod->module_oid, oid_option)) {
continue;
} else {
/* Match! Even if name doesn't. */ /* Match! Even if name doesn't. */
return mod; oid = mod->module_oid;
ret = mod;
} }
} else {
/* Not match, even if name is the same. */
continue;
} }
/* Not match, even if name is the same. */
continue;
} }
if(strcmp(module_name, mod->ModuleName) == 0) if(strcmp(module_name, mod->ModuleName) == 0)
return mod; return mod;
} }
if(ret == NULL) {
DEBUG("\tModule \"%s\" not found", module_name); DEBUG("\tModule \"%s\" not found", module_name);
errno = ENOENT;
errno = ENOENT; }
return NULL; return ret;
} }
static asn1p_expr_t * static asn1p_expr_t *
...@@ -268,7 +266,7 @@ asn1f_lookup_symbol_impl(arg_t *arg, asn1p_expr_t *rhs_pspecs, const asn1p_ref_t ...@@ -268,7 +266,7 @@ asn1f_lookup_symbol_impl(arg_t *arg, asn1p_expr_t *rhs_pspecs, const asn1p_ref_t
* switch namespace to that module. * switch namespace to that module.
*/ */
if(modulename) { if(modulename) {
imports_from = asn1f_lookup_module(arg, modulename, 0); imports_from = asn1f_lookup_module(arg, modulename, 0, 0);
if(imports_from == NULL) { if(imports_from == NULL) {
FATAL( FATAL(
"Module \"%s\" " "Module \"%s\" "
......
...@@ -31,7 +31,7 @@ asn1p_module_t *asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const c ...@@ -31,7 +31,7 @@ asn1p_module_t *asn1f_lookup_in_imports(arg_t *arg, asn1p_module_t *mod, const c
*/ */
asn1p_module_t *asn1f_lookup_module(arg_t *arg, asn1p_module_t *asn1f_lookup_module(arg_t *arg,
const char *module_name, const char *module_name,
const asn1p_oid_t *module_oid); const asn1p_oid_t *module_oid, int oid_option);
/* /*
* Return the reference to a destination of the given reference, * Return the reference to a destination of the given reference,
......
...@@ -381,7 +381,8 @@ UTF8String { ...@@ -381,7 +381,8 @@ UTF8String {
VideotexString return TOK_VideotexString; VideotexString return TOK_VideotexString;
VisibleString return TOK_VisibleString; VisibleString return TOK_VisibleString;
WITH return TOK_WITH; WITH return TOK_WITH;
SUCCESSORS return TOK_SUCCESSORS;
DESCENDANTS return TOK_DESCENDANTS;
<INITIAL,with_syntax>&[A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* { <INITIAL,with_syntax>&[A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)* {
asn1p_lval.tv_str = strdup(yytext); asn1p_lval.tv_str = strdup(yytext);
......
...@@ -89,26 +89,37 @@ asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b) { ...@@ -89,26 +89,37 @@ asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b) {
if(b->arcs_count > i) { if(b->arcs_count > i) {
if(a->arcs_count <= i) if(a->arcs_count <= i)
return -1; return -1-i;
} else if(a->arcs_count > i) { } else if(a->arcs_count > i) {
if(b->arcs_count <= i) if(b->arcs_count <= i)
return 1; return 1+i;
} else if(b->arcs_count <= i && a->arcs_count <= i) { } else if(b->arcs_count <= i && a->arcs_count <= i) {
cmp = b->arcs_count - a->arcs_count; cmp = b->arcs_count - a->arcs_count;
if(cmp < 0) if(cmp < 0)
return -1; return -1-i;
else if(cmp > 0) else if(cmp > 0)
return 1; return 1+i;
return 0; return 0;
} }
cmp = b->arcs[i].number - a->arcs[i].number; cmp = b->arcs[i].number - a->arcs[i].number;
if(cmp < 0) if(cmp < 0)
return -1; return -1-i;
else if(cmp > 0) else if(cmp > 0)
return 1; return 1+i;
} }
}
int
asn1p_oid_compare_opt(const asn1p_oid_t *a, const asn1p_oid_t *b, int oid_options) {
int r = asn1p_oid_compare(a, b);
if(oid_options == OID_WITH_SUCCESSORS) {
if(r == b->arcs_count) /* positive and last arc */
r = 0;
} else if(oid_options == OID_WITH_DESCENDANTS) {
/* not supported yet */
}
return r;
} }
...@@ -63,5 +63,9 @@ void asn1p_oid_free(asn1p_oid_t *); ...@@ -63,5 +63,9 @@ void asn1p_oid_free(asn1p_oid_t *);
*/ */
int asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b); int asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b);
#define OID_WITH_SUCCESSORS 1
#define OID_WITH_DESCENDANTS 2
int asn1p_oid_compare_opt(const asn1p_oid_t *a, const asn1p_oid_t *b, int oid_option);
#endif /* ASN1_PARSER_OID_H */ #endif /* ASN1_PARSER_OID_H */
...@@ -23,6 +23,8 @@ typedef struct asn1p_xports_s { ...@@ -23,6 +23,8 @@ typedef struct asn1p_xports_s {
asn1p_value_t *value; /* DefinedValue */ asn1p_value_t *value; /* DefinedValue */
} identifier; } identifier;
int option; /* (0) | WITH SUCCESSORS (1) | WITH DESCENDANTS (2) */
/* /*
* Number of entities to import. * Number of entities to import.
*/ */
......
...@@ -267,6 +267,8 @@ static asn1p_module_t *currentModule; ...@@ -267,6 +267,8 @@ static asn1p_module_t *currentModule;
%token TOK_TwoDots ".." %token TOK_TwoDots ".."
%token TOK_ThreeDots "..." %token TOK_ThreeDots "..."
%token TOK_SUCCESSORS
%token TOK_DESCENDANTS
/* /*
* Types defined herein. * Types defined herein.
...@@ -286,6 +288,8 @@ static asn1p_module_t *currentModule; ...@@ -286,6 +288,8 @@ static asn1p_module_t *currentModule;
%type <a_module> optImportsBundleSet %type <a_module> optImportsBundleSet
%type <a_module> ImportsBundleSet %type <a_module> ImportsBundleSet
%type <a_xports> ImportsBundle %type <a_xports> ImportsBundle
%type <a_xports> ImportsBundleInt
%type <a_int> ImportSelectionOption
%type <a_xports> ImportsList %type <a_xports> ImportsList
%type <a_xports> ExportsDefinition %type <a_xports> ExportsDefinition
%type <a_xports> ExportsBody %type <a_xports> ExportsBody
...@@ -711,11 +715,19 @@ AssignedIdentifier: ...@@ -711,11 +715,19 @@ AssignedIdentifier:
| ObjectIdentifier { $$.oid = $1; }; | ObjectIdentifier { $$.oid = $1; };
/* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */ /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
ImportsBundle: ImportsBundle:
ImportsBundleInt ImportSelectionOption {
$$ = $1;
$$->option = $2;
}
| ImportsBundleInt ;
ImportsBundleInt:
ImportsList TOK_FROM TypeRefName AssignedIdentifier { ImportsList TOK_FROM TypeRefName AssignedIdentifier {
$$ = $1; $$ = $1;
$$->fromModuleName = $3; $$->fromModuleName = $3;
$$->identifier = $4; $$->identifier = $4;
$$->option = 0;
/* This stupid thing is used for look-back hack. */ /* This stupid thing is used for look-back hack. */
saved_aid = $$->identifier.oid ? 0 : &($$->identifier); saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
checkmem($$); checkmem($$);
...@@ -755,6 +767,14 @@ ImportsElement: ...@@ -755,6 +767,14 @@ ImportsElement:
} }
; ;
ImportSelectionOption:
TOK_WITH TOK_SUCCESSORS {
$$ = OID_WITH_SUCCESSORS;
}
| TOK_WITH TOK_DESCENDANTS {
$$ = OID_WITH_DESCENDANTS;
}
;
optExports: optExports:
{ $$ = 0; } { $$ = 0; }
......
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