Skip to content

Commit 1d34753

Browse files
committed
Merge pull request stepcode#166 from mpictor/review/aggr_runtime_bounds
Runtime bounds for aggregates
2 parents 52bb54d + aa97040 commit 1d34753

14 files changed

Lines changed: 485 additions & 157 deletions

File tree

run_ctest.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ if(NOT SKIP_TEST_EXCHANGE_FILE )
133133
SUBMIT_TEST( Test )
134134
endif()
135135

136+
if(NOT SKIP_TEST_CPP_SCHEMA_SPECIFIC )
137+
ctest_test( BUILD "${CTEST_BINARY_DIRECTORY}" APPEND
138+
PARALLEL_LEVEL ${PROCESSOR_COUNT} INCLUDE_LABEL "cpp_schema_specific" )
139+
SUBMIT_TEST( Test )
140+
endif()
141+
142+
136143
# ctest_coverage( )

src/cleditor/SdaiHeaderSchemaInit.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
5353
header_section_schemae_file_population->AddExplicitAttr( a_3determination_method );
5454
SetTypeDescriptor * t_0 = new SetTypeDescriptor;
5555
t_0->AssignAggrCreator( ( AggregateCreator ) create_StringAggregate ); // Creator function
56-
t_0->Bound1( 1 );
57-
t_0->Bound2( 2147483647 );
56+
t_0->SetBound1( 1 );
57+
t_0->SetBound2( 2147483647 );
5858
t_0->FundamentalType( SET_TYPE );
5959
t_0->Description( "SET [1:?] OF section_name" );
6060
t_0->OriginatingSchema( s_header_section_schema );
@@ -81,8 +81,8 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
8181
header_section_schemae_file_name->AddExplicitAttr( a_6time_stamp );
8282
ListTypeDescriptor * t_1 = new ListTypeDescriptor;
8383
t_1->AssignAggrCreator( ( AggregateCreator ) create_StringAggregate ); // Creator function
84-
t_1->Bound1( 1 );
85-
t_1->Bound2( 2147483647 );
84+
t_1->SetBound1( 1 );
85+
t_1->SetBound2( 2147483647 );
8686
t_1->FundamentalType( LIST_TYPE );
8787
t_1->Description( "LIST [1:?] OF STRING (256)" );
8888
t_1->OriginatingSchema( s_header_section_schema );
@@ -94,8 +94,8 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
9494
header_section_schemae_file_name->AddExplicitAttr( a_7author );
9595
ListTypeDescriptor * t_2 = new ListTypeDescriptor;
9696
t_2->AssignAggrCreator( ( AggregateCreator ) create_StringAggregate ); // Creator function
97-
t_2->Bound1( 1 );
98-
t_2->Bound2( 2147483647 );
97+
t_2->SetBound1( 1 );
98+
t_2->SetBound2( 2147483647 );
9999
t_2->FundamentalType( LIST_TYPE );
100100
t_2->Description( "LIST [1:?] OF STRING (256)" );
101101
t_2->OriginatingSchema( s_header_section_schema );
@@ -132,8 +132,8 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
132132
header_section_schemae_section_context->AddExplicitAttr( a_12section );
133133
ListTypeDescriptor * t_3 = new ListTypeDescriptor;
134134
t_3->AssignAggrCreator( ( AggregateCreator ) create_StringAggregate ); // Creator function
135-
t_3->Bound1( 1 );
136-
t_3->Bound2( 2147483647 );
135+
t_3->SetBound1( 1 );
136+
t_3->SetBound2( 2147483647 );
137137
t_3->FundamentalType( LIST_TYPE );
138138
t_3->Description( "LIST [1:?] OF context_name" );
139139
t_3->OriginatingSchema( s_header_section_schema );
@@ -150,8 +150,8 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
150150

