Skip to content

Commit e343668

Browse files
committed
Merge pull request stepcode#279 from stepcode/review/lost-qualifiers
Lost qualifiers on inverse attributes and uniqueness rules
2 parents 6772b3a + 8f72192 commit e343668

18 files changed

Lines changed: 1099 additions & 955 deletions

src/exp2cxx/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ include_directories(
3333

3434
SC_ADDEXEC(exp2cxx "${exp2cxx_SOURCES}" "libexppp;express;base")
3535

36-
add_dependencies( exp2cxx version_string )
36+
add_dependencies( exp2cxx version_string )
37+
38+
if( SC_ENABLE_TESTING )
39+
add_subdirectory(test)
40+
endif( SC_ENABLE_TESTING )

src/exp2cxx/classes.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,27 +2502,21 @@ void ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap
25022502
uniqRule_formatted = whereRule_formatted;
25032503
}
25042504

2505-
/*
2506-
FIXME DASBUG
2507-
* take care of qualified attribute names like SELF\entity.attrname
2508-
* add parent entity to the uniqueness rule
2509-
* change EntityDescriptor::generate_express() to generate the UNIQUE clause
2510-
*/
25112505
LISTdo( uniqs, list, Linked_List ) {
25122506
int i = 0;
25132507
fprintf( files->create, " ur = new Uniqueness_rule(\"" );
2514-
LISTdo_n( list, v, Variable, b ) {
2508+
LISTdo_n( list, e, Expression, b ) {
25152509
i++;
25162510
if( i == 1 ) {
25172511
/* print label if present */
2518-
if( v ) {
2519-
fprintf( files->create, "%s : ", StrToUpper( ( ( Symbol * )v )->name ) );
2512+
if( e ) {
2513+
fprintf( files->create, "%s : ", StrToUpper( ( ( Symbol * )e )->name ) );
25202514
}
25212515
} else {
25222516
if( i > 2 ) {
25232517
fprintf( files->create, ", " );
25242518
}
2525-
uniqRule = EXPRto_string( v->name );
2519+
uniqRule = EXPRto_string( e );
25262520
fprintf( files->create, "%s", uniqRule );
25272521
sc_free( uniqRule );
25282522
}

src/exp2cxx/test/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#tests specific to exp2cxx
2+
3+
set( unitary_dir ${SC_SOURCE_DIR}/test/unitary_schemas )
4+
5+
add_test( NAME test_exp2cxx_unique_qualifiers
6+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
7+
COMMAND ${CMAKE_COMMAND} -DEXE=$<TARGET_FILE:exp2cxx>
8+
-DINFILE=${unitary_dir}/unique_qualifiers.exp
9+
-P ${CMAKE_CURRENT_SOURCE_DIR}/unique_qualifiers.cmake
10+
)
11+
12+
add_test( NAME test_exp2cxx_inverse_qualifiers
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
14+
COMMAND ${CMAKE_COMMAND} -DEXE=$<TARGET_FILE:exp2cxx>
15+
-DINFILE=${unitary_dir}/inverse_qualifiers.exp
16+
-P ${CMAKE_CURRENT_SOURCE_DIR}/inverse_qualifiers.cmake
17+
)
18+
set_tests_properties( test_exp2cxx_unique_qualifiers test_exp2cxx_inverse_qualifiers PROPERTIES DEPENDS exp2cxx )
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required( VERSION 2.8 )
2+
3+
# executable is ${EXE}, input file is ${INFILE}
4+
5+
set( ofile "SdaiINVERSE_PROBLEM.init.cc" )
6+
execute_process( COMMAND ${EXE} ${INFILE}
7+
RESULT_VARIABLE CMD_RESULT )
8+
if( NOT ${CMD_RESULT} EQUAL 0 )
9+
message(FATAL_ERROR "Error running ${EXE} on ${INFILE}")
10+
endif( NOT ${CMD_RESULT} EQUAL 0 )
11+
12+
file( READ ${ofile} cxx LIMIT 10240 ) #9051 bytes now
13+
14+
# new Inverse_attribute("product_occurrence.occurrence_contexts"
15+
string( REGEX MATCH "new *Inverse_attribute *\\\( *\\\" *product_occurrence *\\. *occurrence_contexts" match_result ${cxx} )
16+
17+
if( match_result STREQUAL "" )
18+
message( FATAL_ERROR "exp2cxx output does not match input schema." )
19+
endif( match_result STREQUAL "" )
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required( VERSION 2.8 )
2+
3+
# executable is ${EXE}, input file is ${INFILE}
4+
5+
set( ofile "SdaiAll.cc" )
6+
execute_process( COMMAND ${EXE} ${INFILE}
7+
RESULT_VARIABLE CMD_RESULT )
8+
if( NOT ${CMD_RESULT} EQUAL 0 )
9+
message(FATAL_ERROR "Error running ${EXE} on ${INFILE}")
10+
endif( NOT ${CMD_RESULT} EQUAL 0 )
11+
12+
file( READ ${ofile} cxx LIMIT 4096 )
13+
14+
# ur = new Uniqueness_rule("UR1 : SELF\shape_aspect_relationship.name;\n");
15+
string( REGEX MATCH "new *Uniqueness_rule *\\\( *\\\" *[uU][rR]1 *: *SELF *\\\\ *shape_aspect_relationship *\\. *name" match_result ${cxx} )
16+
17+
if( match_result STREQUAL "" )
18+
message( FATAL_ERROR "exp2cxx output does not match input schema." )
19+
endif( match_result STREQUAL "" )

src/exppp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ set_target_properties(libexppp PROPERTIES PREFIX "")
3939

4040
SC_ADDEXEC(exppp "${EXPPP_SOURCES}" "libexppp;express;base")
4141

42-
if( ENABLE_TESTING )
42+
if( SC_ENABLE_TESTING )
4343
add_subdirectory(test)
44-
endif( ENABLE_TESTING )
44+
endif( SC_ENABLE_TESTING )

src/exppp/pretty_entity.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,20 @@ void ENTITYunique_out( Linked_List u, int level ) {
102102

103103
LISTdo( u, list, Linked_List ) {
104104
i = 0;
105-
LISTdo_n( list, v, Variable, b ) {
105+
LISTdo_n( list, e, Expression, b ) {
106106
i++;
107107
if( i == 1 ) {
108108
/* print label if present */
109-
if( v ) {
110-
raw( "%*s%-*s : ", level, "",
111-
max_indent, ( ( Symbol * )v )->name );
109+
if( e ) {
110+
raw( "%*s%-*s : ", level, "", max_indent, ( ( Symbol * )e )->name );
112111
} else {
113-
raw( "%*s%-*s ", level, "",
114-
max_indent, "" );
112+
raw( "%*s%-*s ", level, "", max_indent, "" );
115113
}
116114
} else {
117115
if( i > 2 ) {
118116
raw( ", " );
119117
}
120-
EXPR_out( v->name, 0 );
118+
EXPR_out( e, 0 );
121119
}
122120
} LISTod
123121
raw( ";\n" );
@@ -150,8 +148,9 @@ void ENTITYinverse_out( Linked_List attrs, int level ) {
150148
LISTdo( attrs, v, Variable ) {
151149
if( v->inverse_symbol ) {
152150
/* print attribute name */
153-
raw( "%*s%-*s :", level, "",
154-
max_indent, v->name->symbol.name );
151+
raw( "%*s", level, "" );
152+
EXPR_out( v->name, 0 );
153+
raw( "%-*s :", ( ( ( max_indent - curpos ) > 0 ) ? max_indent - curpos : 0 ), "" );
155154

156155
/* print attribute type */
157156
if( VARget_optional( v ) ) {

src/exppp/test/CMakeLists.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required( VERSION 2.8 )
12
project( test_exppp )
23

34
set( breakLongStr_SRCS
@@ -6,6 +7,32 @@ set( breakLongStr_SRCS
67
)
78

89
# this executable doesn't really check the results, just ensures no segfaults. ought to improve it...
9-
SC_ADDEXEC( test_breakLongStr "${breakLongStr_SRCS}" "express;base" )
10+
SC_ADDEXEC( tst_breakLongStr "${breakLongStr_SRCS}" "express;base" "TESTABLE" )
11+
add_test( NAME build_tst_breakLongStr
12+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
13+
COMMAND ${CMAKE_COMMAND} --build .
14+
--target tst_breakLongStr
15+
--config $<CONFIGURATION> )
16+
add_test( test_breakLongStr ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tst_breakLongStr )
17+
set_tests_properties( test_breakLongStr PROPERTIES DEPENDS build_tst_breakLongStr )
1018

1119
#could run test schemas through exppp, then check line length...
20+
21+
22+
# ---- syntax tests ----
23+
set( unitary_dir ${SC_SOURCE_DIR}/test/unitary_schemas )
24+
25+
add_test( NAME test_exppp_unique_qualifiers
26+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
27+
COMMAND ${CMAKE_COMMAND} -DEXPPP=$<TARGET_FILE:exppp>
28+
-DINFILE=${unitary_dir}/unique_qualifiers.exp
29+
-P ${CMAKE_CURRENT_SOURCE_DIR}/unique_qualifiers.cmake
30+
)
31+
32+
add_test( NAME test_exppp_inverse_qualifiers
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
34+
COMMAND ${CMAKE_COMMAND} -DEXPPP=$<TARGET_FILE:exppp>
35+
-DINFILE=${unitary_dir}/inverse_qualifiers.exp
36+
-P ${CMAKE_CURRENT_SOURCE_DIR}/inverse_qualifiers.cmake
37+
)
38+
set_tests_properties( test_exppp_unique_qualifiers test_exppp_inverse_qualifiers PROPERTIES DEPENDS exppp )
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required( VERSION 2.8 )
2+
3+
# executable is ${EXPPP}, input file is ${INFILE}
4+
5+
set( ofile "inverse_qual_out.exp" )
6+
execute_process( COMMAND ${EXPPP} -o ${ofile} ${INFILE}
7+
RESULT_VARIABLE CMD_RESULT )
8+
if( NOT ${CMD_RESULT} EQUAL 0 )
9+
message(FATAL_ERROR "Error running ${EXPPP} on ${INFILE}")
10+
endif( NOT ${CMD_RESULT} EQUAL 0 )
11+
12+
# file( READ ${INFILE} pretty_in LIMIT 1024 )
13+
file( READ ${ofile} pretty_out LIMIT 1024 )
14+
15+
# SELF\product_occurrence.occurrence_contexts : SET [1 : ?] OF assembly_component_relationship FOR related_view;
16+
# one backslash baloons into 4 x(
17+
string( REGEX MATCH " *SELF *\\\\ *product_occurrence *\\. *occurrence_contexts *: *SET *\\[ *1 *:" match_result ${pretty_out} )
18+
19+
if( match_result STREQUAL "" )
20+
message( FATAL_ERROR "Pretty printer output does not match input." )
21+
endif( match_result STREQUAL "" )

src/exppp/test/test_breakLongStr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdlib.h>
22
#include "../pp.h"
3+
#include "exppp.h"
34

45
int main() {
56
char * testarr[] = {

0 commit comments

Comments
 (0)