maintaining parent expression

This commit is contained in:
Lev Walkin 2004-09-08 00:28:11 +00:00
parent 699ed4bf79
commit 1004aa9462
8 changed files with 2315 additions and 3081 deletions

View File

@ -68,8 +68,10 @@ asn1f_pull_components_of(arg_t *arg) {
* Move all components of the cloned structure
* into the current one.
*/
while((memb = TQ_REMOVE(&(coft->members), next)))
while((memb = TQ_REMOVE(&(coft->members), next))) {
TQ_ADD(&list, memb, next);
memb->parent_expr = expr;
}
asn1p_expr_free(coft); /* Remove wrapper */
}
@ -159,7 +161,7 @@ asn1f_fix_constr_ext(arg_t *arg) {
asn1p_expr_free(v);
r_value = -1;
} else {
TQ_ADD(&(expr->members), v, next);
asn1p_expr_add(expr, v);
}
} else {
r_value = -1;

View File

@ -171,6 +171,7 @@ asn1f_recurse_expr(arg_t *arg, int (*callback)(arg_t *arg)) {
*/
TQ_FOR(arg->expr, &(expr->members), next) {
assert(arg->expr->expr_type != A1TC_INVALID);
assert(arg->expr->parent_expr == expr);
ret = asn1f_recurse_expr(arg, callback);
RET2RVAL(ret, rvalue);
}

View File

@ -58,15 +58,23 @@ asn1f_fix_parametrized_assignment(arg_t *arg) {
return asn1f_parametrize(arg, expr, ptype);
}
#define SUBSTITUTE(to, from) do { \
asn1p_expr_t tmp; \
tmp = *(to); \
*(to) = *(from); \
*(from) = tmp; \
(to)->next = tmp.next; \
memset(&((from)->next), 0, \
sizeof((from)->next)); \
asn1p_expr_free(from); \
#define SUBSTITUTE(to, from) do { \
asn1p_expr_t tmp, *__v; \
tmp = *(to); \
*(to) = *(from); \
TQ_MOVE(&(to)->members, &(from)->members); \
*(from) = tmp; \
(to)->next = tmp.next; \
(to)->parent_expr = tmp.parent_expr; \
memset(&((from)->next), 0, \
sizeof((from)->next)); \
memset(&((from)->members), 0, \
sizeof((from)->members)); \
asn1p_expr_free(from); \
TQ_FOR(__v, &((to)->members), next) { \
assert(__v->parent_expr == (from)); \
__v->parent_expr = (to); \
} \
} while(0)
static int

View File

@ -82,12 +82,22 @@ asn1p_expr_clone(asn1p_expr_t *expr, int skip_extensions) {
asn1p_expr_free(clone);
return NULL;
}
TQ_ADD(&(clone->members), cmemb, next);
asn1p_expr_add(clone, cmemb);
}
return clone;
}
/*
* Add expression as a member of another.
*/
void
asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what) {
TQ_ADD(&(to->members), what, next);
what->parent_expr = to;
}
/*
* Destruct the types collection structure.
*/
@ -96,6 +106,16 @@ asn1p_expr_free(asn1p_expr_t *expr) {
if(expr) {
asn1p_expr_t *tm;
/* Remove all children */
while((tm = TQ_REMOVE(&(expr->members), next))) {
if(tm->parent_expr != expr)
printf("<%s:%p !-> %s:%p>\n",
tm->Identifier, tm->parent_expr,
expr->Identifier, expr);
assert(tm->parent_expr == expr);
asn1p_expr_free(tm);
}
if(expr->Identifier)
free(expr->Identifier);
if(expr->reference)
@ -111,11 +131,6 @@ asn1p_expr_free(asn1p_expr_t *expr) {
if(expr->with_syntax)
asn1p_wsyntx_free(expr->with_syntax);
/* Remove all children */
while((tm = TQ_REMOVE(&(expr->members), next))) {
asn1p_expr_free(tm);
}
if(expr->data && expr->data_free)
expr->data_free(expr->data);

View File

@ -195,14 +195,16 @@ typedef struct asn1p_expr_s {
*/
TQ_ENTRY(struct asn1p_expr_s) next;
struct asn1p_expr_s *parent_expr; /* optional */
struct asn1p_module_s *module; /* Defined in module */
/*
* Line number where this structure is defined in the original
* grammar source.
*/
int _lineno;
struct asn1p_module_s *module; /* Defined in module */
/*
* Marks are used for various purposes.
* Here are some predefined ones.
@ -228,6 +230,7 @@ typedef struct asn1p_expr_s {
*/
asn1p_expr_t *asn1p_expr_new(int _lineno);
asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
void asn1p_expr_free(asn1p_expr_t *expr);
#endif /* ASN1_PARSER_EXPR_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,243 +1,3 @@
/* A Bison parser, made from asn1p_y.y, by GNU bison 1.75. */
/* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, when this file is copied by Bison into a
Bison output file, you may use that output file without restriction.
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
#ifndef BISON_ASN_P_Y_H
# define BISON_ASN_P_Y_H
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
TOK_PPEQ = 258,
TOK_opaque = 259,
TOK_bstring = 260,
TOK_cstring = 261,
TOK_hstring = 262,
TOK_identifier = 263,
TOK_number = 264,
TOK_number_negative = 265,
TOK_typereference = 266,
TOK_capitalreference = 267,
TOK_typefieldreference = 268,
TOK_valuefieldreference = 269,
TOK_ABSENT = 270,
TOK_ABSTRACT_SYNTAX = 271,
TOK_ALL = 272,
TOK_ANY = 273,
TOK_APPLICATION = 274,
TOK_AUTOMATIC = 275,
TOK_BEGIN = 276,
TOK_BIT = 277,
TOK_BMPString = 278,
TOK_BOOLEAN = 279,
TOK_BY = 280,
TOK_CHARACTER = 281,
TOK_CHOICE = 282,
TOK_CLASS = 283,
TOK_COMPONENT = 284,
TOK_COMPONENTS = 285,
TOK_CONSTRAINED = 286,
TOK_CONTAINING = 287,
TOK_DEFAULT = 288,
TOK_DEFINITIONS = 289,
TOK_DEFINED = 290,
TOK_EMBEDDED = 291,
TOK_ENCODED = 292,
TOK_ENCODING_CONTROL = 293,
TOK_END = 294,
TOK_ENUMERATED = 295,
TOK_EXPLICIT = 296,
TOK_EXPORTS = 297,
TOK_EXTENSIBILITY = 298,
TOK_EXTERNAL = 299,
TOK_FALSE = 300,
TOK_FROM = 301,
TOK_GeneralizedTime = 302,
TOK_GeneralString = 303,
TOK_GraphicString = 304,
TOK_IA5String = 305,
TOK_IDENTIFIER = 306,
TOK_IMPLICIT = 307,
TOK_IMPLIED = 308,
TOK_IMPORTS = 309,
TOK_INCLUDES = 310,
TOK_INSTANCE = 311,
TOK_INSTRUCTIONS = 312,
TOK_INTEGER = 313,
TOK_ISO646String = 314,
TOK_MAX = 315,
TOK_MIN = 316,
TOK_MINUS_INFINITY = 317,
TOK_NULL = 318,
TOK_NumericString = 319,
TOK_OBJECT = 320,
TOK_ObjectDescriptor = 321,
TOK_OCTET = 322,
TOK_OF = 323,
TOK_OPTIONAL = 324,
TOK_PATTERN = 325,
TOK_PDV = 326,
TOK_PLUS_INFINITY = 327,
TOK_PRESENT = 328,
TOK_PrintableString = 329,
TOK_PRIVATE = 330,
TOK_REAL = 331,
TOK_RELATIVE_OID = 332,
TOK_SEQUENCE = 333,
TOK_SET = 334,
TOK_SIZE = 335,
TOK_STRING = 336,
TOK_SYNTAX = 337,
TOK_T61String = 338,
TOK_TAGS = 339,
TOK_TeletexString = 340,
TOK_TRUE = 341,
TOK_TYPE_IDENTIFIER = 342,
TOK_UNIQUE = 343,
TOK_UNIVERSAL = 344,
TOK_UniversalString = 345,
TOK_UTCTime = 346,
TOK_UTF8String = 347,
TOK_VideotexString = 348,
TOK_VisibleString = 349,
TOK_WITH = 350,
TOK_EXCEPT = 351,
TOK_INTERSECTION = 352,
TOK_UNION = 353,
TOK_TwoDots = 354,
TOK_ThreeDots = 355,
TOK_tag = 356
};
#endif
#define TOK_PPEQ 258
#define TOK_opaque 259
#define TOK_bstring 260
#define TOK_cstring 261
#define TOK_hstring 262
#define TOK_identifier 263
#define TOK_number 264
#define TOK_number_negative 265
#define TOK_typereference 266
#define TOK_capitalreference 267
#define TOK_typefieldreference 268
#define TOK_valuefieldreference 269
#define TOK_ABSENT 270
#define TOK_ABSTRACT_SYNTAX 271
#define TOK_ALL 272
#define TOK_ANY 273
#define TOK_APPLICATION 274
#define TOK_AUTOMATIC 275
#define TOK_BEGIN 276
#define TOK_BIT 277
#define TOK_BMPString 278
#define TOK_BOOLEAN 279
#define TOK_BY 280
#define TOK_CHARACTER 281
#define TOK_CHOICE 282
#define TOK_CLASS 283
#define TOK_COMPONENT 284
#define TOK_COMPONENTS 285
#define TOK_CONSTRAINED 286
#define TOK_CONTAINING 287
#define TOK_DEFAULT 288
#define TOK_DEFINITIONS 289
#define TOK_DEFINED 290
#define TOK_EMBEDDED 291
#define TOK_ENCODED 292
#define TOK_ENCODING_CONTROL 293
#define TOK_END 294
#define TOK_ENUMERATED 295
#define TOK_EXPLICIT 296
#define TOK_EXPORTS 297
#define TOK_EXTENSIBILITY 298
#define TOK_EXTERNAL 299
#define TOK_FALSE 300
#define TOK_FROM 301
#define TOK_GeneralizedTime 302
#define TOK_GeneralString 303
#define TOK_GraphicString 304
#define TOK_IA5String 305
#define TOK_IDENTIFIER 306
#define TOK_IMPLICIT 307
#define TOK_IMPLIED 308
#define TOK_IMPORTS 309
#define TOK_INCLUDES 310
#define TOK_INSTANCE 311
#define TOK_INSTRUCTIONS 312
#define TOK_INTEGER 313
#define TOK_ISO646String 314
#define TOK_MAX 315
#define TOK_MIN 316
#define TOK_MINUS_INFINITY 317
#define TOK_NULL 318
#define TOK_NumericString 319
#define TOK_OBJECT 320
#define TOK_ObjectDescriptor 321
#define TOK_OCTET 322
#define TOK_OF 323
#define TOK_OPTIONAL 324
#define TOK_PATTERN 325
#define TOK_PDV 326
#define TOK_PLUS_INFINITY 327
#define TOK_PRESENT 328
#define TOK_PrintableString 329
#define TOK_PRIVATE 330
#define TOK_REAL 331
#define TOK_RELATIVE_OID 332
#define TOK_SEQUENCE 333
#define TOK_SET 334
#define TOK_SIZE 335
#define TOK_STRING 336
#define TOK_SYNTAX 337
#define TOK_T61String 338
#define TOK_TAGS 339
#define TOK_TeletexString 340
#define TOK_TRUE 341
#define TOK_TYPE_IDENTIFIER 342
#define TOK_UNIQUE 343
#define TOK_UNIVERSAL 344
#define TOK_UniversalString 345
#define TOK_UTCTime 346
#define TOK_UTF8String 347
#define TOK_VideotexString 348
#define TOK_VisibleString 349
#define TOK_WITH 350
#define TOK_EXCEPT 351
#define TOK_INTERSECTION 352
#define TOK_UNION 353
#define TOK_TwoDots 354
#define TOK_ThreeDots 355
#define TOK_tag 356
#ifndef YYSTYPE
#line 58 "asn1p_y.y"
typedef union {
asn1p_t *a_grammar;
asn1p_module_flags_e a_module_flags;
@ -269,14 +29,106 @@ typedef union {
char *name;
struct asn1p_type_tag_s tag;
} tv_nametag;
} yystype;
/* Line 1281 of /usr/local/share/bison/yacc.c. */
#line 275 "y.tab.h"
# define YYSTYPE yystype
#endif
} YYSTYPE;
#define TOK_PPEQ 257
#define TOK_opaque 258
#define TOK_bstring 259
#define TOK_cstring 260
#define TOK_hstring 261
#define TOK_identifier 262
#define TOK_number 263
#define TOK_number_negative 264
#define TOK_typereference 265
#define TOK_capitalreference 266
#define TOK_typefieldreference 267
#define TOK_valuefieldreference 268
#define TOK_ABSENT 269
#define TOK_ABSTRACT_SYNTAX 270
#define TOK_ALL 271
#define TOK_ANY 272
#define TOK_APPLICATION 273
#define TOK_AUTOMATIC 274
#define TOK_BEGIN 275
#define TOK_BIT 276
#define TOK_BMPString 277
#define TOK_BOOLEAN 278
#define TOK_BY 279
#define TOK_CHARACTER 280
#define TOK_CHOICE 281
#define TOK_CLASS 282
#define TOK_COMPONENT 283
#define TOK_COMPONENTS 284
#define TOK_CONSTRAINED 285
#define TOK_CONTAINING 286
#define TOK_DEFAULT 287
#define TOK_DEFINITIONS 288
#define TOK_DEFINED 289
#define TOK_EMBEDDED 290
#define TOK_ENCODED 291
#define TOK_ENCODING_CONTROL 292
#define TOK_END 293
#define TOK_ENUMERATED 294
#define TOK_EXPLICIT 295
#define TOK_EXPORTS 296
#define TOK_EXTENSIBILITY 297
#define TOK_EXTERNAL 298
#define TOK_FALSE 299
#define TOK_FROM 300
#define TOK_GeneralizedTime 301
#define TOK_GeneralString 302
#define TOK_GraphicString 303
#define TOK_IA5String 304
#define TOK_IDENTIFIER 305
#define TOK_IMPLICIT 306
#define TOK_IMPLIED 307
#define TOK_IMPORTS 308
#define TOK_INCLUDES 309
#define TOK_INSTANCE 310
#define TOK_INSTRUCTIONS 311
#define TOK_INTEGER 312
#define TOK_ISO646String 313
#define TOK_MAX 314
#define TOK_MIN 315
#define TOK_MINUS_INFINITY 316
#define TOK_NULL 317
#define TOK_NumericString 318
#define TOK_OBJECT 319
#define TOK_ObjectDescriptor 320
#define TOK_OCTET 321
#define TOK_OF 322
#define TOK_OPTIONAL 323
#define TOK_PATTERN 324
#define TOK_PDV 325
#define TOK_PLUS_INFINITY 326
#define TOK_PRESENT 327
#define TOK_PrintableString 328
#define TOK_PRIVATE 329
#define TOK_REAL 330
#define TOK_RELATIVE_OID 331
#define TOK_SEQUENCE 332
#define TOK_SET 333
#define TOK_SIZE 334
#define TOK_STRING 335
#define TOK_SYNTAX 336
#define TOK_T61String 337
#define TOK_TAGS 338
#define TOK_TeletexString 339
#define TOK_TRUE 340
#define TOK_TYPE_IDENTIFIER 341
#define TOK_UNIQUE 342
#define TOK_UNIVERSAL 343
#define TOK_UniversalString 344
#define TOK_UTCTime 345
#define TOK_UTF8String 346
#define TOK_VideotexString 347
#define TOK_VisibleString 348
#define TOK_WITH 349
#define TOK_EXCEPT 350
#define TOK_INTERSECTION 351
#define TOK_UNION 352
#define TOK_TwoDots 353
#define TOK_ThreeDots 354
#define TOK_tag 355
extern YYSTYPE asn1p_lval;
#endif /* not BISON_ASN_P_Y_H */

View File

@ -23,9 +23,9 @@ extern int asn1p_lineno;
static asn1p_value_t *
_convert_bitstring2binary(char *str, int base);
#define checkmem(ptr) do { \
if(!(ptr)) \
return yyerror("Memory failure"); \
#define checkmem(ptr) do { \
if(!(ptr)) \
return yyerror("Memory failure"); \
} while(0)
#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
@ -818,11 +818,11 @@ ActualParameterList:
ActualParameter {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
TQ_ADD(&($$->members), $1, next);
asn1p_expr_add($$, $1);
}
| ActualParameterList ',' ActualParameter {
$$ = $1;
TQ_ADD(&($$->members), $3, next);
asn1p_expr_add($$, $3);
}
;
@ -846,11 +846,11 @@ ComponentTypeLists:
ComponentType {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
TQ_ADD(&($$->members), $1, next);
asn1p_expr_add($$, $1);
}
| ComponentTypeLists ',' ComponentType {
$$ = $1;
TQ_ADD(&($$->members), $3, next);
asn1p_expr_add($$, $3);
}
;
@ -867,7 +867,7 @@ ComponentType:
checkmem($$);
$$->meta_type = $3->meta_type;
$$->expr_type = A1TC_COMPONENTS_OF;
TQ_ADD(&($$->members), $3, next);
asn1p_expr_add($$, $3);
}
| ExtensionAndException {
$$ = $1;
@ -878,11 +878,11 @@ AlternativeTypeLists:
AlternativeType {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
TQ_ADD(&($$->members), $1, next);
asn1p_expr_add($$, $1);
}
| AlternativeTypeLists ',' AlternativeType {
$$ = $1;
TQ_ADD(&($$->members), $3, next);
asn1p_expr_add($$, $3);
}
;
@ -919,11 +919,11 @@ ClassFieldList:
checkmem($$);
$$->expr_type = A1TC_CLASSDEF;
$$->meta_type = AMT_OBJECT;
TQ_ADD(&($$->members), $1, next);
asn1p_expr_add($$, $1);
}
| ClassFieldList ',' ClassField {
$$ = $1;
TQ_ADD(&($$->members), $3, next);
asn1p_expr_add($$, $3);
}
;
@ -1085,7 +1085,7 @@ TypeDeclaration:
$$->constraints = $2;
$$->expr_type = ASN_CONSTR_SEQUENCE_OF;
$$->meta_type = AMT_TYPE;
TQ_ADD(&($$->members), $4, next);
asn1p_expr_add($$, $4);
}
| TOK_SET optConstraints TOK_OF TypeDeclaration {
$$ = asn1p_expr_new(yylineno);
@ -1093,7 +1093,7 @@ TypeDeclaration:
$$->constraints = $2;
$$->expr_type = ASN_CONSTR_SET_OF;
$$->meta_type = AMT_TYPE;
TQ_ADD(&($$->members), $4, next);
asn1p_expr_add($$, $4);
}
| TOK_ANY {
$$ = asn1p_expr_new(yylineno);
@ -1808,11 +1808,11 @@ UniverationList:
UniverationElement {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
TQ_ADD(&($$->members), $1, next);
asn1p_expr_add($$, $1);
}
| UniverationList ',' UniverationElement {
$$ = $1;
TQ_ADD(&($$->members), $3, next);
asn1p_expr_add($$, $3);
}
;