151151
ListTypeDescriptor * t_4 = new ListTypeDescriptor;
152152
t_4->AssignAggrCreator( ( AggregateCreator ) create_StringAggregate ); // Creator function
153-
t_4->Bound1( 1 );
154-
t_4->Bound2( 2147483647 );
153+
t_4->SetBound1( 1 );
154+
t_4->SetBound2( 2147483647 );
155155
t_4->FundamentalType( LIST_TYPE );
156156
t_4->Description( "LIST [1:?] OF STRING (256)" );
157157
t_4->OriginatingSchema( s_header_section_schema );
@@ -173,8 +173,8 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
173173

174174
ListTypeDescriptor * t_5 = new ListTypeDescriptor;
175175
t_5->AssignAggrCreator( ( AggregateCreator ) create_StringAggregate ); // Creator function
176-
t_5->Bound1( 1 );
177-
t_5->Bound2( 2147483647 );
176+
t_5->SetBound1( 1 );
177+
t_5->SetBound2( 2147483647 );
178178
t_5->UniqueElements( LTrue );
179179
t_5->FundamentalType( LIST_TYPE );
180180
t_5->Description( "LIST [1:?] OF UNIQUE schema_name" );

src/clstepcore/ExpDict.h

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <deque>
1919
#include <string>
20+
#include <assert.h>
2021

2122
typedef SDAI_Application_instance * ( * Creator )() ;
2223

@@ -27,6 +28,13 @@ enum AttrType_Enum {
2728
AttrType_Redefining
2829
};
2930

31+
enum AggrBoundTypeEnum {
32+
bound_unset = 0,
33+
bound_constant,
34+
bound_runtime,
35+
bound_funcall
36+
};
37+
3038
#include <SingleLinkList.h>
3139

3240
#include <baseType.h>
@@ -1636,6 +1644,8 @@ SCL_CORE_EXPORT RealAggregate * create_RealAggregate();
16361644

16371645
SCL_CORE_EXPORT IntAggregate * create_IntAggregate();
16381646

