* Better support of where/rules functions

* Bugfix in OPTIONAL attributes
This commit is contained in:
tpaviot
2012-05-11 12:08:25 +02:00
parent 58e340b36c
commit ee13526af5
8 changed files with 804 additions and 6 deletions
@@ -70,6 +70,13 @@ class shape_aspect(BaseEntityClass):
else:
self._of_shape = value
return property(**locals())
def wr1(self):
eval_wr1_wr = (SIZEOF(USEDIN(self,'INDEX_ATTRIBUTE.' + 'ID_ATTRIBUTE.IDENTIFIED_ITEM')) <= 1)
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
####################
# ENTITY general_datum_reference #
@@ -97,6 +104,13 @@ class general_datum_reference(shape_aspect):
else:
self._base = value
return property(**locals())
def wr1(self):
eval_wr1_wr = (( not ('INDEX_ATTRIBUTE.COMMON_DATUM_LIST' == TYPEOF(self.base))) or (self.self.shape_aspect.self.of_shape == self.base[1].self.shape_aspect.self.of_shape))
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
####################
# ENTITY product_definition_shape #
@@ -137,6 +137,13 @@ class shape_representation_relationship(representation_relationship):
'''
def __init__( self , inherited0__name , inherited1__rep_1 , inherited2__rep_2 , ):
representation_relationship.__init__(self , inherited0__name , inherited1__rep_1 , inherited2__rep_2 , )
def wr1(self):
eval_wr1_wr = ('MULTIPLE_REP.SHAPE_REPRESENTATION' == (TYPEOF(self.self.representation_relationship.self.rep_1) + TYPEOF(self.self.representation_relationship.self.rep_2)))
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
####################
# ENTITY representation #
@@ -199,6 +206,20 @@ class representation(BaseEntityClass):
else:
self._context_of_items = value
return property(**locals())
def wr1(self):
eval_wr1_wr = (SIZEOF(USEDIN(self,'MULTIPLE_REP.' + 'ID_ATTRIBUTE.IDENTIFIED_ITEM')) <= 1)
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
def wr2(self):
eval_wr2_wr = (SIZEOF(USEDIN(self,'MULTIPLE_REP.' + 'DESCRIPTION_ATTRIBUTE.DESCRIBED_ITEM')) <= 1)
if not eval_wr2_wr:
raise AssertionError('Rule wr2 violated')
else:
return eval_wr2_wr
####################
# ENTITY property_definition #
@@ -243,6 +264,13 @@ class property_definition(BaseEntityClass):
else:
self._definition = value
return property(**locals())
def wr1(self):
eval_wr1_wr = (SIZEOF(USEDIN(self,'MULTIPLE_REP.' + 'ID_ATTRIBUTE.IDENTIFIED_ITEM')) <= 1)
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
####################
# ENTITY context_dependent_shape_representation #
@@ -269,6 +297,20 @@ class context_dependent_shape_representation(BaseEntityClass):
else:
self._representation_relation = value
return property(**locals())
def wr2(self):
eval_wr2_wr = (SIZEOF(USEDIN(self,'MULTIPLE_REP.' + 'DESCRIPTION_ATTRIBUTE.DESCRIBED_ITEM')) <= 1)
if not eval_wr2_wr:
raise AssertionError('Rule wr2 violated')
else:
return eval_wr2_wr
def wr3(self):
eval_wr3_wr = (SIZEOF(USEDIN(self,'MULTIPLE_REP.' + 'NAME_ATTRIBUTE.NAMED_ITEM')) <= 1)
if not eval_wr3_wr:
raise AssertionError('Rule wr3 violated')
else:
return eval_wr3_wr
####################
# ENTITY definitional_representation_relationship #
@@ -302,3 +344,10 @@ class component_2d_location(context_dependent_shape_representation,shape_represe
# DERIVED argument
raise AssertionError('Argument context_dependent_shape_representation_representation_relation is DERIVED. It is computed and can not be set to any value')
return property(**locals())
def wr1(self):
eval_wr1_wr = (self.self.representation_relationship.self.name == 'component 2d location')
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
@@ -96,7 +96,7 @@ class circle(BaseEntityClass):
@apply
def area():
def fget( self ):
attribute_eval = ( PI * (radius ** 2))
attribute_eval = ( PI * (self.radius ** 2))
return attribute_eval
def fset( self, value ):
# DERIVED argument
@@ -106,7 +106,7 @@ class circle(BaseEntityClass):
@apply
def perimeter():
def fget( self ):
attribute_eval = ((2 * PI ) * radius)
attribute_eval = ((2 * PI ) * self.radius)
return attribute_eval
def fset( self, value ):
# DERIVED argument
@@ -0,0 +1,322 @@
# This file was generated by fedex_python. You probably don't want to edit
# it since your modifications will be lost if fedex_plus is used to
# regenerate it.
import sys
from SCL.SCLBase import *
from SCL.SimpleDataTypes import *
from SCL.ConstructedDataTypes import *
from SCL.AggregationDataTypes import *
from SCL.TypeChecker import check_type
from SCL.Builtin import *
from SCL.Rules import *
schema_name = 'test_entity_where_rule'
schema_scope = sys.modules[__name__]
# Defined datatype label
class label(STRING):
def __init__(self,*kargs):
pass
####################
# ENTITY unit_vector #
####################
class unit_vector(BaseEntityClass):
'''Entity unit_vector definition.
:param a
:type a:REAL
:param b
:type b:REAL
:param c
:type c:REAL
'''
def __init__( self , a,b,c, ):
self.a = a
self.b = b
self.c = c
@apply
def a():
def fget( self ):
return self._a
def fset( self, value ):
# Mandatory argument
if value==None:
raise AssertionError('Argument a is mantatory and can not be set to None')
if not check_type(value,REAL):
self._a = REAL(value)
else:
self._a = value
return property(**locals())
@apply
def b():
def fget( self ):
return self._b
def fset( self, value ):
# Mandatory argument
if value==None:
raise AssertionError('Argument b is mantatory and can not be set to None')
if not check_type(value,REAL):
self._b = REAL(value)
else:
self._b = value
return property(**locals())
@apply
def c():
def fget( self ):
return self._c
def fset( self, value ):
# Mandatory argument
if value==None:
raise AssertionError('Argument c is mantatory and can not be set to None')
if not check_type(value,REAL):
self._c = REAL(value)
else:
self._c = value
return property(**locals())
def length_1(self):
eval_length_1_wr = ((((self.a ** 2) + (self.b ** 2)) + (self.c ** 2)) == 1)
if not eval_length_1_wr:
raise AssertionError('Rule length_1 violated')
else:
return eval_length_1_wr
####################
# ENTITY address #
####################
class address(BaseEntityClass):
'''Entity address definition.
:param internal_location
:type internal_location:label
:param street_number
:type street_number:label
:param street
:type street:label
:param postal_box
:type postal_box:label
:param town
:type town:label
:param region
:type region:label
:param postal_code
:type postal_code:label
:param country
:type country:label
:param facsimile_number
:type facsimile_number:label
:param telephone_number
:type telephone_number:label
:param electronic_mail_address
:type electronic_mail_address:label
:param telex_number
:type telex_number:label
'''
def __init__( self , internal_location,street_number,street,postal_box,town,region,postal_code,country,facsimile_number,telephone_number,electronic_mail_address,telex_number, ):
self.internal_location = internal_location
self.street_number = street_number
self.street = street
self.postal_box = postal_box
self.town = town
self.region = region
self.postal_code = postal_code
self.country = country
self.facsimile_number = facsimile_number
self.telephone_number = telephone_number
self.electronic_mail_address = electronic_mail_address
self.telex_number = telex_number
@apply
def internal_location():
def fget( self ):
return self._internal_location
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._internal_location = label(value)
else:
self._internal_location = value
else:
self._internal_location = value
return property(**locals())
@apply
def street_number():
def fget( self ):
return self._street_number
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._street_number = label(value)
else:
self._street_number = value
else:
self._street_number = value
return property(**locals())
@apply
def street():
def fget( self ):
return self._street
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._street = label(value)
else:
self._street = value
else:
self._street = value
return property(**locals())
@apply
def postal_box():
def fget( self ):
return self._postal_box
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._postal_box = label(value)
else:
self._postal_box = value
else:
self._postal_box = value
return property(**locals())
@apply
def town():
def fget( self ):
return self._town
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._town = label(value)
else:
self._town = value
else:
self._town = value
return property(**locals())
@apply
def region():
def fget( self ):
return self._region
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._region = label(value)
else:
self._region = value
else:
self._region = value
return property(**locals())
@apply
def postal_code():
def fget( self ):
return self._postal_code
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._postal_code = label(value)
else:
self._postal_code = value
else:
self._postal_code = value
return property(**locals())
@apply
def country():
def fget( self ):
return self._country
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._country = label(value)
else:
self._country = value
else:
self._country = value
return property(**locals())
@apply
def facsimile_number():
def fget( self ):
return self._facsimile_number
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._facsimile_number = label(value)
else:
self._facsimile_number = value
else:
self._facsimile_number = value
return property(**locals())
@apply
def telephone_number():
def fget( self ):
return self._telephone_number
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._telephone_number = label(value)
else:
self._telephone_number = value
else:
self._telephone_number = value
return property(**locals())
@apply
def electronic_mail_address():
def fget( self ):
return self._electronic_mail_address
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._electronic_mail_address = label(value)
else:
self._electronic_mail_address = value
else:
self._electronic_mail_address = value
return property(**locals())
@apply
def telex_number():
def fget( self ):
return self._telex_number
def fset( self, value ):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._telex_number = label(value)
else:
self._telex_number = value
else:
self._telex_number = value
return property(**locals())
def wr1(self):
eval_wr1_wr = (((((((((((EXISTS(self.internal_location) or EXISTS(self.street_number)) or EXISTS(self.street)) or EXISTS(self.postal_box)) or EXISTS(self.town)) or EXISTS(self.region)) or EXISTS(self.postal_code)) or EXISTS(self.country)) or EXISTS(self.facsimile_number)) or EXISTS(self.telephone_number)) or EXISTS(self.electronic_mail_address)) or EXISTS(self.telex_number))
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
@@ -100,6 +100,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._internal_location = label(value)
else:
self._internal_location = value
else:
self._internal_location = value
return property(**locals())
@@ -112,6 +114,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._street_number = label(value)
else:
self._street_number = value
else:
self._street_number = value
return property(**locals())
@@ -124,6 +128,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._street = label(value)
else:
self._street = value
else:
self._street = value
return property(**locals())
@@ -136,6 +142,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._postal_box = label(value)
else:
self._postal_box = value
else:
self._postal_box = value
return property(**locals())
@@ -148,6 +156,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._town = label(value)
else:
self._town = value
else:
self._town = value
return property(**locals())
@@ -160,6 +170,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._region = label(value)
else:
self._region = value
else:
self._region = value
return property(**locals())
@@ -172,6 +184,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._postal_code = label(value)
else:
self._postal_code = value
else:
self._postal_code = value
return property(**locals())
@@ -184,6 +198,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._country = label(value)
else:
self._country = value
else:
self._country = value
return property(**locals())
@@ -196,6 +212,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._facsimile_number = label(value)
else:
self._facsimile_number = value
else:
self._facsimile_number = value
return property(**locals())
@@ -208,6 +226,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._telephone_number = label(value)
else:
self._telephone_number = value
else:
self._telephone_number = value
return property(**locals())
@@ -220,6 +240,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._electronic_mail_address = label(value)
else:
self._electronic_mail_address = value
else:
self._electronic_mail_address = value
return property(**locals())
@@ -232,6 +254,8 @@ class address(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._telex_number = label(value)
else:
self._telex_number = value
else:
self._telex_number = value
return property(**locals())
@@ -275,6 +299,8 @@ class personal_address(address):
if value != None: # OPTIONAL attribute
if not check_type(value,text):
self._description = text(value)
else:
self._description = value
else:
self._description = value
return property(**locals())
@@ -318,6 +344,8 @@ class organizational_address(address):
if value != None: # OPTIONAL attribute
if not check_type(value,text):
self._description = text(value)
else:
self._description = value
else:
self._description = value
return property(**locals())
@@ -376,6 +404,8 @@ class person(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._last_name = label(value)
else:
self._last_name = value
else:
self._last_name = value
return property(**locals())
@@ -388,6 +418,8 @@ class person(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,label):
self._first_name = label(value)
else:
self._first_name = value
else:
self._first_name = value
return property(**locals())
@@ -400,6 +432,8 @@ class person(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,LIST(1,None,'STRING', scope = schema_scope)):
self._middle_names = LIST(value)
else:
self._middle_names = value
else:
self._middle_names = value
return property(**locals())
@@ -412,6 +446,8 @@ class person(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,LIST(1,None,'STRING', scope = schema_scope)):
self._prefix_titles = LIST(value)
else:
self._prefix_titles = value
else:
self._prefix_titles = value
return property(**locals())
@@ -424,9 +460,18 @@ class person(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,LIST(1,None,'STRING', scope = schema_scope)):
self._suffix_titles = LIST(value)
else:
self._suffix_titles = value
else:
self._suffix_titles = value
return property(**locals())
def wr1(self):
eval_wr1_wr = (EXISTS(self.last_name) or EXISTS(self.first_name))
if not eval_wr1_wr:
raise AssertionError('Rule wr1 violated')
else:
return eval_wr1_wr
####################
# ENTITY organization #
@@ -456,6 +501,8 @@ class organization(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,identifier):
self._id = identifier(value)
else:
self._id = value
else:
self._id = value
return property(**locals())
@@ -482,6 +529,8 @@ class organization(BaseEntityClass):
if value != None: # OPTIONAL attribute
if not check_type(value,text):
self._description = text(value)
else:
self._description = value
else:
self._description = value
return property(**locals())
+259 -4
View File
@@ -38,6 +38,11 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
EXPRESSIONop2__out(oe,string,paren,pad,OP_UNKNOWN,f)
#define EXPRESSIONop_out(oe,paren,f) EXPRESSIONop__out(oe,paren,OP_UNKNOWN,f)
#define ATTRIBUTE_INITIALIZER_out(e,p,f) ATTRIBUTE_INITIALIZER__out(e,p,OP_UNKNOWN,f)
#define ATTRIBUTE_INITIALIZERop2_out(oe,string,paren,pad,f) \
ATTRIBUTE_INITIALIZERop2__out(oe,string,paren,pad,OP_UNKNOWN,f)
#define ATTRIBUTE_INITIALIZERop_out(oe,paren,f) ATTRIBUTE_INITIALIZERop__out(oe,paren,OP_UNKNOWN,f)
#define PAD 1
#define NOPAD 0
@@ -754,7 +759,7 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) {
// evaluation of attribute
fprintf(file,"\t\t\tattribute_eval = ");
// outputs expression initializer
EXPRESSION_out(v->initializer,1,file);
ATTRIBUTE_INITIALIZER_out(v->initializer,1,file);
// then returns the value
fprintf(file,"\n\t\t\treturn attribute_eval\n");
}
@@ -801,12 +806,15 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) {
fprintf(file, "\t\t\t\tself._%s = ",attrnm);
print_aggregate_type(file,t);
fprintf(file,"(value)\n");
fprintf(file, "\t\t\telse:\n\t");
}
else {
fprintf(file, "\t\t\t\tself._%s = %s(value)\n",attrnm,attr_type);
fprintf(file, "\t\t\telse:\n\t");
}
if (VARget_optional(v)) {
fprintf(file,"\t\t\t\telse:\n");
fprintf(file,"\t\t\t\t\tself._%s = value\n",attrnm);
}
fprintf(file, "\t\t\telse:\n\t");
fprintf(file,"\t\t\tself._%s = value\n",attrnm);
}
// if the attribute is derived, prevent fset to attribute to be set
@@ -821,6 +829,8 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) {
fprintf(file,"\t\treturn property(**locals())\n");
LISTod
}
// before exiting, process where rules
WHEREPrint( entity->where, 0, file );
}
int
@@ -1174,6 +1184,126 @@ STATEMENTlist_out( Linked_List stmts, int indent_level, FILE *file ) {
STATEMENTPrint( stmt, indent_level, file );
LISTod
}
/*****************************************************************
** Procedure: ATTRIBUTE_INITIALIZER__out
** Description: this method is almost the same as EXPRESSION__out
** but it adds self. before each attribute identifier
**
******************************************************************/
void
ATTRIBUTE_INITIALIZER__out( Expression e, int paren, int previous_op , FILE *file) {
fprintf(stdout, "on est dedan!!");
int i; /* trusty temporary */
switch( TYPEis( e->type ) ) {
case integer_:
if( e == LITERAL_INFINITY ) {
fprintf(file," None ");
} else {
fprintf(file,"%d", e->u.integer );
}
break;
case real_:
if( e == LITERAL_PI ) {
fprintf(file," PI ");
} else if( e == LITERAL_E ) {
fprintf(file," E ");;
} else {
fprintf(file, "%g", e->u.real );
}
break;
case binary_:
fprintf(file, "%%%s", e->u.binary ); /* put "%" back */
break;
case logical_:
case boolean_:
switch( e->u.logical ) {
case Ltrue:
fprintf(file,"TRUE");
break;
case Lfalse:
fprintf(file,"FALSE" );
break;
default:
fprintf(file,"UNKNOWN" );
break;
}
break;
case string_:
if( TYPEis_encoded( e->type ) ) {
fprintf(file, "\"%s\"", e->symbol.name );
} else {
fprintf(file, "'%s'", e->symbol.name );
}
break;
case entity_:
case identifier_:
fprintf(file, "self.%s", e->symbol.name );
break;
case attribute_:
fprintf(file, "%s", e->symbol.name );
break;
case enumeration_:
fprintf(file, "%s", e->symbol.name );
break;
case query_:
//fprintf(file, "QUERY ( %s <* ", e->u.query->local->name->symbol.name );
//EXPRESSION_out( e->u.query->aggregate, 1, files );
//fprintf(file, " | " );
//EXPRESSION_out( e->u.query->expression, 1 ,files);
//fprintf(file, " )" );
//break;
// so far we don't handle queries
fprintf(file, "None");
break;
case self_:
fprintf(file, "self" );
break;
case funcall_:
fprintf(file, "%s(", e->symbol.name );
i = 0;
LISTdo( e->u.funcall.list, arg, Expression )
i++;
if( i != 1 ) {
fprintf(file, "," );
}
ATTRIBUTE_INITIALIZER_out( arg, 0 ,file);
LISTod
fprintf(file, ")" );
break;
case op_:
ATTRIBUTE_INITIALIZERop__out( &e->e, paren, previous_op, file );
break;
case aggregate_:
fprintf(file,"[" );
i = 0;
LISTdo( e->u.list, arg, Expression )
i++;
if( i != 1 ) {
fprintf(file, "," );
}
ATTRIBUTE_INITIALIZER_out( arg, 0 , file);
LISTod
fprintf(file, "]" );
break;
case oneof_:
fprintf(file, "ONEOF (" );
i = 0;
LISTdo( e->u.list, arg, Expression )
i++;
if( i != 1 ) {
fprintf(file, "," );
}
ATTRIBUTE_INITIALIZER_out( arg, 0, file );
LISTod
fprintf(file, ")" );
break;
default:
fprintf(file, "unknown expression, type %d", TYPEis( e->type ) );
}
}
/*****************************************************************
** Procedure: EXPRESSION__out
@@ -1294,6 +1424,99 @@ EXPRESSION__out( Expression e, int paren, int previous_op , FILE *file) {
}
}
void
ATTRIBUTE_INITIALIZERop__out( struct Op_Subexpression * oe, int paren, int previous_op , FILE *file) {
switch( oe->op_code ) {
case OP_AND:
ATTRIBUTE_INITIALIZERop2_out( oe, " and ", paren, PAD, file );
break;
case OP_ANDOR:
case OP_OR:
ATTRIBUTE_INITIALIZERop2_out( oe, " or ", paren, PAD, file );
break;
case OP_CONCAT:
case OP_EQUAL:
ATTRIBUTE_INITIALIZERop2_out( oe, " == ", paren, PAD, file );
break;
case OP_PLUS:
ATTRIBUTE_INITIALIZERop2_out( oe, " + ", paren, PAD, file );
break;
case OP_TIMES:
ATTRIBUTE_INITIALIZERop2_out( oe, " * ", paren, PAD, file );
break;
case OP_XOR:
ATTRIBUTE_INITIALIZERop2__out( oe, ( char * )0, paren, PAD, previous_op, file );
break;
case OP_EXP:
ATTRIBUTE_INITIALIZERop2_out( oe, " ** ", paren, PAD, file );
break;
case OP_GREATER_EQUAL:
ATTRIBUTE_INITIALIZERop2_out( oe, " >= ", paren, PAD, file );
break;
case OP_GREATER_THAN:
ATTRIBUTE_INITIALIZERop2_out( oe, " > ", paren, PAD, file );
break;
case OP_IN:
// EXPRESSIONop2_out( oe, " in ", paren, PAD, file );
// break;
case OP_INST_EQUAL:
ATTRIBUTE_INITIALIZERop2_out( oe, " == ", paren, PAD, file);
break;
case OP_INST_NOT_EQUAL:
ATTRIBUTE_INITIALIZERop2_out( oe, " != ", paren, PAD, file );
break;
case OP_LESS_EQUAL:
ATTRIBUTE_INITIALIZERop2_out( oe, " <= ", paren, PAD, file );
break;
case OP_LESS_THAN:
ATTRIBUTE_INITIALIZERop2_out( oe, " < ", paren, PAD, file );
break;
case OP_LIKE:
case OP_MOD:
ATTRIBUTE_INITIALIZERop2_out( oe, " % ", paren, PAD, file );
break;
case OP_NOT_EQUAL:
//EXPRESSIONop2_out( oe, ( char * )0, paren, PAD ,file);
ATTRIBUTE_INITIALIZERop2_out( oe, " != ", paren, PAD ,file);
break;
case OP_NOT:
ATTRIBUTE_INITIALIZERop1_out( oe, " not ", paren, file );
break;
case OP_REAL_DIV:
case OP_DIV:
ATTRIBUTE_INITIALIZERop2_out( oe, "/", paren, PAD, file );
break;
case OP_MINUS:
ATTRIBUTE_INITIALIZERop2_out( oe, "-", paren, PAD, file );
break;
case OP_DOT:
ATTRIBUTE_INITIALIZERop2_out( oe, ".", paren, NOPAD, file );
break;
case OP_GROUP:
ATTRIBUTE_INITIALIZERop2_out( oe, ".", paren, NOPAD, file );
break;
case OP_NEGATE:
ATTRIBUTE_INITIALIZERop1_out( oe, "-", paren, file );
break;
case OP_ARRAY_ELEMENT:
ATTRIBUTE_INITIALIZER_out( oe->op1, 1, file );
fprintf(file, "[" );
ATTRIBUTE_INITIALIZER_out( oe->op2, 0, file );
fprintf(file, "]" );
break;
case OP_SUBCOMPONENT:
ATTRIBUTE_INITIALIZER_out( oe->op1, 1 , file);
fprintf(file, "[" );
ATTRIBUTE_INITIALIZER_out( oe->op2, 0, file );
fprintf(file, ":" );
ATTRIBUTE_INITIALIZER_out( oe->op3, 0, file );
fprintf(file, "]" );
break;
default:
fprintf(file, "(* unknown op-expression *)" );
}
}
/* print expression that has op and operands */
void
EXPRESSIONop__out( struct Op_Subexpression * oe, int paren, int previous_op , FILE *file) {
@@ -1407,6 +1630,25 @@ EXPRESSIONop2__out( struct Op_Subexpression * eo, char * opcode, int paren, int
}
}
void
ATTRIBUTE_INITIALIZERop2__out( struct Op_Subexpression * eo, char * opcode, int paren, int pad, int previous_op, FILE *file ) {
if( pad && paren && ( eo->op_code != previous_op ) ) {
fprintf(file,"(" );
}
ATTRIBUTE_INITIALIZER__out( eo->op1, 1, eo->op_code , file);
if( pad ) {
fprintf(file, " " );
}
fprintf(file, "%s", ( opcode ? opcode : EXPop_table[eo->op_code].token ) );
if( pad ) {
fprintf(file, " " );
}
ATTRIBUTE_INITIALIZER__out( eo->op2, 1, eo->op_code, file );
if( pad && paren && ( eo->op_code != previous_op ) ) {
fprintf(file, ")" );
}
}
/* Print out a one-operand operation. If there were more than two of these */
/* I'd generalize it to do padding, but it's not worth it. */
void
@@ -1421,6 +1663,18 @@ EXPRESSIONop1_out( struct Op_Subexpression * eo, char * opcode, int paren, FILE
}
}
void
ATTRIBUTE_INITIALIZERop1_out( struct Op_Subexpression * eo, char * opcode, int paren, FILE *file ) {
if( paren ) {
fprintf(file, "(" );
}
fprintf(file, "%s", opcode );
ATTRIBUTE_INITIALIZER_out( eo->op1, 1, file );
if( paren ) {
fprintf(file, ")" );
}
}
int
EXPRop_length( struct Op_Subexpression * oe ) {
switch( oe->op_code ) {
@@ -1455,7 +1709,8 @@ WHEREPrint( Linked_List wheres, int level , FILE *file ) {
fprintf(file, "\tdef unnamed_wr_%i(self):\n",where_rule_number);
fprintf(file,"\t\teval_unnamed_wr_%i = ",where_rule_number);
}
EXPRESSION_out( w->expr, level+1 , file );
//EXPRESSION_out( w->expr, level+1 , file );
ATTRIBUTE_INITIALIZER_out( w->expr, level+1 , file );
// raise exception if rule violated
if( strcmp(w->label->name,"<unnamed>") ) {
fprintf(file,"\n\t\tif not eval_%s_wr:\n",w->label->name);
@@ -382,6 +382,73 @@ class TestFunctions(unittest.TestCase):
self.assertEqual(case_1(INTEGER(5)),log(5.))
self.assertEqual(case_1(INTEGER(6)),0.)
class TestEntityWhereRules(unittest.TestCase):
'''
unitary/test_entity_where_rule
'''
def test_import_schema(self):
import test_entity_where_rule
def test_entity_unit_vector(self):
'''
ENTITY unit_vector;
a, b, c : REAL;
WHERE
length_1 : a**2 + b**2 + c**2 = 1.0;
END_ENTITY;
'''
from test_entity_where_rule import unit_vector
u = unit_vector(REAL(1),REAL(0),REAL(0))
self.assertTrue(u.length_1())
v = unit_vector(REAL(0),REAL(0),REAL(0.5))
def test_entity_address(self):
'''
TYPE label = STRING;
END_TYPE; -- label
ENTITY address;
internal_location : OPTIONAL label;
street_number : OPTIONAL label;
street : OPTIONAL label;
postal_box : OPTIONAL label;
town : OPTIONAL label;
region : OPTIONAL label;
postal_code : OPTIONAL label;
country : OPTIONAL label;
facsimile_number : OPTIONAL label;
telephone_number : OPTIONAL label;
electronic_mail_address : OPTIONAL label;
telex_number : OPTIONAL label;
WHERE
WR1: EXISTS(internal_location) OR
EXISTS(street_number) OR
EXISTS(street) OR
EXISTS(postal_box) OR
EXISTS(town) OR
EXISTS(region) OR
EXISTS(postal_code) OR
EXISTS(country) OR
EXISTS(facsimile_number) OR
EXISTS(telephone_number) OR
EXISTS(electronic_mail_address) OR
EXISTS(telex_number);
END_ENTITY; -- address
'''
from test_entity_where_rule import address, label
a = address(None,None,None,None,None,None,None,None,None,None,None,None)
# wr1 should raise an issue since a.wr1()
try:
a.wr1()
except AssertionError:
pass
except e:
self.fail('Unexpected exception thrown:', e)
else:
self.fail('ExpectedException not thrown')
a.town = label('Paris')
a.wr1()
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestSelectDataType))
@@ -390,6 +457,7 @@ def suite():
suite.addTest(unittest.makeSuite(TestEnumEntityName))
suite.addTest(unittest.makeSuite(TestDefinedTypesWhereRule))
suite.addTest(unittest.makeSuite(TestFunctions))
suite.addTest(unittest.makeSuite(TestEntityWhereRules))
return suite
if __name__ == '__main__':
@@ -0,0 +1,41 @@
SCHEMA test_entity_where_rule;
TYPE label = STRING;
END_TYPE; -- label
ENTITY address;
internal_location : OPTIONAL label;
street_number : OPTIONAL label;
street : OPTIONAL label;
postal_box : OPTIONAL label;
town : OPTIONAL label;
region : OPTIONAL label;
postal_code : OPTIONAL label;
country : OPTIONAL label;
facsimile_number : OPTIONAL label;
telephone_number : OPTIONAL label;
electronic_mail_address : OPTIONAL label;
telex_number : OPTIONAL label;
WHERE
WR1: EXISTS(internal_location) OR
EXISTS(street_number) OR
EXISTS(street) OR
EXISTS(postal_box) OR
EXISTS(town) OR
EXISTS(region) OR
EXISTS(postal_code) OR
EXISTS(country) OR
EXISTS(facsimile_number) OR
EXISTS(telephone_number) OR
EXISTS(electronic_mail_address) OR
EXISTS(telex_number);
END_ENTITY; -- address
ENTITY unit_vector;
a, b, c : REAL;
WHERE
length_1 : a**2 + b**2 + c**2 = 1.0;
END_ENTITY;
END_SCHEMA;