From fc7933885d24e7ba07623495419f5bacc0a10d57 Mon Sep 17 00:00:00 2001 From: abv Date: Thu, 30 Apr 2020 21:29:57 +0300 Subject: [PATCH] Fix parser to avoid loosing fields after redefinition of inherited field (SELF\field = type;) --- src/ExpToCasExe/expparse.cxx | 2 +- src/ExpToCasExe/exptocas.l | 14 +-- src/ExpToCasExe/exptocas.y | 165 +++++++++++++++++------------------ 3 files changed, 90 insertions(+), 91 deletions(-) diff --git a/src/ExpToCasExe/expparse.cxx b/src/ExpToCasExe/expparse.cxx index 08ee5cc5e7..fb8af94d49 100644 --- a/src/ExpToCasExe/expparse.cxx +++ b/src/ExpToCasExe/expparse.cxx @@ -1274,7 +1274,7 @@ case 48: { yyval.flist = 0; /* redefinition of inherited field, just skip */ } break; case 49: # line 235 "Express.y" -{ yyval.flist = 0; } break; +{ yyval.flist = yypvt[-0].flist; /* ignore redefinition of inherited field, take trailing list */ } break; case 50: # line 237 "Express.y" { yyval.flist = NULL; /* empty list of fields */ } break; diff --git a/src/ExpToCasExe/exptocas.l b/src/ExpToCasExe/exptocas.l index 1c3ee41b98..00bcc4e50d 100644 --- a/src/ExpToCasExe/exptocas.l +++ b/src/ExpToCasExe/exptocas.l @@ -39,13 +39,13 @@ Also, error processing and current line number tracking functions are defined #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include "expparse.h" /* define tokens */ diff --git a/src/ExpToCasExe/exptocas.y b/src/ExpToCasExe/exptocas.y index d50b61ec5c..a342009234 100644 --- a/src/ExpToCasExe/exptocas.y +++ b/src/ExpToCasExe/exptocas.y @@ -33,34 +33,33 @@ complex time or redefinition of inherited field are ignored. \*****************************************************************************/ -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /************************************************/ /* ERROR MESSAGE FUNCTION */ @@ -78,21 +77,21 @@ int yyerror ( char *s ) /************************************************/ /* FUNCTIONS FOR CREATING SCHEMA REPRESENTATION */ -static ExpToCas_Schema *mkschema ( char *name, ExpToCas_HSequenceOfItem *ilist ); -static ExpToCas_HSequenceOfItem *mkilist ( ExpToCas_Item *item, ExpToCas_HSequenceOfItem *seq ); -static ExpToCas_Item *mkenum ( char *name, TColStd_HSequenceOfHAsciiString *tlist ); -static ExpToCas_Item *mkselect ( char *name, TColStd_HSequenceOfHAsciiString *tlist ); -static ExpToCas_Item *mkalias ( char *name, ExpToCas_Type *type ); -static ExpToCas_Item *mkentity ( char *name, TColStd_HSequenceOfHAsciiString *inherit, - ExpToCas_HSequenceOfField *field, int isabstract ); -static ExpToCas_Reference *mkrefs ( char *name, TColStd_HSequenceOfHAsciiString *items); +static Express_Schema *mkschema ( char *name, Express_HSequenceOfItem *ilist ); +static Express_HSequenceOfItem *mkilist ( Express_Item *item, Express_HSequenceOfItem *seq ); +static Express_Item *mkenum ( char *name, TColStd_HSequenceOfHAsciiString *tlist ); +static Express_Item *mkselect ( char *name, TColStd_HSequenceOfHAsciiString *tlist ); +static Express_Item *mkalias ( char *name, Express_Type *type ); +static Express_Item *mkentity ( char *name, TColStd_HSequenceOfHAsciiString *inherit, + Express_HSequenceOfField *field, int isabstract ); +static Express_Reference *mkrefs ( char *name, TColStd_HSequenceOfHAsciiString *items); static TColStd_HSequenceOfHAsciiString *mktlist ( char *name, TColStd_HSequenceOfHAsciiString *tlist ); static TColStd_HSequenceOfHAsciiString *mktlists ( TColStd_HSequenceOfHAsciiString *tlist1, TColStd_HSequenceOfHAsciiString *tlist2 ); -static ExpToCas_Type *mktstd ( int keyword ); -static ExpToCas_Type *mktname ( char *name ); -static ExpToCas_Type *mktset ( int keyword, int ilow, int ihigh, ExpToCas_Type *of ); -static ExpToCas_Field *mkfield ( char *name, ExpToCas_Type *type, int optional ); -static ExpToCas_HSequenceOfField *mkflist ( ExpToCas_Field *field, ExpToCas_HSequenceOfField *seq ); +static Express_Type *mktstd ( int keyword ); +static Express_Type *mktname ( char *name ); +static Express_Type *mktset ( int keyword, int ilow, int ihigh, Express_Type *of ); +static Express_Field *mkfield ( char *name, Express_Type *type, int optional ); +static Express_HSequenceOfField *mkflist ( Express_Field *field, Express_HSequenceOfField *seq ); %} @@ -101,13 +100,13 @@ static ExpToCas_HSequenceOfField *mkflist ( ExpToCas_Field *field, ExpToCas_HSeq int num; char *str; TColStd_HSequenceOfHAsciiString *tlist; - ExpToCas_HSequenceOfField *flist; - ExpToCas_HSequenceOfItem *ilist; - ExpToCas_Field *field; - ExpToCas_Item *item; - ExpToCas_Type *type; - ExpToCas_Schema *schema; - ExpToCas_Reference *ref; + Express_HSequenceOfField *flist; + Express_HSequenceOfItem *ilist; + Express_Field *field; + Express_Item *item; + Express_Type *type; + Express_Schema *schema; + Express_Reference *ref; } /* Definition of keywords */ @@ -241,7 +240,7 @@ SUPLST: NAME { $$ = 0; /* simple list of supertypes */ } FLIST : FIELD { $$ = mkflist ( $1, 0 ); /* list of fields of ENTITY item */ } | FIELD FLIST { $$ = mkflist ( $1, $2 ); } | REDEF { $$ = 0; /* redefinition of inherited field, just skip */ } - | REDEF FLIST { $$ = 0; } + | REDEF FLIST { $$ = $2; /* ignore redefinition of inherited field, take trailing list */ } ; FLIST1: /* empty */ { $$ = NULL; /* empty list of fields */ } | FLIST { $$ = $1; /* or not empty.. just to fix reduce/reduce conflict */ } @@ -277,49 +276,49 @@ SPCLST: KSELF '\\' SPECIF { $$ = 0; /* list of specifications */ } /************************************************/ /* FUNCTIONS FOR CREATING SCHEMA REPRESENTATION */ -static ExpToCas_Schema *mkschema ( char *name, ExpToCas_HSequenceOfItem *ilist ) +static Express_Schema *mkschema ( char *name, Express_HSequenceOfItem *ilist ) { - ExpToCas_Schema *sch = new ExpToCas_Schema ( name, ilist ); - ExpToCas::Schema() = sch; + Express_Schema *sch = new Express_Schema ( name, ilist ); + Express::Schema() = sch; return sch; } -static ExpToCas_HSequenceOfItem *mkilist ( ExpToCas_Item *item, ExpToCas_HSequenceOfItem *seq ) +static Express_HSequenceOfItem *mkilist ( Express_Item *item, Express_HSequenceOfItem *seq ) { if ( ! seq ) { - seq = new ExpToCas_HSequenceOfItem; + seq = new Express_HSequenceOfItem; seq->Append ( item ); } else seq->Prepend ( item ); return seq; } -static ExpToCas_Item *mkenum ( char *name, TColStd_HSequenceOfHAsciiString *tlist ) +static Express_Item *mkenum ( char *name, TColStd_HSequenceOfHAsciiString *tlist ) { - return new ExpToCas_Enum ( name, tlist ); + return new Express_Enum ( name, tlist ); } -static ExpToCas_Item *mkselect ( char *name, TColStd_HSequenceOfHAsciiString *tlist ) +static Express_Item *mkselect ( char *name, TColStd_HSequenceOfHAsciiString *tlist ) { - return new ExpToCas_Select ( name, tlist ); + return new Express_Select ( name, tlist ); } -static ExpToCas_Item *mkalias ( char *name, ExpToCas_Type *type ) +static Express_Item *mkalias ( char *name, Express_Type *type ) { - return new ExpToCas_Alias ( name, type ); + return new Express_Alias ( name, type ); } -static ExpToCas_Item *mkentity ( char *name, TColStd_HSequenceOfHAsciiString *inherit, - ExpToCas_HSequenceOfField *field, int isabstract ) +static Express_Item *mkentity ( char *name, TColStd_HSequenceOfHAsciiString *inherit, + Express_HSequenceOfField *field, int isabstract ) { - ExpToCas_Entity *ent = new ExpToCas_Entity ( name, inherit, field ); + Express_Entity *ent = new Express_Entity ( name, inherit, field ); if ( isabstract ) ent->SetAbstractFlag ( Standard_True ); return ent; } -static ExpToCas_Reference *mkrefs ( char *name, TColStd_HSequenceOfHAsciiString *items) +static Express_Reference *mkrefs ( char *name, TColStd_HSequenceOfHAsciiString *items) { - return new ExpToCas_Reference ( name, items ); + return new Express_Reference ( name, items ); } static TColStd_HSequenceOfHAsciiString *mktlist ( char *name, TColStd_HSequenceOfHAsciiString *tlist ) @@ -343,47 +342,47 @@ static TColStd_HSequenceOfHAsciiString *mktlists ( TColStd_HSequenceOfHAsciiStri return tlist1; } -static ExpToCas_Type *mktstd ( int keyword ) +static Express_Type *mktstd ( int keyword ) { switch ( keyword ) { - case KINT : return new ExpToCas_Integer; - case KNUM : return new ExpToCas_Number; - case KDBL : return new ExpToCas_Real; - case KSTR : return new ExpToCas_String; - case KBOOL: return new ExpToCas_Boolean; - case KLOG : return new ExpToCas_Logical; + case KINT : return new Express_Integer; + case KNUM : return new Express_Number; + case KDBL : return new Express_Real; + case KSTR : return new Express_String; + case KBOOL: return new Express_Boolean; + case KLOG : return new Express_Logical; default : ec_error ( "Predefined type not treated!", "" ); return NULL; } } -static ExpToCas_Type *mktname ( char *name ) +static Express_Type *mktname ( char *name ) { - return new ExpToCas_NamedType ( name ); + return new Express_NamedType ( name ); } -static ExpToCas_Type *mktset ( int keyword, int ilow, int ihigh, ExpToCas_Type *of ) +static Express_Type *mktset ( int keyword, int ilow, int ihigh, Express_Type *of ) { switch ( keyword ) { - case KLIST: return new ExpToCas_List ( ilow, ihigh, of ); - case KARR : return new ExpToCas_Array ( ilow, ihigh, of ); - case KBAG : return new ExpToCas_Bag ( ilow, ihigh, of ); - case KSET : return new ExpToCas_Set ( ilow, ihigh, of ); + case KLIST: return new Express_List ( ilow, ihigh, of ); + case KARR : return new Express_Array ( ilow, ihigh, of ); + case KBAG : return new Express_Bag ( ilow, ihigh, of ); + case KSET : return new Express_Set ( ilow, ihigh, of ); default : ec_error ( "Complex type not treated!", "" ); return NULL; } } -static ExpToCas_Field *mkfield ( char *name, ExpToCas_Type *type, int optional ) +static Express_Field *mkfield ( char *name, Express_Type *type, int optional ) { - return new ExpToCas_Field ( name, type, optional ); + return new Express_Field ( name, type, optional ); } -static ExpToCas_HSequenceOfField *mkflist ( ExpToCas_Field *field, ExpToCas_HSequenceOfField *seq ) +static Express_HSequenceOfField *mkflist ( Express_Field *field, Express_HSequenceOfField *seq ) { if ( seq ) seq->Prepend ( field ); else { - seq = new ExpToCas_HSequenceOfField; + seq = new Express_HSequenceOfField; seq->Append ( field ); } return seq; @@ -392,12 +391,12 @@ static ExpToCas_HSequenceOfField *mkflist ( ExpToCas_Field *field, ExpToCas_HSeq /*******************************************************************/ /* External interface to result of parsing */ -Handle(ExpToCas_Schema) ec_parse ( FILE *fin ) +Handle(Express_Schema) ec_parse ( FILE *fin ) { extern FILE *yyin; yyin = fin; yyparse(); - return ExpToCas::Schema(); + return Express::Schema(); } /*******************************************************************/ -- 2.39.5