1647+
typedef SDAI_Integer (*boundCallbackFn)(SDAI_Application_instance *);
1648+
16391649
/**
16401650
* \class AggrTypeDescriptor
16411651
* I think we decided on a simplistic representation of aggr. types for now?
@@ -1651,12 +1661,15 @@ class SCL_CORE_EXPORT AggrTypeDescriptor : public TypeDescriptor {
16511661

16521662
protected:
16531663

1654-
SDAI_Integer _bound1 ;
1655-
SDAI_Integer _bound2 ;
1664+
SDAI_Integer _bound1, _bound2;
16561665
SDAI_LOGICAL _uniqueElements ;
16571666
TypeDescriptor * _aggrDomainType ;
16581667
AggregateCreator CreateNewAggr;
16591668

1669+
AggrBoundTypeEnum _bound1_type, _bound2_type;
1670+
boundCallbackFn _bound1_callback, _bound2_callback;
1671+
std::string _bound1_str, _bound2_str;
1672+
16601673
public:
16611674

16621675
void AssignAggrCreator( AggregateCreator f = 0 ) {
@@ -1672,22 +1685,72 @@ class SCL_CORE_EXPORT AggrTypeDescriptor : public TypeDescriptor {
16721685
AggrTypeDescriptor( const char * nm, PrimitiveType ft,
16731686
Schema * origSchema, const char * d,
16741687
AggregateCreator f = 0 )
1675-
: TypeDescriptor( nm, ft, origSchema, d ), CreateNewAggr( f ) { }
1688+
: TypeDescriptor( nm, ft, origSchema, d ), CreateNewAggr( f ) { }
16761689
virtual ~AggrTypeDescriptor();
16771690

16781691

1679-
SDAI_Integer & Bound1() {
1692+
/// find bound type
1693+
AggrBoundTypeEnum Bound1Type() const { return _bound1_type; };
1694+
/// get a constant bound
1695+
SDAI_Integer Bound1( ) const {
1696+
assert( _bound1_type == bound_constant );
16801697
return _bound1;
16811698
}
1682-
void Bound1( SDAI_Integer b1 ) {
1699+
/// get a runtime bound using an object's 'this' pointer
1700+
SDAI_Integer Bound1Runtime( SDAI_Application_instance* this_ptr) const {
1701+
assert( this_ptr && ( _bound1_type == bound_runtime ) );
1702+
return _bound1_callback(this_ptr) ;
1703+
}
1704+
/// get a bound's EXPRESS function call string
1705+
std::string Bound1Funcall() const {
1706+
return _bound1_str;
1707+
}
1708+
/// set bound to a constant
1709+
void SetBound1( SDAI_Integer b1 ) {
16831710
_bound1 = b1;
1711+
_bound1_type = bound_constant;
1712+
}
1713+
///set bound's callback fn. only for bounds dependent on an attribute
1714+
void SetBound1FromMemberAccessor( boundCallbackFn callback ) {
1715+
_bound1_callback = callback;
1716+
_bound1_type = bound_runtime;
1717+
}
1718+
///set bound from express function call. currently, this only stores the function call as a string.
1719+
void SetBound1FromExpressFuncall( std::string s ) {
1720+
_bound1_str = s;
1721+
_bound1_type = bound_funcall;
16841722
}
16851723

1686-
SDAI_Integer & Bound2() {
1724+
/// find bound type
1725+
AggrBoundTypeEnum Bound2Type() const { return _bound2_type; };
1726+
/// get a constant bound
1727+
SDAI_Integer Bound2( ) const {
1728+
assert( _bound2_type == bound_constant );
16871729
return _bound2;
16881730
}
1689-
void Bound2( SDAI_Integer b2 ) {
1731+
/// get a runtime bound using an object's 'this' pointer
1732+
SDAI_Integer Bound2Runtime( SDAI_Application_instance* this_ptr) const {
1733+
assert( this_ptr && ( _bound2_type == bound_runtime ) );
1734+
return _bound2_callback(this_ptr) ;
1735+
}
1736+
/// get a bound's EXPRESS function call string
1737+
std::string Bound2Funcall() const {
1738+
return _bound2_str;
1739+
}
1740+
/// set bound to a constant
1741+
void SetBound2( SDAI_Integer b2 ) {
16901742
_bound2 = b2;
1743+
_bound2_type = bound_constant;
1744+
}
1745+
///set bound's callback fn
1746+
void SetBound2FromMemberAccessor( boundCallbackFn callback ){
1747+
_bound2_callback = callback;
1748+
_bound2_type = bound_runtime;
1749+
}
1750+
///set bound from express function call. currently, this only stores the function call as a string.
1751+
void SetBound2FromExpressFuncall( std::string s ) {
1752+
_bound2_str = s;
1753+
_bound2_type = bound_funcall;
16911754
}
16921755

16931756
SDAI_LOGICAL & UniqueElements() {

src/express/expr.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,19 @@ Type EXPresolve_op_group( Expression expr, Scope scope ) {
568568
/* &op2->symbol, op2->symbol.name);*/
569569
return( Type_Runtime );
570570
}
571+
case array_:
572+
if( op1->type->u.type->body->type == self_ ) {
573+
if( yydebug ) {
574+
printf("%s:%d: Array with 'SELF' in upper or lower bound, setting type as Type_Runtime\n",__FILE__,__LINE__);
575+
}
576+
return( Type_Runtime ); //not sure if there are other cases where Type_Runtime should be returned, or not
577+
} // else fallthrough
571578
case unknown_: /* unable to resolve operand */
572579
/* presumably error has already been reported */
573580
resolve_failed( expr );
574581
return( Type_Bad );
575582
case aggregate_:
576-
case array_:
583+
577584
case bag_:
578585
case list_:
579586
case set_:

0 commit comments

Comments
 (0)