From 10999e7a48b5d5dd06e81222914e75a2294fe87a Mon Sep 17 00:00:00 2001 From: tpaviot Date: Sun, 8 Jan 2012 23:29:23 +0100 Subject: [PATCH 01/19] First draft for a SCL python generator --- CMakeLists.txt | 4 + include/express/type.h | 2 + src/fedex_python/CMakeLists.txt | 44 + src/fedex_python/REAMDE.md | 1 + .../generate_shemas_modules.py | 13 + .../unitary_schemas/index_attribute.py | 105 + .../examples/unitary_schemas/test_array.py | 33 + .../test_array_of_simple_types.py | 65 + .../unitary_schemas/test_derived_attribute.py | 185 + .../unitary_schemas/test_enum_entity_name.py | 14 + .../unitary_schemas/test_enums_same_name.py | 19 + .../test_multiple_inheritance.py | 456 ++ .../unitary_schemas/test_named_type.py | 35 + .../unitary_schemas/test_select_data_type.py | 215 + .../test_single_inheritance.py | 93 + .../test_single_inheritance_multi_level.py | 102 + .../python/SCL/AggregationDataType.py | 117 + .../python/SCL/ConstructedDataTypes.py | 67 + src/fedex_python/python/SCL/Expr.py | 71 + src/fedex_python/python/SCL/Part21.py | 203 + src/fedex_python/python/SCL/SCLBase.py | 44 + .../python/SCL/SimpleDataTypes.py | 186 + src/fedex_python/python/SCL/TypeChecker.py | 53 + src/fedex_python/python/SCL/__init__.py | 0 src/fedex_python/python/SCL_unittest.py | 166 + src/fedex_python/python/setup.py | 43 + src/fedex_python/src/classes_misc_python.c | 859 +++ src/fedex_python/src/classes_python.c | 4674 +++++++++++++++++ .../src/classes_wrapper_python.cc | 553 ++ src/fedex_python/src/fedex_main_python.c | 134 + src/fedex_python/src/multpass_python.c | 729 +++ src/fedex_python/src/selects_python.c | 1946 +++++++ 32 files changed, 11231 insertions(+) create mode 100644 src/fedex_python/CMakeLists.txt create mode 100644 src/fedex_python/REAMDE.md create mode 100644 src/fedex_python/examples/unitary_schemas/generate_shemas_modules.py create mode 100644 src/fedex_python/examples/unitary_schemas/index_attribute.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_array.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_derived_attribute.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_enums_same_name.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_named_type.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_select_data_type.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_single_inheritance.py create mode 100644 src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py create mode 100644 src/fedex_python/python/SCL/AggregationDataType.py create mode 100644 src/fedex_python/python/SCL/ConstructedDataTypes.py create mode 100644 src/fedex_python/python/SCL/Expr.py create mode 100644 src/fedex_python/python/SCL/Part21.py create mode 100644 src/fedex_python/python/SCL/SCLBase.py create mode 100644 src/fedex_python/python/SCL/SimpleDataTypes.py create mode 100644 src/fedex_python/python/SCL/TypeChecker.py create mode 100644 src/fedex_python/python/SCL/__init__.py create mode 100644 src/fedex_python/python/SCL_unittest.py create mode 100644 src/fedex_python/python/setup.py create mode 100644 src/fedex_python/src/classes_misc_python.c create mode 100644 src/fedex_python/src/classes_python.c create mode 100644 src/fedex_python/src/classes_wrapper_python.cc create mode 100644 src/fedex_python/src/fedex_main_python.c create mode 100644 src/fedex_python/src/multpass_python.c create mode 100644 src/fedex_python/src/selects_python.c diff --git a/CMakeLists.txt b/CMakeLists.txt index de07747ab..ddb5c681c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,9 @@ OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON) # build static libs by default OPTION(BUILD_STATIC_LIBS "Build static libraries" OFF) +OPTION(PYTHON_GENERATOR "Compile fedex_plus_python" ON) +OPTION(CPP_GENERATOR "Compile fedex_plus" ON) + # Set version SET(SCL_VERSION_MAJOR "3") SET(SCL_VERSION_MINOR "2") @@ -258,6 +261,7 @@ include_directories( ADD_SUBDIRECTORY(src/express) ADD_SUBDIRECTORY(src/exppp) ADD_SUBDIRECTORY(src/fedex_plus) +ADD_SUBDIRECTORY(src/fedex_python) ADD_SUBDIRECTORY(src/clstepcore) ADD_SUBDIRECTORY(src/cleditor) ADD_SUBDIRECTORY(src/cldai) diff --git a/include/express/type.h b/include/express/type.h index c399e13ae..f6bf3b11b 100644 --- a/include/express/type.h +++ b/include/express/type.h @@ -235,6 +235,8 @@ GLOBAL SCL_EXPRESS_EXPORT Error ERROR_corrupted_type INITIALLY( ERROR_none ); #define TYPEis_identifier(t) ((t)->u.type->body->type == identifier_) #define TYPEis_logical(t) ((t)->u.type->body->type == logical_) #define TYPEis_boolean(t) ((t)->u.type->body->type == boolean_) +#define TYPEis_real(t) ((t)->u.type->body->type == real_) +#define TYPEis_integer(t) ((t)->u.type->body->type == integer_) #define TYPEis_string(t) ((t)->u.type->body->type == string_) #define TYPEis_expression(t) ((t)->u.type->body->type == op_) #define TYPEis_oneof(t) ((t)->u.type->body->type == oneof_) diff --git a/src/fedex_python/CMakeLists.txt b/src/fedex_python/CMakeLists.txt new file mode 100644 index 000000000..a434ad25a --- /dev/null +++ b/src/fedex_python/CMakeLists.txt @@ -0,0 +1,44 @@ +if(PYTHON_GENERATOR) + +include_directories( + ${SCL_SOURCE_DIR}/include + ${SCL_SOURCE_DIR}/include/exppp + ${SCL_SOURCE_DIR}/include/express + ${SCL_SOURCE_DIR}/src/fedex_plus +) + +add_definitions( -DHAVE_CONFIG_H ) + +IF(MSVC) +set(fedex_plus_MSVC_SOURCES + ${SCL_SOURCE_DIR}/src/fedex_plus/xgetopt.cc +) +add_definitions( -DSCL_EXPRESS_DLL_IMPORTS ) +add_definitions( -DSCL_EXPPP_DLL_IMPORTS ) +ENDIF(MSVC) + +set(fedex_python_SOURCES + src/classes_misc_python.c + ${SCL_SOURCE_DIR}/src/express/fedex.c + src/fedex_main_python.c + src/classes_wrapper_python.cc + src/classes_python.c + src/selects_python.c + src/multpass_python.c + ${SCL_SOURCE_DIR}/src/fedex_plus/collect.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/complexlist.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/entlist.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/multlist.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/orlist.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/entnode.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/expressbuild.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/non-ors.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/match-ors.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/trynext.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/write.cc + ${SCL_SOURCE_DIR}/src/fedex_plus/print.cc +) +SCL_ADDEXEC(fedex_python "${fedex_python_SOURCES} ${fedex_plus_MSVC_SOURCES}" "libexppp express") + +add_dependencies( fedex_python version_string ) +endif(PYTHON_GENERATOR) diff --git a/src/fedex_python/REAMDE.md b/src/fedex_python/REAMDE.md new file mode 100644 index 000000000..64e7179c7 --- /dev/null +++ b/src/fedex_python/REAMDE.md @@ -0,0 +1 @@ +Howto diff --git a/src/fedex_python/examples/unitary_schemas/generate_shemas_modules.py b/src/fedex_python/examples/unitary_schemas/generate_shemas_modules.py new file mode 100644 index 000000000..86f6b3b51 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/generate_shemas_modules.py @@ -0,0 +1,13 @@ +__doc__= ''' This script runs fedex_python over each EXPRESS schema in the test/unitary_schemas folder''' + +unitary_schemas_path = '../../../../test/unitary_schemas' +fedex_python_path = '../../../../cmake-build/bin/fedex_python' + +import subprocess +import glob +import os + +unitary_schemas = glob.glob(os.path.join(unitary_schemas_path,'*.exp')) + +for unitary_schema in unitary_schemas: + subprocess.call([fedex_python_path,unitary_schema]) \ No newline at end of file diff --git a/src/fedex_python/examples/unitary_schemas/index_attribute.py b/src/fedex_python/examples/unitary_schemas/index_attribute.py new file mode 100644 index 000000000..4982859ff --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/index_attribute.py @@ -0,0 +1,105 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +common_datum_list = 'LIST TYPE Not implemented' +label = STRING + +#################### + # ENTITY shape_aspect # +#################### +class shape_aspect(BaseEntityClass): + '''Entity shape_aspect definition. + + :param name + :type name:STRING + + :param of_shape + :type of_shape:product_definition_shape + ''' + def __init__( self , name,of_shape, ): + self.name = name + self.of_shape = of_shape + + @apply + def name(): + def fget( self ): + return self._name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument name is mantatory and can not be set to None') + check_type(value,STRING) + self._name = value + return property(**locals()) + + @apply + def of_shape(): + def fget( self ): + return self._of_shape + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument of_shape is mantatory and can not be set to None') + check_type(value,product_definition_shape) + self._of_shape = value + return property(**locals()) + +#################### + # ENTITY general_datum_reference # +#################### +class general_datum_reference(shape_aspect): + '''Entity general_datum_reference definition. + + :param base + :type base:datum_or_common_datum + ''' + def __init__( self , shape_aspect__name , shape_aspect__of_shape , base, ): + shape_aspect.__init__(self , shape_aspect__name , shape_aspect__of_shape , ) + self.base = base + + @apply + def base(): + def fget( self ): + return self._base + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument base is mantatory and can not be set to None') + check_type(value,datum_or_common_datum) + self._base = value + return property(**locals()) + +#################### + # ENTITY product_definition_shape # +#################### +class product_definition_shape(BaseEntityClass): + '''Entity product_definition_shape definition. + ''' + # This class does not define any attribute. + pass + +#################### + # ENTITY datum_reference_element # +#################### +class datum_reference_element(general_datum_reference): + '''Entity datum_reference_element definition. + ''' + def __init__( self , general_datum_reference__base , ): + general_datum_reference.__init__(self , general_datum_reference__base , ) + +#################### + # ENTITY datum # +#################### +class datum(shape_aspect): + '''Entity datum definition. + ''' + def __init__( self , shape_aspect__name , shape_aspect__of_shape , ): + shape_aspect.__init__(self , shape_aspect__name , shape_aspect__of_shape , ) +# SELECT TYPE datum_or_common_datum +datum_or_common_datum=SELECT([common_datum_list,datum]) diff --git a/src/fedex_python/examples/unitary_schemas/test_array.py b/src/fedex_python/examples/unitary_schemas/test_array.py new file mode 100644 index 000000000..3f85ef484 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_array.py @@ -0,0 +1,33 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * + +#################### + # ENTITY point # +#################### +class point(BaseEntityClass): + '''Entity point definition. + + :param coords + :type coords:(null) + ''' + def __init__( self , coords, ): + self.coords = coords + + @apply + def coords(): + def fget( self ): + return self._coords + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument coords is mantatory and can not be set to None') + check_type(value,ARRAY(1,3,REAL)) + self._coords = value + return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py b/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py new file mode 100644 index 000000000..e34d9600a --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py @@ -0,0 +1,65 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * + +#################### + # ENTITY point # +#################### +class point(BaseEntityClass): + '''Entity point definition. + + :param arr_real + :type arr_real:(null) + + :param arr_string + :type arr_string:(null) + + :param arr_integer + :type arr_integer:(null) + ''' + def __init__( self , arr_real,arr_string,arr_integer, ): + self.arr_real = arr_real + self.arr_string = arr_string + self.arr_integer = arr_integer + + @apply + def arr_real(): + def fget( self ): + return self._arr_real + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument arr_real is mantatory and can not be set to None') + check_type(value,ARRAY(1,3,REAL)) + self._arr_real = value + return property(**locals()) + + @apply + def arr_string(): + def fget( self ): + return self._arr_string + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument arr_string is mantatory and can not be set to None') + check_type(value,ARRAY(1,3,STRING)) + self._arr_string = value + return property(**locals()) + + @apply + def arr_integer(): + def fget( self ): + return self._arr_integer + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument arr_integer is mantatory and can not be set to None') + check_type(value,ARRAY(1,None,INTEGER)) + self._arr_integer = value + return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py b/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py new file mode 100644 index 000000000..69723d30c --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py @@ -0,0 +1,185 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * + +#################### + # ENTITY vector # +#################### +class vector(BaseEntityClass): + '''Entity vector definition. + + :param x + :type x:REAL + + :param y + :type y:REAL + ''' + def __init__( self , x,y, ): + self.x = x + self.y = y + + @apply + def x(): + def fget( self ): + return self._x + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument x is mantatory and can not be set to None') + check_type(value,REAL) + self._x = value + return property(**locals()) + + @apply + def y(): + def fget( self ): + return self._y + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument y is mantatory and can not be set to None') + check_type(value,REAL) + self._y = value + return property(**locals()) + +#################### + # ENTITY circle # +#################### +class circle(BaseEntityClass): + '''Entity circle definition. + + :param centre + :type centre:point + + :param radius + :type radius:REAL + + :param axis + :type axis:vector + + :param area + :type area:REAL + + :param perimeter + :type perimeter:REAL + ''' + def __init__( self , centre,radius,axis, ): + self.centre = centre + self.radius = radius + self.axis = axis + + @apply + def centre(): + def fget( self ): + return self._centre + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument centre is mantatory and can not be set to None') + check_type(value,point) + self._centre = value + return property(**locals()) + + @apply + def radius(): + def fget( self ): + return self._radius + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument radius is mantatory and can not be set to None') + check_type(value,REAL) + self._radius = value + return property(**locals()) + + @apply + def axis(): + def fget( self ): + return self._axis + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument axis is mantatory and can not be set to None') + check_type(value,vector) + self._axis = value + return property(**locals()) + + @apply + def area(): + def fget( self ): + return EvalDerivedAttribute(self,'''PI * (radius ** 2)''') + def fset( self, value ): + # DERIVED argument + raise AssertionError('Argument area is DERIVED. It is computed and can not be set to any value') + return property(**locals()) + + @apply + def perimeter(): + def fget( self ): + return EvalDerivedAttribute(self,'''2 * PI * radius''') + def fset( self, value ): + # DERIVED argument + raise AssertionError('Argument perimeter is DERIVED. It is computed and can not be set to any value') + return property(**locals()) + +#################### + # ENTITY point # +#################### +class point(BaseEntityClass): + '''Entity point definition. + + :param x + :type x:REAL + + :param y + :type y:REAL + + :param z + :type z:REAL + ''' + def __init__( self , x,y,z, ): + self.x = x + self.y = y + self.z = z + + @apply + def x(): + def fget( self ): + return self._x + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument x is mantatory and can not be set to None') + check_type(value,REAL) + self._x = value + return property(**locals()) + + @apply + def y(): + def fget( self ): + return self._y + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument y is mantatory and can not be set to None') + check_type(value,REAL) + self._y = value + return property(**locals()) + + @apply + def z(): + def fget( self ): + return self._z + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument z is mantatory and can not be set to None') + check_type(value,REAL) + self._z = value + return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py b/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py new file mode 100644 index 000000000..96aee837a --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py @@ -0,0 +1,14 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +# ENUMERATION TYPE simple_datum_reference_modifier +simple_datum_reference_modifier = ENUMERATION([ + 'line', + 'translation', + ]) diff --git a/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py b/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py new file mode 100644 index 000000000..41a5112a0 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py @@ -0,0 +1,19 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +# ENUMERATION TYPE hair_color +hair_color = ENUMERATION([ + 'bald', + 'red', + ]) +# ENUMERATION TYPE favorite_color +favorite_color = ENUMERATION([ + 'clear', + 'red', + ]) diff --git a/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py b/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py new file mode 100644 index 000000000..784c2539f --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py @@ -0,0 +1,456 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +text = STRING +identifier = STRING +label = STRING + +#################### + # ENTITY address # +#################### +class address(BaseEntityClass): + '''Entity address definition. + + :param internal_location + :type internal_location:STRING + + :param street_number + :type street_number:STRING + + :param street + :type street:STRING + + :param postal_box + :type postal_box:STRING + + :param town + :type town:STRING + + :param region + :type region:STRING + + :param postal_code + :type postal_code:STRING + + :param country + :type country:STRING + + :param facsimile_number + :type facsimile_number:STRING + + :param telephone_number + :type telephone_number:STRING + + :param electronic_mail_address + :type electronic_mail_address:STRING + + :param telex_number + :type telex_number:STRING + ''' + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + self._town = value + return property(**locals()) + + @apply + def region(): + def fget( self ): + return self._region + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + 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 + check_type(value,STRING) + self._telex_number = value + return property(**locals()) + +#################### + # ENTITY personal_address # +#################### +class personal_address(address): + '''Entity personal_address definition. + + :param people + :type people:(null) + + :param description + :type description:STRING + ''' + def __init__( self , address__internal_location , address__street_number , address__street , address__postal_box , address__town , address__region , address__postal_code , address__country , address__facsimile_number , address__telephone_number , address__electronic_mail_address , address__telex_number , people,description, ): + address.__init__(self , address__internal_location , address__street_number , address__street , address__postal_box , address__town , address__region , address__postal_code , address__country , address__facsimile_number , address__telephone_number , address__electronic_mail_address , address__telex_number , ) + self.people = people + self.description = description + + @apply + def people(): + def fget( self ): + return self._people + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument people is mantatory and can not be set to None') + check_type(value,SET(1,None,person)) + self._people = value + return property(**locals()) + + @apply + def description(): + def fget( self ): + return self._description + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + self._description = value + return property(**locals()) + +#################### + # ENTITY organizational_address # +#################### +class organizational_address(address): + '''Entity organizational_address definition. + + :param organizations + :type organizations:(null) + + :param description + :type description:STRING + ''' + def __init__( self , address__internal_location , address__street_number , address__street , address__postal_box , address__town , address__region , address__postal_code , address__country , address__facsimile_number , address__telephone_number , address__electronic_mail_address , address__telex_number , organizations,description, ): + address.__init__(self , address__internal_location , address__street_number , address__street , address__postal_box , address__town , address__region , address__postal_code , address__country , address__facsimile_number , address__telephone_number , address__electronic_mail_address , address__telex_number , ) + self.organizations = organizations + self.description = description + + @apply + def organizations(): + def fget( self ): + return self._organizations + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument organizations is mantatory and can not be set to None') + check_type(value,SET(1,None,organization)) + self._organizations = value + return property(**locals()) + + @apply + def description(): + def fget( self ): + return self._description + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + self._description = value + return property(**locals()) + +#################### + # ENTITY person # +#################### +class person(BaseEntityClass): + '''Entity person definition. + + :param id + :type id:STRING + + :param last_name + :type last_name:STRING + + :param first_name + :type first_name:STRING + + :param middle_names + :type middle_names:(null) + + :param prefix_titles + :type prefix_titles:(null) + + :param suffix_titles + :type suffix_titles:(null) + ''' + def __init__( self , id,last_name,first_name,middle_names,prefix_titles,suffix_titles, ): + self.id = id + self.last_name = last_name + self.first_name = first_name + self.middle_names = middle_names + self.prefix_titles = prefix_titles + self.suffix_titles = suffix_titles + + @apply + def id(): + def fget( self ): + return self._id + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument id is mantatory and can not be set to None') + check_type(value,STRING) + self._id = value + return property(**locals()) + + @apply + def last_name(): + def fget( self ): + return self._last_name + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + self._last_name = value + return property(**locals()) + + @apply + def first_name(): + def fget( self ): + return self._first_name + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + self._first_name = value + return property(**locals()) + + @apply + def middle_names(): + def fget( self ): + return self._middle_names + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,LIST(1,None,STRING)) + self._middle_names = value + return property(**locals()) + + @apply + def prefix_titles(): + def fget( self ): + return self._prefix_titles + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,LIST(1,None,STRING)) + self._prefix_titles = value + return property(**locals()) + + @apply + def suffix_titles(): + def fget( self ): + return self._suffix_titles + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,LIST(1,None,STRING)) + self._suffix_titles = value + return property(**locals()) + +#################### + # ENTITY organization # +#################### +class organization(BaseEntityClass): + '''Entity organization definition. + + :param id + :type id:STRING + + :param name + :type name:STRING + + :param description + :type description:STRING + ''' + def __init__( self , id,name,description, ): + self.id = id + self.name = name + self.description = description + + @apply + def id(): + def fget( self ): + return self._id + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + self._id = value + return property(**locals()) + + @apply + def name(): + def fget( self ): + return self._name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument name is mantatory and can not be set to None') + check_type(value,STRING) + self._name = value + return property(**locals()) + + @apply + def description(): + def fget( self ): + return self._description + def fset( self, value ): + if value != None: # OPTIONAL attribute + check_type(value,STRING) + self._description = value + return property(**locals()) + +#################### + # ENTITY person_and_organization_address # +#################### +class person_and_organization_address(organizational_address,personal_address): + '''Entity person_and_organization_address definition. + + :param organizational_address_organizations + :type organizational_address_organizations:(null) + + :param personal_address_people + :type personal_address_people:(null) + ''' + def __init__( self , organizational_address__organizations , organizational_address__description , personal_address__people , personal_address__description , organizational_address_organizations,personal_address_people, ): + organizational_address.__init__(self , organizational_address__organizations , organizational_address__description , ) + personal_address.__init__(self , personal_address__people , personal_address__description , ) + self.organizational_address_organizations = organizational_address_organizations + self.personal_address_people = personal_address_people + + @apply + def organizational_address_organizations(): + def fget( self ): + return self._organizational_address_organizations + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument organizational_address_organizations is mantatory and can not be set to None') + check_type(value,SET(1,1,organization)) + self._organizational_address_organizations = value + return property(**locals()) + + @apply + def personal_address_people(): + def fget( self ): + return self._personal_address_people + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument personal_address_people is mantatory and can not be set to None') + check_type(value,SET(1,1,person)) + self._personal_address_people = value + return property(**locals()) +# SELECT TYPE classification_item +classification_item=SELECT([person_and_organization_address,address]) diff --git a/src/fedex_python/examples/unitary_schemas/test_named_type.py b/src/fedex_python/examples/unitary_schemas/test_named_type.py new file mode 100644 index 000000000..f8dced66c --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_named_type.py @@ -0,0 +1,35 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +measure = REAL +type2 = INTEGER + +#################### + # ENTITY line # +#################### +class line(BaseEntityClass): + '''Entity line definition. + + :param line_length + :type line_length:REAL + ''' + def __init__( self , line_length, ): + self.line_length = line_length + + @apply + def line_length(): + def fget( self ): + return self._line_length + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument line_length is mantatory and can not be set to None') + check_type(value,REAL) + self._line_length = value + return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_select_data_type.py b/src/fedex_python/examples/unitary_schemas/test_select_data_type.py new file mode 100644 index 000000000..95de3b070 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_select_data_type.py @@ -0,0 +1,215 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * + +#################### + # ENTITY weld # +#################### +class weld(BaseEntityClass): + '''Entity weld definition. + + :param composition + :type composition:STRING + ''' + def __init__( self , composition, ): + self.composition = composition + + @apply + def composition(): + def fget( self ): + return self._composition + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument composition is mantatory and can not be set to None') + check_type(value,STRING) + self._composition = value + return property(**locals()) + +#################### + # ENTITY glue # +#################### +class glue(BaseEntityClass): + '''Entity glue definition. + + :param composition + :type composition:STRING + + :param solvent + :type solvent:STRING + ''' + def __init__( self , composition,solvent, ): + self.composition = composition + self.solvent = solvent + + @apply + def composition(): + def fget( self ): + return self._composition + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument composition is mantatory and can not be set to None') + check_type(value,STRING) + self._composition = value + return property(**locals()) + + @apply + def solvent(): + def fget( self ): + return self._solvent + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument solvent is mantatory and can not be set to None') + check_type(value,STRING) + self._solvent = value + return property(**locals()) + +#################### + # ENTITY wall_mounting # +#################### +class wall_mounting(BaseEntityClass): + '''Entity wall_mounting definition. + + :param mounting + :type mounting:STRING + + :param on + :type on:STRING + + :param using + :type using:attachment_method + ''' + def __init__( self , mounting,on,using, ): + self.mounting = mounting + self.on = on + self.using = using + + @apply + def mounting(): + def fget( self ): + return self._mounting + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument mounting is mantatory and can not be set to None') + check_type(value,STRING) + self._mounting = value + return property(**locals()) + + @apply + def on(): + def fget( self ): + return self._on + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument on is mantatory and can not be set to None') + check_type(value,STRING) + self._on = value + return property(**locals()) + + @apply + def using(): + def fget( self ): + return self._using + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument using is mantatory and can not be set to None') + check_type(value,attachment_method) + self._using = value + return property(**locals()) + +#################### + # ENTITY screw # +#################### +class screw(BaseEntityClass): + '''Entity screw definition. + + :param body_length + :type body_length:REAL + + :param pitch + :type pitch:REAL + ''' + def __init__( self , body_length,pitch, ): + self.body_length = body_length + self.pitch = pitch + + @apply + def body_length(): + def fget( self ): + return self._body_length + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument body_length is mantatory and can not be set to None') + check_type(value,REAL) + self._body_length = value + return property(**locals()) + + @apply + def pitch(): + def fget( self ): + return self._pitch + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument pitch is mantatory and can not be set to None') + check_type(value,REAL) + self._pitch = value + return property(**locals()) + +#################### + # ENTITY nail # +#################### +class nail(BaseEntityClass): + '''Entity nail definition. + + :param body_length + :type body_length:REAL + + :param head_area + :type head_area:REAL + ''' + def __init__( self , body_length,head_area, ): + self.body_length = body_length + self.head_area = head_area + + @apply + def body_length(): + def fget( self ): + return self._body_length + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument body_length is mantatory and can not be set to None') + check_type(value,REAL) + self._body_length = value + return property(**locals()) + + @apply + def head_area(): + def fget( self ): + return self._head_area + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument head_area is mantatory and can not be set to None') + check_type(value,REAL) + self._head_area = value + return property(**locals()) +# SELECT TYPE permanent_attachment +permanent_attachment=SELECT([glue,weld]) +# SELECT TYPE temporary_attachment +temporary_attachment=SELECT([nail,screw]) +# SELECT TYPE attachment_method +attachment_method=SELECT([permanent_attachment,temporary_attachment]) diff --git a/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py b/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py new file mode 100644 index 000000000..7a9d6ac53 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py @@ -0,0 +1,93 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +length_measure = REAL +label = STRING +point = REAL + +#################### + # ENTITY shape # +#################### +class shape(BaseEntityClass): + '''Entity shape definition. + + :param item_name + :type item_name:STRING + + :param number_of_sides + :type number_of_sides:INTEGER + ''' + def __init__( self , item_name,number_of_sides, ): + self.item_name = item_name + self.number_of_sides = number_of_sides + + @apply + def item_name(): + def fget( self ): + return self._item_name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument item_name is mantatory and can not be set to None') + check_type(value,STRING) + self._item_name = value + return property(**locals()) + + @apply + def number_of_sides(): + def fget( self ): + return self._number_of_sides + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument number_of_sides is mantatory and can not be set to None') + check_type(value,INTEGER) + self._number_of_sides = value + return property(**locals()) + +#################### + # ENTITY rectangle # +#################### +class rectangle(shape): + '''Entity rectangle definition. + + :param height + :type height:REAL + + :param width + :type width:REAL + ''' + def __init__( self , shape__item_name , shape__number_of_sides , height,width, ): + shape.__init__(self , shape__item_name , shape__number_of_sides , ) + self.height = height + self.width = width + + @apply + def height(): + def fget( self ): + return self._height + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument height is mantatory and can not be set to None') + check_type(value,REAL) + self._height = value + return property(**locals()) + + @apply + def width(): + def fget( self ): + return self._width + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument width is mantatory and can not be set to None') + check_type(value,REAL) + self._width = value + return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py b/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py new file mode 100644 index 000000000..9113d4cbf --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py @@ -0,0 +1,102 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataType import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +length_measure = REAL +label = STRING +point = REAL + +#################### + # ENTITY shape # +#################### +class shape(BaseEntityClass): + '''Entity shape definition. + + :param item_name + :type item_name:STRING + + :param number_of_sides + :type number_of_sides:INTEGER + ''' + def __init__( self , item_name,number_of_sides, ): + self.item_name = item_name + self.number_of_sides = number_of_sides + + @apply + def item_name(): + def fget( self ): + return self._item_name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument item_name is mantatory and can not be set to None') + check_type(value,STRING) + self._item_name = value + return property(**locals()) + + @apply + def number_of_sides(): + def fget( self ): + return self._number_of_sides + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument number_of_sides is mantatory and can not be set to None') + check_type(value,INTEGER) + self._number_of_sides = value + return property(**locals()) + +#################### + # ENTITY subshape # +#################### +class subshape(shape): + '''Entity subshape definition. + ''' + def __init__( self , shape__item_name , shape__number_of_sides , ): + shape.__init__(self , shape__item_name , shape__number_of_sides , ) + +#################### + # ENTITY rectangle # +#################### +class rectangle(subshape): + '''Entity rectangle definition. + + :param height + :type height:REAL + + :param width + :type width:REAL + ''' + def __init__( self , height,width, ): + subshape.__init__(self , ) + self.height = height + self.width = width + + @apply + def height(): + def fget( self ): + return self._height + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument height is mantatory and can not be set to None') + check_type(value,REAL) + self._height = value + return property(**locals()) + + @apply + def width(): + def fget( self ): + return self._width + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument width is mantatory and can not be set to None') + check_type(value,REAL) + self._width = value + return property(**locals()) diff --git a/src/fedex_python/python/SCL/AggregationDataType.py b/src/fedex_python/python/SCL/AggregationDataType.py new file mode 100644 index 000000000..b36a95b54 --- /dev/null +++ b/src/fedex_python/python/SCL/AggregationDataType.py @@ -0,0 +1,117 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from SimpleDataTypes import * + +class BaseAggregate(object): + """ A class that define common properties to ARRAY, LIST, SET and BAG. + """ + def __init__( self , bound1 , bound2 , base_type ): + # init base list with an empty list + list.__init__(self,[]) + # check that bound1bound2: + raise AssertionError("bound1 shall be less than or equal to bound2") + self._bound1 = bound1 + self._bound2 = bound2 + self._base_type = base_type + print base_type + + def __getitem__(self, index): + if indexself._bound2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) + else: + return list.__getitem__(self,index) + + def __setitem__(self,index,value): + if indexself._bound2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) + elif not isinstance(value,self._base_type): + raise TypeError("%s type expected, passed %s."%(self._base_type, type(value))) + else: + # first find the length of the list, and extend it if ever + # the index is + list.__setitem__(self,index,value) + +class ARRAY(list, BaseAggregate): + """An array data type has as its domain indexed, fixed-size collections of like elements. The lower + and upper bounds, which are integer-valued expressions, define the range of index values, and + thus the size of each array collection. + An array data type definition may optionally specify + that an array value cannot contain duplicate elements. + It may also specify that an array value + need not contain an element at every index position. + """ + def __init__( self , bound1 , bound2 , base_type ): + BaseAggregate.__init__( self , bound1 , bound2 , base_type ) + +class LIST(list, BaseAggregate): + """A list data type has as its domain sequences of like elements. The optional lower and upper + bounds, which are integer-valued expressions, dfine the minimum and maximum number of + elements that can be held in the collection defined by a list data type. + A list data type + definition may optionally specify that a list value cannot contain duplicate elements. + """ + def __init__( self , bound1 , bound2 , base_type ): + BaseAggregate.__init__( self , bound1 , bound2 , base_type ) + +class BAG(tuple, BaseAggregate): + """A bag data type has as its domain unordered collections of like elements. The optional lower + and upper bounds, which are integer-valued expressions, de ne the minimum and maximum + number of elements that can be held in the collection de ned by a bag data type. + """ + def __init__( self , bound1 , bound2 , base_type ): + BaseAggregate.__init__( self , bound1 , bound2 , base_type ) + +class SET(set, BaseAggregate): + """A set data type has as its domain unordered collections of like elements. The set data type is + a specialization of the bag data type. The optional lower and upper bounds, which are integer- + valued expressions, de ne the minimum and maximum number of elements that can be held in + the collection de ned by a set data type. The collection de ned by set data type shall not + contain two or more elements which are instance equal. + """ + def __init__( self , bound1 , bound2 , base_type ): + BaseAggregate.__init__( self , bound1 , bound2 , base_type ) + +if __name__=='__main__': + # test ARRAY + a = ARRAY(1,3,REAL) + a[1] = REAL(3.) + a[2] = REAL(-1.5) + a[3] = REAL(4.) + print a + + diff --git a/src/fedex_python/python/SCL/ConstructedDataTypes.py b/src/fedex_python/python/SCL/ConstructedDataTypes.py new file mode 100644 index 000000000..18cdfbbdf --- /dev/null +++ b/src/fedex_python/python/SCL/ConstructedDataTypes.py @@ -0,0 +1,67 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +class ENUMERATION(list): + """ An ENUMERATION data type has as its domain an ordered set of names. The names represent + values of the enumeration data type. + """ + def __getattr__(self,attr_name): + if attr_name in self: + return attr_name + else: + raise AttributeError("This ENUMERATION has no element '%s'"%attr_name) + +class SELECT(list): + """ A select data type has as its domain the union of the domains of the named data types in + its select list. The select data type is a generalization of each of the named data types in its + select list. + """ + def get_aggregated_allowed_types(self): + """ This method returns a list of all types that are handle by this SELECT. + A SELECT can actually be an aggregate of many SELECTs""" + agg = [] + for allowed_type in self: + if isinstance(allowed_type,SELECT): + # in this case, we should recurse the select to get all subtypes + b = allowed_type.get_aggregated_allowed_types() + for elem in b: + agg.append(elem) + else: + agg.append(allowed_type) + return agg + +if __name__=='__main__': + a = SELECT([1,2]) + b = SELECT([3,4]) + c = SELECT([a,b]) + print a.get_aggregated_allowed_types() + print c.get_aggregated_allowed_types() + \ No newline at end of file diff --git a/src/fedex_python/python/SCL/Expr.py b/src/fedex_python/python/SCL/Expr.py new file mode 100644 index 000000000..685743af0 --- /dev/null +++ b/src/fedex_python/python/SCL/Expr.py @@ -0,0 +1,71 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from math import * +PI = pi #in EXPRESS, PI is uppercase + +def EvalDerivedAttribute(class_instance, str_expr): + ''' + This functions tries to evaluate EXPRESS math expr. + For instance in the following example: + == + ENTITY circle; + centre : point; + radius : REAL; + axis : vector; + DERIVE + area : REAL := PI*radius**2; + perimeter : REAL := 2.0*PI*radius; + + END_ENTITY; + == + The following string should be passed to EvalExpr: + 'PI*radius**2' + ''' + # first, try to find class paramters + # in the previous example, we should replace radius with self.radius before eval'ing expr + props = [] + for prop in dir(class_instance): + if not prop.startswith("_"): #means prop is an item that might be considered + props.append(prop) + for item in props: + str_expr = str_expr.replace(item,"class_instance.%s"%item) + # after that step, the expression should be: + # PI*class_instance.radiüs*class_instance.radius + # this can be evaluated with the eval function + # CAREFUL: eval is known to be unsafe. This should be changed in the future + # (using a parser, or simpy for instance) + try: + return eval(str_expr.lower()) + except: + print 'Error evaluating expression' + return None + diff --git a/src/fedex_python/python/SCL/Part21.py b/src/fedex_python/python/SCL/Part21.py new file mode 100644 index 000000000..75a5fdcb2 --- /dev/null +++ b/src/fedex_python/python/SCL/Part21.py @@ -0,0 +1,203 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import re + +INSTANCE_DEFINITION_RE = re.compile("#(\d+)[^\S\n]?=[^\S\n]?(.*?)\((.*)\)[^\S\n]?;[\\r]?$") + +def map_string_to_num(stri): + """ Take a string, check wether it is an integer, a float or not + """ + if ('.' in stri) or ('E' in stri): #it's definitely a float + return REAL(stri) + else: + return INTEGER(stri) + +class Model: + """ + A model contains a list of instances + """ + def __init__(self,name): + self._name = name + # a dict of instances + # each time an instance is added to the model, count is incremented + self._instances = {} + self._number_of_instances = 0 + + def add_instance(self, instance): + ''' + Adds an instance to the model + ''' + self._number_of_instances += 1 + self._instances[self._number_of_instances-1] = instance + + def print_instances(self): + ''' + Dump instances to stdout + ''' + for idx in range(self._number_of_instances): + "==========" + print "Instance #%i"%(idx+1) + print self._instances[idx] + +class Part21Loader: + """ + Loads all instances definition of a Part21 file into memory. + Two dicts are created: + self._instance_definition : stores attibutes, key is the instance integer id + self._number_of_ancestors : stores the number of ancestors of entity id. This enables + to define the order of instances creation. + """ + def __init__(self, filename): + self._filename = filename + # the schema + self._schema = "" + # the dict self._instances contain instance definition + self._instances_definition = {} + # this dict contains lists of 0 ancestors, 1 ancestor, etc. + # initializes this dict + self._number_of_ancestors = {} + for i in range(2000): + self._number_of_ancestors[i]=[] + print "Parsing file %s..."%filename, + self.parse_file() + print "done." + # reduce number_of_ancestors dict + for item in self._number_of_ancestors.keys(): + if len(self._number_of_ancestors[item])==0: + del self._number_of_ancestors[item] + + def get_schema(self): + return self._schema + + def get_number_of_instances(self): + return len(self._instances_definition.keys()) + + def parse_file(self): + fp = open(self._filename) + for line in fp: + # parse line + match_instance_definition = INSTANCE_DEFINITION_RE.search(line) # id,name,attrs + if match_instance_definition: + instance_id, entity_name, entity_attrs = match_instance_definition.groups() + instance_int_id = int(instance_id) + # find number of ancestors + number_of_ancestors = entity_attrs.count('#') + # fill number of ancestors dict + self._number_of_ancestors[number_of_ancestors].append(instance_int_id) + self._instances_definition[instance_int_id] = [entity_name,entity_attrs] + else: #does not match with entity instance definition, parse the header + if line.startswith('FILE_SCHEMA'): + #identify the schema name + self._schema = line.split("'")[1].split("'")[0].split(" ")[0].lower() + fp.close() + +class Part21Population(object): + def __init__(self, part21_loader): + """ Take a part21_loader a tries to create entities + """ + self._part21_loader = part21_loader + self._aggregate_scope = [] + self._aggr_scope = False + + def create_entity_instances(self): + """ Starts entity instances creation + """ + for number_of_ancestor in self._part21_loader._number_of_ancestors.keys(): + for entity_definition_id in self._part21_loader._number_of_ancestors[number_of_ancestor]: + self.create_entity_instance(entity_definition_id) + + def create_entity_instance(self, instance_id): + instance_definition = self._part21_loader._instances_definition[instance_id] + # first find class name + class_name = instance_definition[0].lower() + object_ = globals()[class_name] + # then attributes + #print object_.__doc__ + instance_attributes = instance_definition[1] + #print instance_attributes + # find attributes + attributes = instance_attributes.split(",") + instance_attributes = [] + #print attributes + for attr in attributes: + if attr[0]=="(":#new aggregate_scope + #print "new aggregate scope" + self._aggr_scope = True + at = self.map_express_to_python(attr[1:]) + #self._aggregate_scope.append(at) + elif attr[-1]==")": + #print "end aggregate scope" + at = self.map_express_to_python(attr[:-1]) + self._aggregate_scope.append(at) + self._aggr_scope = False + else: + at = self.map_express_to_python(attr) + if self._aggr_scope: + self._aggregate_scope.append(at) + if len(self._aggregate_scope)>0 and not self._aggr_scope: + instance_attributes.append(self._aggregate_scope) + self._aggregate_scope = [] + elif len(self._aggregate_scope)>0 and self._aggr_scope: + pass + else: + instance_attributes.append(at) + a = object_(*instance_attributes) + + + def map_express_to_python(self,attr): + """ Map EXPRESS to python""" + if attr in ["$","''"]: #optional argument + return None + elif attr.startswith('#'): #entity_id + return attr[1:] + else: + return map_string_to_num(attr) + +if __name__ == "__main__": + import time + import sys + sys.path.append("..") + from config_control_design import * + t1 = time.time() + print "Loading file into memory" + #file = Part21Loader("as1-oc-214.stp") + #file = Part21Loader("as1-tu-203.stp") + #file = Part21Loader("HAYON.stp") + p21loader = Part21Loader("as1.stp") + t2 = time.time() + print "Loading schema took: %s s \n" % ((t2-t1)) + t1 = time.time() + print "Creating instances" + p21population = Part21Population(p21loader) + p21population.create_entity_instances() + t2 = time.time() + print "Creating instances took: %s s \n" % ((t2-t1)) \ No newline at end of file diff --git a/src/fedex_python/python/SCL/SCLBase.py b/src/fedex_python/python/SCL/SCLBase.py new file mode 100644 index 000000000..617c816ad --- /dev/null +++ b/src/fedex_python/python/SCL/SCLBase.py @@ -0,0 +1,44 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +class BaseEntityClass(object): + """ A class that allows advanced __repr__ features for entity instances + """ + def __repr__(self): + """ Displays attribute with their values + """ + doc_string = "# %s class description:\n%s\n# Instance attributes:\n"%(self.__class__,self.__doc__) + # write each argument with its value + properties = dir(self) + for elem in properties: + if not elem.startswith("_"): + doc_string += "\t%s:%s\n"%(elem,self.__getattribute__(elem)) + return doc_string diff --git a/src/fedex_python/python/SCL/SimpleDataTypes.py b/src/fedex_python/python/SCL/SimpleDataTypes.py new file mode 100644 index 000000000..c0a37d4e9 --- /dev/null +++ b/src/fedex_python/python/SCL/SimpleDataTypes.py @@ -0,0 +1,186 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +Docstrings are courtesy of ISO 10303-11:1994(E) +""" + +class NUMBER: + """ + The number data type has as its domain all numeric values in the language. The number data + type shall be used when a more specific numeric representation is not important. + + Python mapping: cannot be mapped to a builtin python type. The constructor only checks that + the parameter passed at initialization is a number. + """ + def __init__(self,value): + # should test the type of value (float, or integer) + pass + +class REAL(float): + """ + The real data type has as its domain all rational, irrational and scientfic real numbers. It is + a specialization of the number data type. + Syntax: + 265 real_type = REAL [ '(' precision_spec ')' ] . + 255 precision_spec = numeric_expression . + Rational and irrational numbers have infnite resolution and are exact. Scientific numbers rep- + resent quantities which are known only to a specified precision. The precision_spec is stated + in terms of significant digits. + A real number literal is represented by a mantissa and optional exponent. The number of digits + making up the mantissa when all leading zeros have been removed is the number of significant + digits. The known precision of a value is the number of leading digits that are necessary to the + application. + Rules and restrictions: + a) The precision_spec gives the minimum number of digits of resolution that are re- + quired. This expression shall evaluate to a positive integer value. + b) When no resolution specification is given the precision of the real number is uncon- + strained. + + Python mapping: REAL is mapped to 'float' type + """ + pass + +class INTEGER(int): + """ + The integer data type has as its domain all integer numbers. It is a specialization of the real + data type. + + Python mapping: INTEGER is mapped to 'int' type""" + pass + +class STRING(str): + """ + The string data type has as its domain sequences of characters. The characters which are + permitted to form part of a string value are de ned in ISO 10646. + Syntax: + 293 string_type = STRING [ width_spec ] . + 318 width_spec = '(' width ')' [ FIXED ] . + 317 width = numeric_expression . + A string data type may be de ned as either xed or varying width (number of characters). If + it is not specfically defined as fixed width (by using the fixed reserved word in the dfinition) + the string has varying width. + + The domain of a xed width string data type is the set of all character sequences of exactly + the width speci ed in the type de nition. + The domain of a varying width string data type is the set of all character sequences of width + less than or equal to the maximum width speci ed in the type de nition. + If no width is speci ed, the domain is the set of all character sequences, with no constraint on + the width of these sequences. + Substrings and individual characters may be addressed using subscripts as described in 12.5. + The case (upper or lower) of letters within a string is signi cant. + + Python mapping: INTEGER is mapped the 'str' type. An additional width_spec parameter can be passed + to handle the FIXED length constraint + """ + pass + +class LOGICAL: + """ + The logical data type has as its domain the three literals true, false and unknown. + Syntax: + 243 logical_type = LOGICAL . + The following ordering holds for the values of the logical data type: false < unknown < + true. The logical data type is compatible with the boolean data type, except that the value + unknown cannot be assigned to a boolean variable. + """ + pass +Unknown = LOGICAL() + +# +#The boolean data type has as its domain the two literals true and false. The boolean data +#type is a specialization of the logical data type. +# +#Python mapping: BOOLEAN is mapped to 'bool' type +# +# The bool data type can't however be subclassed in Python (see +# See http://mail.python.org/pipermail/python-dev/2002-March/020822.html) +# so it is just set to bool +BOOLEAN = bool + +class BINARY(str): + """ + The binary data type has as its domain sequences of bits, each bit being represented by 0 or 1. + Syntax: + 172 binary_type = BINARY [ width_spec ] . + 318 width_spec = '(' width ')' [ FIXED ] . + 317 width = numeric_expression . + A binary data type may be defined as either fixed or varying width (number of bits). If it is + not specifically defined as fixed width (by using the fixed reserved word in the definition) the + binary data type has varying width. + The domain of a fixed width binary data type is the set of all bit sequences of exactly the width + speci ed in the type definition. + The domain of a varying width binary data type is the set of all bit sequences of width less + than or equal to the maximum width speci ed in the type de nition. If no width is specified, + the domain is the set of all bit sequences, with no constraint on the width of these sequences. + Subbinaries and individual bits may be addressed using subscripts as described in 12.3. + + Python mapping: BINARY is mapped to the 'str' type. A check is performed to validate it is a binary + string representing a number. + """ + def __new__(self, value, width=-1, fixed=False): + return str.__new__(self, value) + + def __init__(self, value, width=-1, fixed=False): + """ By default, lenght is set to None""" + self._specified_width = width + self._fixed = fixed + # Check implicit width + if (width!=-1) and not fixed: + raise ValueError("The 'width' parameter is passed but 'fixed' is still false. Please explicitely set 'fixed' to True to avoid implicit declaration") + # First check the string length if 'fixed' is set to True + if fixed: + if len(value) != width: + raise ValueError("The BINARY width %i is not consistent with the 'width' declaration(%i)"%(len(value),width)) + # Check that the value passed is actually a binary + try: + int(value,2) + except ValueError: + raise ValueError("%s is not a binary"%value) + + +if __name__=="__main__": + print "Creating REAL from float value" + a = REAL(1.5) + print a*2 + print "Creating REAL from string value" + a = REAL("1.2") + print a*3 + print "Creating INTEGER from int value" + b = INTEGER(2) + c = INTEGER(3) + print b+c + print "Creating INTEGER from string value" + e = INTEGER("5") + f = INTEGER("8") + print e*f + + \ No newline at end of file diff --git a/src/fedex_python/python/SCL/TypeChecker.py b/src/fedex_python/python/SCL/TypeChecker.py new file mode 100644 index 000000000..86ba17b52 --- /dev/null +++ b/src/fedex_python/python/SCL/TypeChecker.py @@ -0,0 +1,53 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from ConstructedDataTypes import ENUMERATION, SELECT + +def check_type(instance, expected_type): + """ This function checks wether an object is an instance of a given class + returns False or True + """ + type_match = False #by default, will be set to True if any match + # in the case of an enumeration, we have to check if the instance is in the list + if isinstance(expected_type,ENUMERATION): + type_match = instance in expected_type + elif isinstance(expected_type,SELECT): + # we check if the instance is of the type of any of the types that are in the SELECT + if type(instance) in expected_type.get_aggregated_allowed_types(): + type_match = True + else: + type_match = isinstance(instance,expected_type) + if not type_match: + raise TypeError('Type of argument number_of_sides must be %s (you passed %s)'%(expected_type,type(instance))) + else: + return True + + \ No newline at end of file diff --git a/src/fedex_python/python/SCL/__init__.py b/src/fedex_python/python/SCL/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/fedex_python/python/SCL_unittest.py b/src/fedex_python/python/SCL_unittest.py new file mode 100644 index 000000000..e6f3f8a2c --- /dev/null +++ b/src/fedex_python/python/SCL_unittest.py @@ -0,0 +1,166 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from SCL.SimpleDataTypes import * +from SCL.TypeChecker import * +from SCL.ConstructedDataTypes import * + +import unittest + +# +# Simple data types +# +class TestINTEGER(unittest.TestCase): + ''' + INTEGER test + ''' + def test_create_from_int(self): + a = INTEGER(1) + self.assertEqual(a,1) + b = REAL(0) + self.assertEqual(b,0) + + def test_create_from_string(self): + a = REAL("10") + self.assertEqual(a,10) + b = REAL("0") + self.assertEqual(b,0) + + def test_type(self): + a = INTEGER(5) + self.assertTrue(type(a) == INTEGER) + + def test_INTEGER_ops(self): + a = INTEGER(2) + b = INTEGER(3) + c = a*b + self.assertEqual(c,6) + self.assertTrue(type(c) == int) + + def test_create_from_string_exception(self): + ''' + INT cannot be constructed from an ascii string + ''' + try: + INTEGER("c") + except ValueError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + +class TestREAL(unittest.TestCase): + ''' + REAL test + ''' + def test_create_from_float(self): + a = REAL(1.5) + self.assertEqual(a,1.5) + b = REAL(0) + self.assertEqual(b,0) + + def test_create_from_string(self): + a = REAL("1.5") + self.assertEqual(a,1.5) + b = REAL("0") + self.assertEqual(b,0) + + def test_type(self): + a = REAL(5) + self.assertTrue(type(a) == REAL) + + def test_REAL_ops(self): + a = REAL(1.5) + b = REAL(2) + c = a*b + self.assertEqual(c,3) + self.assertTrue(type(c) == float) + + def test_REAL_INTEGER_ops(self): + a = REAL(5.5) + b = INTEGER(3) + self.assertEqual(a+b,8.5) + self.assertTrue(type(a+b) == float) + + def test_create_from_string_exception(self): + ''' + REAL cannot be constructed from an ascii string + ''' + try: + REAL("c") + except ValueError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + +class TestBOOLEAN(unittest.TestCase): + ''' + BOOLEAN test + ''' + def test_create_from_bool(self): + a = BOOLEAN(True) + self.assertTrue(a) + b = BOOLEAN(False) + self.assertFalse(b) + +# +# TypeChecker +# +class TestTypeChecker(unittest.TestCase): + def test_match_type(self): + class P: + pass + p = P() + match_type = check_type(p,P) #should return True + self.assertTrue(match_type) + + def test_type_dontmatch(self): + class P: + pass + p = P() + try: + check_type(3,P) + except TypeError: + pass + except a: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + + def test_check_enum_type(self): + enum = ENUMERATION(["my","string"]) + print check_type("my",enum) + +unittest.main() + diff --git a/src/fedex_python/python/setup.py b/src/fedex_python/python/setup.py new file mode 100644 index 000000000..6d90931c1 --- /dev/null +++ b/src/fedex_python/python/setup.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from distutils.core import setup + +setup(name='SCL', + version='0.4', + description='Python STEP Class Library', + author='Thomas Paviot', + author_email='tpaviot@gmail.com', + url='http://www.python.org/sigs/distutils-sig/', + packages=['SCL'], + ) \ No newline at end of file diff --git a/src/fedex_python/src/classes_misc_python.c b/src/fedex_python/src/classes_misc_python.c new file mode 100644 index 000000000..5c8ea4ca8 --- /dev/null +++ b/src/fedex_python/src/classes_misc_python.c @@ -0,0 +1,859 @@ +#define CLASSES_MISC_C +#include +#include "classes.h" +/******************************************************************* +** FedEx parser output module for generating C++ class definitions +** December 5, 1989 +** release 2 17-Feb-1992 +** release 3 March 1993 +** release 4 December 1993 +** K. C. Morris +** +** Development of FedEx was funded by the United States Government, +** and is not subject to copyright. + +******************************************************************* +The conventions used in this binding follow the proposed specification +for the STEP Standard Data Access Interface as defined in document +N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. +*******************************************************************/ + +extern int multiple_inheritance; +/*extern int corba_binding; */ + +/****************************************************************** +** The following functions will be used *** +*** through out the the program fedex_plus ***/ + + +/****************************************************************** + ** Procedure: CheckWord + ** Description: if word is a reserved word, it is capitalized + ** Parameters: word -- string to be checked + ** Returns: altered word if word is reserved; otherwise the original word + ** Side Effects: the word is altered in memory + ** Status: started 12/1 + ******************************************************************/ +const char * +CheckWord( const char * word ) { +#ifdef NOT_USING_SDAI_BINDING + /* obsolete with proposed c++ binding */ + + static char * reserved_words [] = { + "application_marker", "asm", "attributes", "auto", + "break", "case", "char", "class", "const", "continue", + "default", "delete", "do", "double", + "else", "enum", "extern", + "float", "for", "friend", "goto", "handle", + "if", "inline", "instance_id", "int", "long", + "new", "nullable", "opcode", "operator", "overload", + "private", "protected", "public", "register", "return", + "shared", "short", "sizeof", "static", "struct", "switch", + "this", "template", "type", "typedef", "type_name", + "union", "unsigned", + "val", "virtual", "void", "volatile" + }; + int nwords = ( sizeof reserved_words / sizeof reserved_words[0] ); + int cond, + i, + low = 0, + high = nwords - 1; + + /* word is obviously not in list, if it is longer than any of the words in the list */ + if( strlen( word ) > 12 ) { + return ( word ); + } + + while( low <= high ) { + i = ( low + high ) / 2; + if( ( cond = strcmp( word, reserved_words [i] ) ) < 0 ) { + high = i - 1; + } else if( cond > 0 ) { + low = i + 1; + } else { /* word is a reserved word, capitalize it */ + printf( "** warning: reserved word %s ", word ); + *( word + 0 ) = toupper( *( word + 0 ) ); + printf( "is changed to %s **\n", word ); + + } + } +#endif + return ( word ); + +} + +/****************************************************************** + ** Procedure: string functions + ** Description: These functions take a character or a string and return + ** a temporary copy of the string with the function applied to it. + ** Parameters: + ** Returns: temporary copy of characters + ** Side Effects: character or string returned persists until the + ** next invocation of the function + ** Status: complete + ******************************************************************/ + +char +ToLower( char c ) { + if( isupper( c ) ) { + return ( tolower( c ) ); + } else { + return ( c ); + } + +} + +char +ToUpper( char c ) { + if( islower( c ) ) { + return ( toupper( c ) ); + } else { + return ( c ); + } +} + +const char * +StrToLower( const char * word ) { + static char newword [MAX_LEN]; + int i = 0; + if( !word ) { + return 0; + } + while( word [i] != '\0' ) { + newword [i] = ToLower( word [i] ); + ++i; + } + newword [i] = '\0'; + return ( newword ) ; + +} + +const char * +StrToUpper( const char * word ) { + static char newword [MAX_LEN]; + int i = 0; + char ToUpper( char c ); + + while( word [i] != '\0' ) { + newword [i] = ToUpper( word [i] ); + ++i; + + } + newword [i] = '\0'; + return ( newword ); +} + +const char * +StrToConstant( const char * word ) { + static char newword [MAX_LEN]; + int i = 0; + + while( word [i] != '\0' ) { + if( word [i] == '/' || word [i] == '.' ) { + newword [i] = '_'; + } else { + newword [i] = ToUpper( word [i] ); + } + ++i; + + } + newword [i] = '\0'; + return ( newword ); +} + +/****************************************************************** + ** Procedure: FILEcreate + ** Description: creates a file for c++ with header definitions + ** Parameters: filename + ** Returns: FILE* pointer to file created or NULL + ** Side Effects: creates a file with name filename + ** Status: complete + ******************************************************************/ + +FILE * +FILEcreate( const char * filename ) { + FILE * file; + //const char * fn; + + if( ( file = fopen( filename, "w" ) ) == NULL ) { + printf( "**Error in SCHEMAprint: unable to create file %s ** \n", filename ); + return ( NULL ); + } + + //fprintf( file, "#ifndef %s\n", fn = StrToConstant( filename ) ); + //fprintf( file, "#define %s\n", fn ); + + fprintf( file, "# This file was generated by fedex_python. You probably don't want to edit\n" ); + fprintf( file, "# it since your modifications will be lost if fedex_plus is used to\n" ); + fprintf( file, "# regenerate it.\n" ); + return ( file ); + +} + +/****************************************************************** + ** Procedure: FILEclose + ** Description: closes a file opened with FILEcreate + ** Parameters: FILE* file -- pointer to file to close + ** Returns: + ** Side Effects: + ** Status: complete + ******************************************************************/ + +void +FILEclose( FILE * file ) { + //fprintf( file, "#endif\n" ); + fclose( file ); +} + + +/****************************************************************** + ** Procedure: isAggregate + ** Parameters: Attribute a + ** Returns: int indicates whether the attribute is an aggregate + ** Description: indicates whether the attribute is an aggregate + ** Side Effects: none + ** Status: complete 1/15/91 + ******************************************************************/ + +int +isAggregate( Variable a ) { + return( TYPEinherits_from( VARget_type( a ), aggregate_ ) ); +} + +int +isAggregateType( const Type t ) { + return( TYPEinherits_from( t, aggregate_ ) ); +} + + +/****************************************************************** + ** Procedure: TYPEget_ctype + ** Parameters: const Type t -- type for attribute + ** Returns: a string which is the type of the data member in the c++ class + ** Description: supplies the type of a data member for the c++ class + ** Side Effects: + ** Status: complete 1/15/90 + ** Changes: Modified by CD to return the appropriate types as outlined in + ** "SDAI C++ Binding for PDES, Inc. Prototyping" by Stephen Clark + ** Change Date: 5/22/91 CD + ** Change Date: 28-Sep-1993 made entities use their real type instead of base + ** class STEPentityH + ******************************************************************/ + +const char * +TYPEget_ctype( const Type t ) { + Class_Of_Type class; + Type bt; + static char retval [BUFSIZ]; + + + /* aggregates are based on their base type + case TYPE_ARRAY: + case TYPE_BAG: + case TYPE_LIST: + case TYPE_SET: + */ + if( isAggregateType( t ) ) { + bt = TYPEget_body( t )->base; + + if( isAggregateType( bt ) ) { + return( "GenericAggregate" ); + } + + class = TYPEget_type( bt ); + + /* case TYPE_INTEGER: */ + if( class == Class_Integer_Type ) { + return ( "IntAggregate" ); + } + + /* case TYPE_REAL: + case TYPE_NUMBER: */ + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + return ( "RealAggregate" ); + } + + /* case TYPE_ENTITY: */ + if( class == Class_Entity_Type ) { + return( "EntityAggregate" ); + } + + /* case TYPE_ENUM: */ + /* case TYPE_SELECT: */ + if( ( class == Class_Enumeration_Type ) + || ( class == Class_Select_Type ) ) { + /* + strcpy (retval, ClassName (TYPEget_name (bt))); + */ + strcpy( retval, TYPEget_ctype( bt ) ); + strcat( retval, "s" ); + return ( retval ); + } + + /* case TYPE_LOGICAL: */ + if( class == Class_Logical_Type ) { + return ( "LOGICALS" ); + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + return ( "BOOLEANS" ); + } + + /* case TYPE_STRING: */ + if( class == Class_String_Type ) { + return( "StringAggregate" ); + } + + /* case TYPE_BINARY: */ + if( class == Class_Binary_Type ) { + return( "BinaryAggregate" ); + } + } + + /* the rest is for things that are not aggregates */ + + class = TYPEget_type( t ); + + /* case TYPE_LOGICAL: */ + if( class == Class_Logical_Type ) { + return ( "SCLP23(LOGICAL)" ); + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + return ( "SCLP23(BOOLEAN)" ); + } + + /* case TYPE_INTEGER: */ + if( class == Class_Integer_Type ) { + return ( "SCLP23(Integer)" ); + } + + /* case TYPE_REAL: + case TYPE_NUMBER: */ + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + return ( "SCLP23(Real)" ) ; + } + + /* case TYPE_STRING: */ + if( class == Class_String_Type ) { + return ( "SCLP23(String)" ); + } + + /* case TYPE_BINARY: */ + if( class == Class_Binary_Type ) { + return ( "SCLP23(Binary)" ); + } + + /* case TYPE_ENTITY: */ + if( class == Class_Entity_Type ) { + strncpy( retval, TypeName( t ), BUFSIZ - 2 ); + strcat( retval, "_ptr" ); + return retval; + /* return ("STEPentityH"); */ + } + /* case TYPE_ENUM: */ + /* case TYPE_SELECT: */ + if( class == Class_Enumeration_Type ) { + strncpy( retval, TypeName( t ), BUFSIZ - 2 ); + strcat( retval, "_var" ); + return retval; + } + if( class == Class_Select_Type ) { + return ( TypeName( t ) ); + } + + /* default returns undefined */ + return ( "SCLundefined" ); +} + +/****************************************************************** + ** Procedure: TypeName + ** Parameters: Type t + ** Returns: name of type as defined in SDAI C++ binding 4-Nov-1993 + ** Status: 4-Nov-1993 + ******************************************************************/ +const char * +TypeName( Type t ) { + static char name [BUFSIZ]; + strcpy( name, TYPE_PREFIX ); + if( TYPEget_name( t ) ) { + strncat( name, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - strlen( TYPE_PREFIX ) - 1 ); + } else { + return TYPEget_ctype( t ); + } + return name; +} + +/****************************************************************** + ** Procedure: AccessType + ** Parameters: const Type t -- type for attribute + ** Returns: a string which is the type used by the access functions to + the data member in the c++ class + ** Description: supplies the type for access functions in a c++ class + ** Side Effects: + ** Status: 3-Nov-1993 -kcm +******************************************************************/ + +const char * +AccessType( Type t ) { + Class_Of_Type class; + static char nm [BUFSIZ]; + strncpy( nm, TypeName( t ), BUFSIZ - 4 ); + if( TYPEis_entity( t ) ) { + /* if(corba_binding) + { + if (TYPEget_name (t)) + strncpy (nm, FirstToUpper (TYPEget_name (t)), BUFSIZ-1); + } + */ + strcat( nm, "_ptr" ); + return nm; + } else if( TYPEis_select( t ) || TYPEis_aggregate( t ) ) { + strcat( nm, "_ptr" ); + return nm; + } + class = TYPEget_type( t ); + if( class == Class_Enumeration_Type ) { + strncpy( nm, TypeName( t ), BUFSIZ - 2 ); + strcat( nm, "_var" ); + return nm; + } + if( class == Class_Logical_Type ) { + strncpy( nm, "Logical", BUFSIZ - 2 ); + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + strncpy( nm, "Boolean", BUFSIZ - 2 ); + } + return nm; +} + +/****************************************************************** + ** Procedure: ClassName + ** Parameters: const char * oldname + ** Returns: temporary copy of name suitable for use as a class name + ** Side Effects: erases the name created by a previous call to this function + ** Status: complete + ******************************************************************/ + +const char * +ClassName( const char * oldname ) { + int i = 0, j = 0; + static char newname [BUFSIZ]; + if( !oldname ) { + return ( "" ); + } + + + strcpy( newname, ENTITYCLASS_PREFIX ) ; + j = strlen( ENTITYCLASS_PREFIX ) ; + newname [j] = ToUpper( oldname [i] ); + ++i; + ++j; + while( oldname [i] != '\0' ) { + newname [j] = ToLower( oldname [i] ); + /* if (oldname [i] == '_') */ + /* character is '_' */ + /* newname [++j] = ToUpper (oldname [++i]);*/ + ++i; + ++j; + } + newname [j] = '\0'; + return ( newname ); + + /****** This procedure gets rid of '_' and is no longer being used + if (oldname [i] != '_') newname [j] = ToLower (oldname [i]); + else { *//* character is '_' *//* +newname [j] = ToUpper (oldname [++i]); +if (oldname [i] == '\0') --i; +} +++i; +++j; +*******/ +} + +const char * +ENTITYget_CORBAname( Entity ent ) { + static char newname [BUFSIZ]; + strcpy( newname, ENTITYget_name( ent ) ); + newname[0] = ToUpper( newname [0] ); + return newname; +} + +/****************************************************************** + ** Procedure: ENTITYget_classname + ** Parameters: Entity ent + ** Returns: the name of the c++ class representing the entity + ** Status: complete + ******************************************************************/ + +const char * +ENTITYget_classname( Entity ent ) { + const char * oldname = ENTITYget_name( ent ); + return ( ClassName( oldname ) ); +} + +/****************************************************************** + ** Procedure: PrettyTmpName (char * oldname) + ** Procedure: PrettyNewName (char * oldname) + ** Parameters: oldname + ** Returns: a new capitalized name + ** Description: creates a new name with first character's in caps + ** Side Effects: PrettyNewName allocates memory for the new name + ** Status: OK 7-Oct-1992 kcm + ******************************************************************/ +const char * +PrettyTmpName( const char * oldname ) { + int i = 0; + static char newname [BUFSIZ]; + newname [0] = '\0'; + while( ( oldname [i] != '\0' ) && ( i < BUFSIZ ) ) { + newname [i] = ToLower( oldname [i] ); + if( oldname [i] == '_' ) { /* character is '_' */ + ++i; + newname [i] = ToUpper( oldname [i] ); + } + if( oldname [i] != '\0' ) { + ++i; + } + } + + newname [0] = ToUpper( oldname [0] ); + newname [i] = '\0'; + return newname; +} + +/* This function is out of date DAS */ +const char * +EnumName( const char * oldname ) { + int j = 0; + static char newname [MAX_LEN]; + if( !oldname ) { + return ( "" ); + } + + strcpy( newname, ENUM_PREFIX ) ; + j = strlen( ENUM_PREFIX ) ; + newname [j] = ToUpper( oldname [0] ); + strncpy( newname + j + 1, StrToLower( oldname + 1 ), MAX_LEN - j ); + j = strlen( newname ); + newname [j] = '\0'; + return ( newname ); +} + +const char * +SelectName( const char * oldname ) { + int j = 0; + static char newname [MAX_LEN]; + if( !oldname ) { + return ( "" ); + } + + strcpy( newname, TYPE_PREFIX ); + newname [0] = ToUpper( newname [0] ); + j = strlen( TYPE_PREFIX ); + newname [j] = ToUpper( oldname [0] ); + strncpy( newname + j + 1, StrToLower( oldname + 1 ), MAX_LEN - j ); + j = strlen( newname ); + newname [j] = '\0'; + return ( newname ); +} + +const char * +FirstToUpper( const char * word ) { + static char newword [MAX_LEN]; + + strncpy( newword, word, MAX_LEN ); + newword[0] = ToUpper( newword[0] ); + return ( newword ); +} + +/* return fundamental type but as the string which corresponds to */ +/* the appropriate type descriptor */ +/* if report_reftypes is true, report REFERENCE_TYPE when appropriate */ +char * +FundamentalType( const Type t, int report_reftypes ) { + if( report_reftypes && TYPEget_head( t ) ) { + return( "REFERENCE_TYPE" ); + } + switch( TYPEget_body( t )->type ) { + case integer_: + return( "INTEGER" ); + case real_: + return( "REAL" ); + case string_: + return( "STRING" ); + case binary_: + return( "BINARY" ); + case boolean_: + return( "BOOLEAN" ); + case logical_: + return( "LOGICAL" ); + case number_: + return( "NUMBER" ); + case generic_: + return( "GENERIC_TYPE" ); + case aggregate_: + return( "AGGREGATE_" ); + case array_: + return( "ARRAY_TYPE" ); + case bag_: + return( "BAG_TYPE" ); + case set_: + return( "'SET_TYPE not implemented'" ); + case list_: + return( "'LIST TYPE Not implemented'" ); + case entity_: + return( "INSTANCE" ); + case enumeration_: + return( "ENUMERATION" ); + case select_: + return ( "SELECT" ); + default: + return( "UNKNOWN_TYPE" ); + } +} + +/* this actually gets you the name of the variable that will be generated to + be a TypeDescriptor or subtype of TypeDescriptor to represent Type t in + the dictionary. */ + +const char * +TypeDescriptorName( Type t ) { + static char b [BUFSIZ]; + Schema parent = t->superscope; + /* NOTE - I corrected a prev bug here in which the *current* schema was + ** passed to this function. Now we take "parent" - the schema in which + ** Type t was defined - which was actually used to create t's name. DAR */ + + if( !parent ) { + parent = TYPEget_body( t )->entity->superscope; + /* This works in certain cases that don't work otherwise (basically a + ** kludge). For some reason types which are really entity choices of + ** a select have no superscope value, but their super may be tracked + ** by following through the entity they reference, as above. */ + } + + sprintf( b, "%s%s%s", SCHEMAget_name( parent ), TYPEprefix( t ), + TYPEget_name( t ) ); + return b; +} + +/* this gets you the name of the type of TypeDescriptor (or subtype) that a + variable generated to represent Type t would be an instance of. */ + +const char * +GetTypeDescriptorName( Type t ) { + switch( TYPEget_body( t )->type ) { + case aggregate_: + return "AggrTypeDescriptor"; + + case list_: + return "ListTypeDescriptor"; + + case set_: + return "SetTypeDescriptor"; + + case bag_: + return "BagTypeDescriptor"; + + case array_: + return "ArrayTypeDescriptor"; + + case select_: + return "SelectTypeDescriptor"; + + case boolean_: + case logical_: + case enumeration_: + return "EnumTypeDescriptor"; + + case entity_: + return "EntityDescriptor"; + + case integer_: + case real_: + case string_: + case binary_: + case number_: + case generic_: + return "TypeDescriptor"; + default: + printf( "Error in %s, line %d: type %d not handled by switch statement.", __FILE__, __LINE__, TYPEget_body( t )->type ); + abort(); + } +} + +int +ENTITYhas_explicit_attributes( Entity e ) { + Linked_List l = ENTITYget_attributes( e ); + int cnt = 0; + LISTdo( l, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + ++cnt; + } + LISTod; + return cnt; + +} + +Entity +ENTITYput_superclass( Entity entity ) { +#define ENTITYget_type(e) ((e)->u.entity->type) + + Linked_List l = ENTITYget_supertypes( entity ); + Entity super = 0; + Entity ignore = 0; + int super_cnt = 0; + EntityTag tag; + + Linked_List list = 0; + + if( ! LISTempty( l ) ) { + + if( multiple_inheritance ) { + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + /* assign superclass to be the first one on the list of parents */ + super = ( Entity )LISTpeek_first( list ); + } + } else { + /* find the first parent that has attributes (in the parent or any of its + ancestors). Make super point at that parent and print warnings for + all the rest of the parents. DAS */ + LISTdo( l, e, Entity ) + /* if there's no super class yet, + or if the entity super class [the variable] super is pointing at + doesn't have any attributes: make super point at the current parent. + As soon as the parent pointed to by super has attributes, stop + assigning super and print ignore messages for the remaining parents. + */ + if( ( ! super ) || ( ! ENTITYhas_explicit_attributes( super ) ) ) { + ignore = super; + super = e; + ++ super_cnt; + } else { + ignore = e; + } + if( ignore ) { + printf( "WARNING: multiple inheritance not implemented.\n" ); + printf( "\tin ENTITY %s\n\tSUPERTYPE %s IGNORED.\n\n", + ENTITYget_name( entity ), ENTITYget_name( e ) ); + } + LISTod; + } + + tag = ( EntityTag ) malloc( sizeof( struct EntityTag_ ) ); + tag -> superclass = super; + TYPEput_clientData( ENTITYget_type( entity ), tag ); + return super; + } + return 0; +} + +Entity +ENTITYget_superclass( Entity entity ) { + EntityTag tag; + tag = TYPEget_clientData( ENTITYget_type( entity ) ); + return ( tag ? tag -> superclass : 0 ); +} + +void ENTITYget_first_attribs( Entity entity, Linked_List result ) { + Linked_List supers; + + LISTdo( ENTITYget_attributes( entity ), attr, Generic ) + LISTadd_last( result, attr ); + LISTod; + supers = ENTITYget_supertypes( entity ); + if( supers ) { + ENTITYget_first_attribs( ( Entity )LISTget_first( supers ), result ); + } +} + +/* Attributes are divided into four categories: +** these are not exclusive as far as I can tell! I added defs below DAS +** +** . simple explicit +** . type shifters // not DERIVEd - redefines type in ancestor +** // VARget_initializer(v) returns null +** +** . simple derived // DERIVEd - is calculated - VARget_initializer(v) +** // returns non-zero, VARis_derived(v) is non-zero +** +** . overriding // includes type shifters and derived +** +** All of them are added to the dictionary. +** Only type shifters generate a new STEPattribute. +** Type shifters generate access functions and data members, for now. +** Overriding generate access functions and data members, for now. ???? DAS + +** // type shifting attributes +** // ------------------------ +** // before printing new STEPattribute +** // check to see if it\'s already printed in supertype +** // still add new access function +** +** // overriding attributes +** // --------------------- +** // go through derived attributes +** // if STEPattribute found with same name +** // tell it to be * for reading and writing +**/ + +Variable +VARis_type_shifter( Variable a ) { + char * temp; + + if( VARis_derived( a ) || VARget_inverse( a ) ) { + return 0; + } + + temp = EXPRto_string( VARget_name( a ) ); + if( ! strncmp( StrToLower( temp ), "self\\", 5 ) ) { + /* a is a type shifter */ + free( temp ); + return a; + } + free( temp ); + return 0; +} + +Variable +VARis_overrider( Entity e, Variable a ) { + + Variable other; + char * tmp; + + tmp = VARget_simple_name( a ); + + LISTdo( ENTITYget_supertypes( e ), s, Entity ) + if( ( other = ENTITYget_named_attribute( s, tmp ) ) + && other != a ) { + return other; + } + LISTod; + return 0; +} + +Type +TYPEget_ancestor( Type t ) +/* + * For a renamed type, returns the original (ancestor) type from which t + * descends. Return NULL if t is top level. + */ +{ + Type i = t; + + if( !TYPEget_head( i ) ) { + return NULL; + } + + while( TYPEget_head( i ) ) { + i = TYPEget_head( i ); + } + + return i; +} diff --git a/src/fedex_python/src/classes_python.c b/src/fedex_python/src/classes_python.c new file mode 100644 index 000000000..3a256794a --- /dev/null +++ b/src/fedex_python/src/classes_python.c @@ -0,0 +1,4674 @@ +/* +** Fed-x parser output module for generating C++ class definitions +** December 5, 1989 +** release 2 17-Feb-1992 +** release 3 March 1993 +** release 4 December 1993 +** K. C. Morris +** +** Development of Fed-x was funded by the United States Government, +** and is not subject to copyright. + +******************************************************************* +The conventions used in this binding follow the proposed specification +for the STEP Standard Data Access Interface as defined in document +N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. +*******************************************************************/ + +/****************************************************************** +*** The functions in this file generate the C++ code for ENTITY ** +*** classes, TYPEs, and TypeDescriptors. *** + ** **/ + + +/* this is used to add new dictionary calls */ +/* #define NEWDICT */ + +#include +#include "classes.h" + +int isAggregateType( const Type t ); +int isAggregate( Variable a ); +Variable VARis_type_shifter( Variable a ); +const char * ENTITYget_CORBAname( Entity ent ); +const char * GetTypeDescriptorName( Type t ); + +char * FundamentalType( const Type t, int report_reftypes ); + +int multiple_inheritance = 1; +int print_logging = 0; +int corba_binding = 0; +int old_accessors = 0; + +/* several classes use attr_count for naming attr dictionary entry + variables. All but the last function generating code for a particular + entity increment a copy of it for naming each attr in the entity. + Here are the functions: + ENTITYhead_print (Entity entity, FILE* file,Schema schema) + LIBdescribe_entity (Entity entity, FILE* file, Schema schema) + LIBcopy_constructor (Entity ent, FILE* file) + LIBstructor_print (Entity entity, FILE* file, Schema schema) + LIBstructor_print_w_args (Entity entity, FILE* file, Schema schema) + ENTITYincode_print (Entity entity, FILE* file,Schema schema) + DAS + */ +static int attr_count; /* number each attr to avoid inter-entity clashes */ +static int type_count; /* number each temporary type for same reason above */ + +extern int any_duplicates_in_select( const Linked_List list ); +extern int unique_types( const Linked_List list ); +extern char * non_unique_types_string( const Type type ); +static void printEnumCreateHdr( FILE *, const Type ); +static void printEnumCreateBody( FILE *, const Type ); +static void printEnumAggrCrHdr( FILE *, const Type ); +static void printEnumAggrCrBody( FILE *, const Type ); +void printAccessHookFriend( FILE *, const char * ); +void printAccessHookHdr( FILE *, const char * ); +int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ); +void TypeBody_Description( TypeBody body, char * buf ); + +/* +Turn the string into a new string that will be printed the same as the +original string. That is, turn backslash into a quoted backslash and +turn \n into "\n" (i.e. 2 chars). +*/ + +char * format_for_stringout( char * orig_buf, char * return_buf ) { + char * optr = orig_buf; + char * rptr = return_buf; + while( *optr ) { + if( *optr == '\n' ) { + *rptr = '\\'; + rptr++; + *rptr = 'n'; + } else if( *optr == '\\' ) { + *rptr = '\\'; + rptr++; + *rptr = '\\'; + } else { + *rptr = *optr; + } + rptr++; + optr++; + } + *rptr = '\0'; + return return_buf; +} + +void +USEREFout( Schema schema, Dictionary refdict, Linked_List reflist, char * type, FILE * file ) { + Dictionary dict; + DictionaryEntry de; + struct Rename * r; + Linked_List list; + char td_name[BUFSIZ]; + char sch_name[BUFSIZ]; + + strncpy( sch_name, PrettyTmpName( SCHEMAget_name( schema ) ), BUFSIZ ); + + LISTdo( reflist, s, Schema ) { + fprintf( file, "\t// %s FROM %s; (all objects)\n", type, s->symbol.name ); + fprintf( file, "\tis = new Interface_spec(\"%s\",\"%s\");\n", sch_name, PrettyTmpName( s->symbol.name ) ); + fprintf( file, "\tis->all_objects_(1);\n" ); + if( !strcmp( type, "USE" ) ) { + fprintf( file, "\t%s%s->use_interface_list_()->Append(is);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } else { + fprintf( file, "\t%s%s->ref_interface_list_()->Append(is);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } + } + LISTod + + if( !refdict ) { + return; + } + dict = DICTcreate( 10 ); + + /* sort each list by schema */ + + /* step 1: for each entry, store it in a schema-specific list */ + DICTdo_init( refdict, &de ); + while( 0 != ( r = ( struct Rename * )DICTdo( &de ) ) ) { + Linked_List list; + + list = ( Linked_List )DICTlookup( dict, r->schema->symbol.name ); + if( !list ) { + list = LISTcreate(); + DICTdefine( dict, r->schema->symbol.name, list, + ( Symbol * )0, OBJ_UNKNOWN ); + } + LISTadd( list, r ); + } + + /* step 2: for each list, print out the renames */ + DICTdo_init( dict, &de ); + while( 0 != ( list = ( Linked_List )DICTdo( &de ) ) ) { + bool first_time = true; + LISTdo( list, r, struct Rename * ) + + /* + Interface_spec_ptr is; + Used_item_ptr ui; + is = new Interface_spec(const char * cur_sch_id); + schemadescriptor->use_interface_list_()->Append(is); + ui = new Used_item(TypeDescriptor *ld, const char *oi, const char *ni) ; + is->_explicit_items->Append(ui); + */ + + /* note: SCHEMAget_name(r->schema) equals r->schema->symbol.name) */ + if( first_time ) { + fprintf( file, "\t// %s FROM %s (selected objects)\n", type, r->schema->symbol.name ); + fprintf( file, "\tis = new Interface_spec(\"%s\",\"%s\");\n", sch_name, PrettyTmpName( r->schema->symbol.name ) ); + if( !strcmp( type, "USE" ) ) { + fprintf( file, "\t%s%s->use_interface_list_()->Append(is);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } else { + fprintf( file, "\t%s%s->ref_interface_list_()->Append(is);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } + } + + if( first_time ) { + first_time = false; + } + if( r->type == OBJ_TYPE ) { + sprintf( td_name, "%s", TYPEtd_name( ( Type )r->object ) ); + } else if( r->type == OBJ_FUNCTION ) { + sprintf( td_name, "/* Function not implemented */ 0" ); + } else if( r->type == OBJ_PROCEDURE ) { + sprintf( td_name, "/* Procedure not implemented */ 0" ); + } else if( r->type == OBJ_RULE ) { + sprintf( td_name, "/* Rule not implemented */ 0" ); + } else if( r->type == OBJ_ENTITY ) { + sprintf( td_name, "%s%s%s", + SCOPEget_name( ( ( Entity )r->object )->superscope ), + ENT_PREFIX, ENTITYget_name( ( Entity )r->object ) ); + } else { + sprintf( td_name, "/* %c from OBJ_? in expbasic.h not implemented */ 0", r->type ); + } + if( r->old != r->nnew ) { + fprintf( file, "\t// object %s AS %s\n", r->old->name, + r->nnew->name ); + if( !strcmp( type, "USE" ) ) { + fprintf( file, "\tui = new Used_item(\"%s\", %s, \"%s\", \"%s\");\n", r->schema->symbol.name, td_name, r->old->name, r->nnew->name ); + fprintf( file, "\tis->explicit_items_()->Append(ui);\n" ); + fprintf( file, "\t%s%s->interface_().explicit_items_()->Append(ui);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } else { + fprintf( file, "\tri = new Referenced_item(\"%s\", %s, \"%s\", \"%s\");\n", r->schema->symbol.name, td_name, r->old->name, r->nnew->name ); + fprintf( file, "\tis->explicit_items_()->Append(ri);\n" ); + fprintf( file, "\t%s%s->interface_().explicit_items_()->Append(ri);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } + } else { + fprintf( file, "\t// object %s\n", r->old->name ); + if( !strcmp( type, "USE" ) ) { + fprintf( file, "\tui = new Used_item(\"%s\", %s, \"\", \"%s\");\n", r->schema->symbol.name, td_name, r->nnew->name ); + fprintf( file, "\tis->explicit_items_()->Append(ui);\n" ); + fprintf( file, "\t%s%s->interface_().explicit_items_()->Append(ui);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } else { + fprintf( file, "\tri = new Referenced_item(\"%s\", %s, \"\", \"%s\");\n", r->schema->symbol.name, td_name, r->nnew->name ); + fprintf( file, "\tis->explicit_items_()->Append(ri);\n" ); + fprintf( file, "\t%s%s->interface_().explicit_items_()->Append(ri);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + } + } + LISTod + } + HASHdestroy( dict ); +} + +const char * +IdlEntityTypeName( Type t ) { + static char name [BUFSIZ]; + strcpy( name, TYPE_PREFIX ); + if( TYPEget_name( t ) ) { + strcpy( name, FirstToUpper( TYPEget_name( t ) ) ); + } else { + return TYPEget_ctype( t ); + } + return name; +} + +const char * +GetAggrElemType( const Type type ) { + Class_Of_Type class; + Type bt; + static char retval [BUFSIZ]; + + if( isAggregateType( type ) ) { + bt = TYPEget_nonaggregate_base_type( type ); + /* + bt = TYPEget_body(t)->base; + */ + if( isAggregateType( bt ) ) { + strcpy( retval, "ERROR_aggr_of_aggr" ); + } + + class = TYPEget_type( bt ); + + /* case TYPE_INTEGER: */ + if( class == Class_Integer_Type ) { /* return ( "IntAggregate" );*/ + strcpy( retval, "long" ); + } + + /* case TYPE_REAL: + case TYPE_NUMBER: */ + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) + /* return ( "RealAggregate" );*/ + { + strcpy( retval, "double" ); + } + + /* case TYPE_ENTITY: */ + if( class == Class_Entity_Type ) { + strcpy( retval, IdlEntityTypeName( bt ) ); + } + + + /* case TYPE_ENUM: */ + /* case TYPE_SELECT: */ + if( ( class == Class_Enumeration_Type ) + || ( class == Class_Select_Type ) ) { + /* + strcpy (retval, ClassName (TYPEget_name (bt))); + */ + strcpy( retval, TYPEget_ctype( bt ) ); + } + + /* case TYPE_LOGICAL: */ + if( class == Class_Logical_Type ) { + strcpy( retval, "Logical" ); + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + strcpy( retval, "Bool" ); + } + + /* case TYPE_STRING: */ + if( class == Class_String_Type ) { /* return("StringAggregate");*/ + strcpy( retval, "string" ); + } + + /* case TYPE_BINARY: */ + if( class == Class_Binary_Type ) { /* return("BinaryAggregate");*/ + strcpy( retval, "binary" ); + } + } + return retval; +} + +const char * +TYPEget_idl_type( const Type t ) { + Class_Of_Type class; + static char retval [BUFSIZ]; + + /* aggregates are based on their base type + case TYPE_ARRAY: + case TYPE_BAG: + case TYPE_LIST: + case TYPE_SET: + */ + + if( isAggregateType( t ) ) { + strcpy( retval, GetAggrElemType( t ) ); + + /* ///////////////////////// */ + /* case TYPE_ARRAY: */ + if( TYPEget_type( t ) == Class_Array_Type ) { + strcat( retval, "__array" ); + } + /* case TYPE_LIST: */ + if( TYPEget_type( t ) == Class_List_Type ) { + strcat( retval, "__list" ); + } + /* case TYPE_SET: */ + if( TYPEget_type( t ) == Class_Set_Type ) { + strcat( retval, "__set" ); + } + /* case TYPE_BAG: */ + if( TYPEget_type( t ) == Class_Bag_Type ) { + strcat( retval, "__bag" ); + } + return retval; + + /* //////////////////////// */ + } + + /* the rest is for things that are not aggregates */ + + class = TYPEget_type( t ); + + /* case TYPE_LOGICAL: */ + if( class == Class_Logical_Type ) { + return ( "Logical" ); + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + return ( "Boolean" ); + } + + /* case TYPE_INTEGER: */ + if( class == Class_Integer_Type ) { + return ( "SCLP23(Integer)" ); + } + /* return ("CORBA::Long");*/ + + /* case TYPE_REAL: + case TYPE_NUMBER: */ + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + return ( "SCLP23(Real)" ); + } + /* return ("CORBA::Double"); */ + + /* case TYPE_STRING: */ + if( class == Class_String_Type ) { + return ( "char *" ); + } + + /* case TYPE_BINARY: */ + if( class == Class_Binary_Type ) { + return ( AccessType( t ) ); + } + + /* case TYPE_ENTITY: */ + if( class == Class_Entity_Type ) { + /* better do this because the return type might go away */ + strcpy( retval, IdlEntityTypeName( t ) ); + strcat( retval, "_ptr" ); + return retval; + /* return ("SCLP23(Application_instance_ptr)"); */ + } + /* case TYPE_ENUM: */ + /* case TYPE_SELECT: */ + if( class == Class_Enumeration_Type ) { + strncpy( retval, EnumName( TYPEget_name( t ) ), BUFSIZ - 2 ); + + strcat( retval, " /*" ); + strcat( retval, IdlEntityTypeName( t ) ); + strcat( retval, "*/ " ); + /* strcat (retval, "_var");*/ + return retval; + } + if( class == Class_Select_Type ) { + return ( IdlEntityTypeName( t ) ); + } + + /* default returns undefined */ + return ( "SCLundefined" ); +} + +int Handle_FedPlus_Args( int i, char * arg ) { + if( ( ( char )i == 's' ) || ( ( char )i == 'S' ) ) { + multiple_inheritance = 0; + } + if( ( ( char )i == 'a' ) || ( ( char )i == 'A' ) ) { + old_accessors = 1; + } + if( ( char )i == 'L' ) { + print_logging = 1; + } + if( ( ( char )i == 'c' ) || ( ( char )i == 'C' ) ) { + corba_binding = 1; + } + return 0; +} + + +bool is_python_keyword(char * word) { + bool python_keyword = false; + if (strcmp(word,"class")==0) python_keyword = true; + return python_keyword; +} + +/****************************************************************** + ** Procedure: generate_attribute_name + ** Parameters: Variable a, an Express attribute; char *out, the C++ name + ** Description: converts an Express name into the corresponding C++ name + ** see relation to generate_dict_attr_name() DAS + ** Side Effects: + ** Status: complete 8/5/93 + ******************************************************************/ +char * +generate_attribute_name( Variable a, char * out ) { + char * temp, *p, *q; + int j; + temp = EXPRto_string( VARget_name( a ) ); + p = temp; + if( ! strncmp( StrToLower( p ), "self\\", 5 ) ) { + p = p + 5; + } + /* copy p to out */ + /* DAR - fixed so that '\n's removed */ + for( j = 0, q = out; j < BUFSIZ; p++ ) { + /* copy p to out, 1 char at time. Skip \n's and spaces, convert */ + /* '.' to '_', and convert to lowercase. */ + if( ( *p != '\n' ) && ( *p != ' ' ) ) { + if( *p == '.' ) { + *q = '_'; + } else { + *q = tolower( *p ); + } + j++; + q++; + } + } + free(temp); + // python generator : we should prevend an attr name to be a python reserved keyword + if (is_python_keyword(out)) strcat(out,"_"); + return out; +} + +char * +generate_attribute_func_name( Variable a, char * out ) { + generate_attribute_name( a, out ); + strncpy( out, CheckWord( StrToLower( out ) ), BUFSIZ ); + if( old_accessors ) { + out[0] = toupper( out[0] ); + } else { + out[strlen( out )] = '_'; + } + return out; +} + +/****************************************************************** + ** Procedure: generate_dict_attr_name + ** Parameters: Variable a, an Express attribute; char *out, the C++ name + ** Description: converts an Express name into the corresponding SCL + ** dictionary name. The difference between this and the + ** generate_attribute_name() function is that for derived + ** attributes the name will have the form . + ** where is the name of the parent containing the + ** attribute being derived and is the name of the + ** derived attribute. Both and may + ** contain underscores but and will be + ** separated by a period. generate_attribute_name() generates + ** the same name except and will be + ** separated by an underscore since it is illegal to have a + ** period in a variable name. This function is used for the + ** dictionary name (a string) and generate_attribute_name() + ** will be used for variable and access function names. + ** Side Effects: + ** Status: complete 8/5/93 + ******************************************************************/ +char * +generate_dict_attr_name( Variable a, char * out ) { + char * temp, *p, *q; + int j; + + temp = EXPRto_string( VARget_name( a ) ); + p = temp; + if( ! strncmp( StrToLower( p ), "self\\", 5 ) ) { + p = p + 5; + } + /* copy p to out */ + strncpy( out, StrToLower( p ), BUFSIZ ); + /* DAR - fixed so that '\n's removed */ + for( j = 0, q = out; j < BUFSIZ; p++ ) { + /* copy p to out, 1 char at time. Skip \n's, and convert to lc. */ + if( *p != '\n' ) { + *q = tolower( *p ); + j++; + q++; + } + } + + free( temp ); + return out; +} + +/****************************************************************** + ** Procedure: TYPEget_express_type (const Type t) + ** Parameters: const Type t -- type for attribute + ** Returns: a string which is the type as it would appear in Express + ** Description: supplies the type for error messages + and to register the entity + - calls itself recursively to create a description of + aggregate types + ** Side Effects: + ** Status: new 1/24/91 + ******************************************************************/ + +String +TYPEget_express_type( const Type t ) { + Class_Of_Type class; + Type bt; + char retval [BUFSIZ]; + char * n, * permval, * aggr_type; + + + /* 1. "DEFINED" types */ + /* case TYPE_ENUM: */ + /* case TYPE_ENTITY: */ + /* case TYPE_SELECT: */ + + if( ( n = TYPEget_name( t ) ) ) { + PrettyTmpName( n ); + } + + /* 2. "BASE" types */ + class = TYPEget_type( t ); + + /* case TYPE_LOGICAL: */ + if( ( class == Class_Boolean_Type ) || ( class == Class_Logical_Type ) ) { + return ( "Logical" ); + } + + /* case TYPE_INTEGER: */ + if( class == Class_Integer_Type ) { + return ( "Integer " ); + } + + /* case TYPE_REAL: + case TYPE_NUMBER: */ + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + return ( "Real " ); + } + + /* case TYPE_STRING: */ + if( class == Class_String_Type ) { + return ( "String " ) ; + } + + /* case TYPE_BINARY: */ + if( class == Class_Binary_Type ) { + return ( "Binary " ) ; + } + + /* AGGREGATES + case TYPE_ARRAY: + case TYPE_BAG: + case TYPE_LIST: + case TYPE_SET: + */ + if( isAggregateType( t ) ) { + bt = TYPEget_nonaggregate_base_type( t ); + class = TYPEget_type( bt ); + + /* case TYPE_ARRAY: */ + if( TYPEget_type( t ) == Class_Array_Type ) { + aggr_type = "Array"; + } + /* case TYPE_LIST: */ + if( TYPEget_type( t ) == Class_List_Type ) { + aggr_type = "List"; + } + /* case TYPE_SET: */ + if( TYPEget_type( t ) == Class_Set_Type ) { + aggr_type = "Set"; + } + /* case TYPE_BAG: */ + if( TYPEget_type( t ) == Class_Bag_Type ) { + aggr_type = "Bag"; + } + + sprintf( retval, "%s of %s", + aggr_type, TYPEget_express_type( bt ) ); + + /* this will declare extra memory when aggregate is > 1D */ + + permval = ( char * )malloc( strlen( retval ) * sizeof( char ) + 1 ); + strcpy( permval, retval ); + return permval; + + } + + /* default returns undefined */ + + printf( "WARNING2: type %s is undefined\n", TYPEget_name( t ) ); + return ( "SCLundefined" ); + +} + +/****************************************************************** + ** Procedure: ATTRsign_access_method + ** Parameters: const Variable a -- attribute to print + access method signature for + ** FILE* file -- file being written to + ** Returns: nothing + ** Description: prints the signature for an access method + ** based on the attribute type + ** DAS i.e. prints the header for the attr. access functions + ** (get and put attr value) in the entity class def in .h file + ** Side Effects: + ** Status: complete 17-Feb-1992 + ******************************************************************/ + +void +ATTRsign_access_methods( Variable a, FILE * file ) { + + Type t = VARget_type( a ); + Class_Of_Type class; + char ctype [BUFSIZ]; + char attrnm [BUFSIZ]; + + generate_attribute_func_name( a, attrnm ); + + /* + generate_attribute_name( a, attrnm ); + strncpy (attrnm, CheckWord (StrToLower (attrnm)), BUFSIZ); + if(old_accessors) + { + attrnm[0] = toupper(attrnm[0]); + } + else + { + attrnm[strlen(attrnm)] = '_'; + } + */ + + class = TYPEget_type( t ); + + if( corba_binding ) { + strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); + } else { + strncpy( ctype, AccessType( t ), BUFSIZ ); + } + if( corba_binding ) { + /* string, entity, and aggregate = no const */ + if( isAggregateType( t ) ) { + fprintf( file, "\t%s * %s(", ctype, attrnm ); + } else { + fprintf( file, "\t%s %s(", ctype, attrnm ); + } + fprintf( file, + "CORBA::Environment &IT_env=CORBA::default_environment) " ); + fprintf( file, + " /* const */ throw (CORBA::SystemException);\n" ); + if( ( class == Class_Enumeration_Type ) || + ( class == Class_Entity_Type ) || + ( class == Class_Boolean_Type ) || + ( class == Class_Logical_Type ) ) { + fprintf( file, "\tvoid %s (%s x", attrnm, ctype ); + } else if( isAggregateType( t ) ) { + fprintf( file, "\tvoid %s (const %s& x", attrnm, ctype ); + } else { + fprintf( file, "\tvoid %s (const %s x", attrnm, ctype ); + } + fprintf( file, + ", CORBA::Environment &IT_env=CORBA::default_environment)" ); + fprintf( file, + " throw (CORBA::SystemException);\n\n" ); + } else { + fprintf( file, "\tconst %s %s() const;\n", ctype, attrnm ); + fprintf( file, "\tvoid %s (const %s x);\n\n", attrnm, ctype ); + } + return; +} + +/****************************************************************** + ** Procedure: ATTRprint_access_methods_get_head + ** Parameters: const Variable a -- attribute to find the type for + ** FILE* file -- file being written + ** Type t - type of the attribute + ** Class_Of_Type class -- type name of the class + ** const char *attrnm -- name of the attribute + ** char *ctype -- (possibly returned) name of the attribute c++ type + ** Returns: name to be used for the type of the c++ access functions + ** Description: prints the access method get head based on the attribute type + ** DAS which being translated is it prints the function header + ** for the get attr value access function defined for an + ** entity class. This is the .cc file version. + ** Side Effects: + ** Status: complete 7/15/93 by DDH + ******************************************************************/ +void +ATTRprint_access_methods_get_head( const char * classnm, Variable a, + FILE * file ) { + Type t = VARget_type( a ); + char ctype [BUFSIZ]; /* return type of the get function */ + char funcnm [BUFSIZ]; /* name of member function */ + + generate_attribute_func_name( a, funcnm ); + /* + generate_attribute_name( a, funcnm ); + funcnm[0] = toupper(funcnm[0]); + */ + + /* ///////////////////////////////////////////////// */ + + if( corba_binding ) { + strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); + } else { + strncpy( ctype, AccessType( t ), BUFSIZ ); + } + if( corba_binding ) { + /* string, entity, and aggregate = no const */ + if( isAggregateType( t ) ) { + fprintf( file, "\n%s * \n%s::%s(", ctype, classnm, funcnm ); + } else { + fprintf( file, "\n%s \n%s::%s(", ctype, classnm, funcnm ); + } + fprintf( file, + "CORBA::Environment &IT_env) " ); + fprintf( file, + " /* const */ throw (CORBA::SystemException)\n" ); + } else { + fprintf( file, "\nconst %s \n%s::%s() const\n", ctype, classnm, funcnm ); + } + return; + /* ///////////////////////////////////////////////// */ +#if 0 + /* case STRING: */ + /* case TYPE_BINARY: */ + /* string can\'t be const because it causes problems with SELECTs */ + if( ( class == Class_String_Type ) || ( class == Class_Binary_Type ) ) { + if( corba_binding ) { + fprintf( file, "\nchar * \n%s::%s(", classnm, funcnm ); + fprintf( file, + "CORBA::Environment &IT_env) const " ); + fprintf( file, + "throw (CORBA::SystemException)\n" ); + } else { + fprintf( file, + "\nconst %s\n%s::%s() const\n", ctype, classnm, funcnm ); + } + return; + } + /* case ENTITY: */ + /* return value isn\'t const */ + if( class == Class_Entity_Type ) { + if( corba_binding ) { + fprintf( file, "\n%s\n%s::%s(", ctype, classnm, funcnm ); + fprintf( file, + "CORBA::Environment &IT_env) /* const */ " ); + fprintf( file, + "throw (CORBA::SystemException)\n" ); + } else { + fprintf( file, "\n%s\n%s::%s() const \n", ctype, classnm, funcnm ); + } + return; + } + + /* case TYPE_LOGICAL: */ + if( class == Class_Logical_Type ) { + if( corba_binding ) { + fprintf( file, "\nconst Logical\n%s::%s(", classnm, funcnm ); + fprintf( file, + "CORBA::Environment &IT_env) const throw (CORBA::SystemException)\n" ); + } else + fprintf( file, + "\nconst Logical \n%s::%s() const\n", classnm, funcnm ); + return; + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + if( corba_binding ) { + fprintf( file, "\nconst Boolean\n%s::%s(", classnm, funcnm ); + fprintf( file, + "CORBA::Environment &IT_env) const throw (CORBA::SystemException)\n" ); + } else + fprintf( file, + "\nconst Boolean\n%s::%s() const\n", classnm, funcnm ); + return; + } + + /* case TYPE_ENUM: */ + if( class == Class_Enumeration_Type ) { + sprintf( ctype, "%s ", EnumName( TYPEget_name( t ) ) ); + } + + + /* default: INTEGER and NUMBER */ + /* case TYPE_AGGRETATES: */ + /* case TYPE_SELECT: */ + /* case TYPE_ENTITY: */ + /* is the same type as the data member */ + fprintf( file, "\nconst %s\n%s::%s(", ctype, classnm, funcnm ); + if( corba_binding ) + fprintf( file, + "CORBA::Environment &IT_env) const throw (CORBA::SystemException)\n" ); + else { + fprintf( file, ") const\n" ); + } +#endif +} + +/****************************************************************** + ** Procedure: ATTRprint_access_methods_put_head + ** Parameters: const Variable a -- attribute to find the type for + ** FILE* file -- file being written to + ** Type t - type of the attribute + ** Class_Of_Type class -- type name of the class + ** const char *attrnm -- name of the attribute + ** char *ctype -- name of the attribute c++ type + ** Returns: name to be used for the type of the c++ access functions + ** Description: prints the access method put head based on the attribute type + ** DAS which being translated is it prints the function header + ** for the put attr value access function defined for an + ** entity class. This is the .cc file version. + ** Side Effects: + ** Status: complete 7/15/93 by DDH + ******************************************************************/ +void +ATTRprint_access_methods_put_head( CONST char * entnm, Variable a, FILE * file ) { + + Type t = VARget_type( a ); + char ctype [BUFSIZ]; + char funcnm [BUFSIZ]; + Class_Of_Type class = TYPEget_type( t ); + + generate_attribute_func_name( a, funcnm ); + /* + generate_attribute_name( a, funcnm ); + funcnm[0] = toupper(funcnm[0]); + */ + + /* ///////////////////////////////////////////////// */ + + if( corba_binding ) { + strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); + } else { + strncpy( ctype, AccessType( t ), BUFSIZ ); + } + if( corba_binding ) { + /* string, entity, and aggregate = no const */ + if( ( class == Class_Enumeration_Type ) || + ( class == Class_Entity_Type ) || + ( class == Class_Boolean_Type ) || + ( class == Class_Logical_Type ) ) { + fprintf( file, "\nvoid \n%s::%s (%s x", entnm, funcnm, ctype ); + } else if( isAggregateType( t ) ) { + fprintf( file, "\nvoid \n%s::%s (const %s& x", entnm, funcnm, ctype ); + } else { + fprintf( file, "\nvoid \n%s::%s (const %s x", entnm, funcnm, ctype ); + } + fprintf( file, + ", CORBA::Environment &IT_env)" ); + fprintf( file, + " throw (CORBA::SystemException)\n\n" ); + } else { + fprintf( file, "\nvoid \n%s::%s (const %s x)\n\n", entnm, funcnm, ctype ); + } + return; + /* ///////////////////////////////////////////////// */ +#if 0 + + /* case TYPE_LOGICAL: */ + if( class == Class_Logical_Type ) { + strcpy( ctype, "Logical" ); + } + + /* case TYPE_BOOLEAN: */ + if( class == Class_Boolean_Type ) { + strcpy( ctype, "Boolean" ); + } + + /* case TYPE_ENUM: */ + if( class == Class_Enumeration_Type ) { + strncpy( ctype, EnumName( TYPEget_name( t ) ), BUFSIZ ); + } + + + /* case STRING:*/ + if( class == Class_String_Type ) { + strcpy( ctype, "const char *" ); + } + + /* case TYPE_BINARY: */ + if( class == Class_Binary_Type ) { + sprintf( ctype, "const %s&", AccessType( t ) ); + } + + /* default: INTEGER and NUMBER */ + /* case TYPE_AGGRETATES: */ + /* case TYPE_ENTITY: */ + /* case TYPE_SELECT: */ + /* is the same type as the data member */ + fprintf( file, "\nvoid \n%s::%s (%s x", entnm, funcnm, ctype ); + if( corba_binding ) { + fprintf( file, ", CORBA::Environment &IT_env) \nthrow (CORBA::SystemException" ); + } + fprintf( file, ")\n" ); + +#endif + +} + +void +AGGRprint_access_methods( CONST char * entnm, Variable a, FILE * file, Type t, + char * ctype, char * attrnm ) { + char aggrnode_name [BUFSIZ]; + Type bt; + Class_Of_Type class = TYPEget_type( t ); + char nm [BUFSIZ]; + + ATTRprint_access_methods_get_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( !corba_binding ) { + fprintf( file, " return (%s) &_%s; \n}\n", ctype, attrnm ); + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "\t{ _%s.ShallowCopy (*x); }\n", attrnm ); + return; + } else { + bt = TYPEget_nonaggregate_base_type( t ); + if( isAggregateType( bt ) ) { + strcpy( aggrnode_name, "/* ERROR aggr_of_aggr */" ); + } + + fprintf( file, " %s * seq = new %s;\n\n", ctype, ctype ); + /* Part_version__set * seq = new Part_version__set;*/ + + fprintf( file, " int count = _%s.EntryCount();\n", attrnm ); + fprintf( file, " seq->length(count);\n\n" ); + + fprintf( file, " int i = 0;\n" ); + fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n\n", attrnm ); + + + class = TYPEget_type( bt ); + + if( class == Class_Integer_Type ) { + /* strcpy(aggrnode_name,"IntNode"); */ + fprintf( file, " while(n)\n" ); + fprintf( file, " {\n" ); + + fprintf( file, "\t(*seq)[i] = ((IntNode*)n)->value;\n" ); + fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr integer element: \" << ((IntNode*)n)->value << std::endl;\n", entnm, attrnm ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr integer element: \" << ((IntNode*)n)->value << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, " return seq;\n" ); + fprintf( file, "}\n" ); + } + + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + /* strcpy(aggrnode_name,"RealNode"); */ + fprintf( file, " while(n)\n" ); + fprintf( file, " {\n" ); + + fprintf( file, "\t(*seq)[i] = ((RealNode*)n)->value;\n" ); + fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr real element: \" << ((RealNode*)n)->value << std::endl;\n", entnm, attrnm ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + + fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr real element: \" << ((RealNode*)n)->value << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, " return seq;\n" ); + fprintf( file, "}\n" ); + } + + if( class == Class_Entity_Type ) { + /* strcpy(aggrnode_name,"EntityNode");*/ + fprintf( file, " int file_id = 0;\n" ); + fprintf( file, " char markerServer[BUFSIZ];\n" ); + fprintf( file, " while(n)\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tfile_id = ((EntityNode*)n)->node->STEPfile_id;\n" ); + fprintf( file, "\tstd::cout << \"StepFileId: \" << file_id;\n" ); + + fprintf( file, "\t// the marker:server is used\n" ); + fprintf( file, "\tsprintf(markerServer, \"%%d:%%s\", file_id, serverName);\n" ); + fprintf( file, "\tstd::cout << \" markerServer: \" << markerServer << std::endl;\n" ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr entity element w/file_id: \" << file_id << \" markerServer: \" << markerServer << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + if( TYPEget_name( bt ) ) { + strncpy( nm, FirstToUpper( TYPEget_name( bt ) ), BUFSIZ - 1 ); + } + fprintf( file, "\t(*seq)[i] = %s::_bind(markerServer, sclHostName);\n", nm ); + fprintf( file, + "/*\n\t%s_var x = %s::_bind((const char *)markerServer," + "sclHostName);\n", nm, nm ); + fprintf( file, + "\t%s::_duplicate(x);\n\n", nm ); + fprintf( file, "\t(*seq)[i] = x;\n*/\n" ); + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, " return seq;\n" ); + fprintf( file, "}\n" ); + /* ////////////////////////////////////////////////// */ + } + + if( ( class == Class_Enumeration_Type ) || + ( class == Class_Logical_Type ) || + ( class == Class_Boolean_Type ) ) { + /* strcpy(aggrnode_name,"EnumNode"); */ + fprintf( file, " while(n)\n" ); + fprintf( file, " {\n" ); + + fprintf( file, "\t(*seq)[i] = ((EnumNode*)n)->node->asInt();\n" ); + fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr enumeration/Boolean/Logical element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() ) << std::endl;\n", entnm, attrnm ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr enumeration/Boolean/Logical element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() ) << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, " return seq;\n" ); + fprintf( file, "}\n" ); + } + + if( class == Class_Select_Type ) { + strcpy( aggrnode_name, "SelectNode" ); + fprintf( file, " std::cout << \"ERROR function not implemented: entity %s, attr _%s: aggr select element: \" << std::endl;\n", entnm, attrnm ); + fprintf( file, " return 0;\n" ); + fprintf( file, "}\n" ); + } + + if( class == Class_String_Type ) { /* return("StringAggregate");*/ + /* strcpy(aggrnode_name,"StringNode");*/ + fprintf( file, " while(n)\n" ); + fprintf( file, " {\n" ); + + fprintf( file, "\t(*seq)[i] = CORBA::string_dupl( ((StringNode*)n)->value.c_str() );\n" ); + fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr string element: \" << ((StringNode*)n)->value.c_str() << std::endl;\n", entnm, attrnm ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr string element: \" << ((StringNode*)n)->value.c_str() << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, " return seq;\n" ); + fprintf( file, "}\n" ); + } + if( class == Class_Binary_Type ) { /* return("BinaryAggregate");*/ + strcpy( aggrnode_name, "BinaryNode" ); + fprintf( file, " std::cout << \"ERROR function not implemented: entity %s, attr _%s: aggr binary element: \" << std::endl;\n", entnm, attrnm ); + fprintf( file, " return 0;\n" ); + fprintf( file, "}\n" ); + } + /* ////////////////////////////////////// */ + ATTRprint_access_methods_put_head( entnm, a, file ); + + bt = TYPEget_nonaggregate_base_type( t ); + if( isAggregateType( bt ) ) { + strcpy( aggrnode_name, "/* ERROR aggr_of_aggr */" ); + } + + class = TYPEget_type( bt ); + + if( class == Class_Integer_Type ) { + /* ************************************** */ + if( TYPEget_name( bt ) ) { + strcpy( nm, "Sdai" ); + strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); + } + + fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); + fprintf( file, "{\n" ); + fprintf( file, " int countx = x.length();\n" ); + fprintf( file, " SingleLinkNode *trailn = 0;\n" ); + fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); + fprintf( file, " if( countx == 0 )\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\t_%s.Empty();\n", attrnm ); + fprintf( file, "\treturn;\n" ); + fprintf( file, " }\n\n" ); + fprintf( file, " int i = 0;\n" ); + fprintf( file, " while(i < countx)\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tif(n == 0)\n" ); + fprintf( file, "\t{\n" ); + fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); + fprintf( file, "\t _%s.AppendNode( (IntNode*)n );\n", attrnm ); + fprintf( file, "\t}\n" ); + fprintf( file, "\t((IntNode*)n)->value = x[i];\n"); + fprintf( file, "\tstd::cout << \"Assigning aggr int element: \" << ((IntNode*)n)->value;\n" ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr integer element: \" << ((IntNode*)n)->value << std::endl;\n", entnm, attrnm ); + + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\ttrailn = n;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "/*\n" ); + fprintf( file, " if(n)\n" ); + fprintf( file, "\t_%s.DeleteFollowingNodes((IntNode*)trailn);\n", attrnm ); + fprintf( file, "*/\n" ); + fprintf( file, "}\n" ); + /* ************************************** */ + } + + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + /* ************************************** */ + if( TYPEget_name( bt ) ) { + strcpy( nm, "Sdai" ); + strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); + } + + fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); + fprintf( file, "{\n" ); + fprintf( file, " int countx = x.length();\n" ); + fprintf( file, " SingleLinkNode *trailn = 0;\n" ); + fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); + fprintf( file, " if( countx == 0 )\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\t_%s.Empty();\n", attrnm ); + fprintf( file, "\treturn;\n" ); + fprintf( file, " }\n\n" ); + fprintf( file, " int i = 0;\n" ); + fprintf( file, " while(i < countx)\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tif(n == 0)\n" ); + fprintf( file, "\t{\n" ); + fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); + fprintf( file, "\t _%s.AppendNode( (RealNode*)n );\n", attrnm ); + fprintf( file, "\t}\n" ); + fprintf( file, "\t((RealNode*)n)->value = x[i];\n"); + fprintf( file, "\tstd::cout << \"Assigning aggr real element: \" << ((RealNode*)n)->value;\n" ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr real element: \" << ((RealNode*)n)->value << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + fprintf( file, "\ti++;\n" ); + fprintf( file, "\ttrailn = n;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "/*\n" ); + fprintf( file, " if(n)\n" ); + fprintf( file, "\t_%s.DeleteFollowingNodes((RealNode*)trailn);\n", attrnm ); + fprintf( file, "*/\n" ); + fprintf( file, "}\n" ); + /* ************************************** */ + } + + if( class == Class_Entity_Type ) { + /* strcpy(nm, TYPEget_name(bt)); + strcpy(nm, TYPEget_name + (TYPEget_nonaggregate_base_type (VARget_type (a)))); + */ + /* ************************************** */ + if( TYPEget_name( bt ) ) { + strcpy( nm, "Sdai" ); + strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); + } + + fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); + fprintf( file, "{\n" ); + fprintf( file, " int countx = x.length();\n" ); + fprintf( file, " SingleLinkNode *trailn = 0;\n" ); + fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); + fprintf( file, " if( countx > 0 )\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tif( n == 0 )\n" ); + fprintf( file, "\t{\n" ); + fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); + fprintf( file, "\t _%s.AppendNode( (EntityNode*)n );\n", attrnm ); + fprintf( file, "\t}\n" ); + fprintf( file, " }\n" ); + fprintf( file, " else\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\t_%s.Empty();\n", attrnm ); + fprintf( file, "\treturn;\n" ); + fprintf( file, " }\n\n" ); + fprintf( file, " int i = 0;\n" ); + fprintf( file, " while(i < countx)\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tif(n == 0)\n" ); + fprintf( file, "\t{\n" ); + fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); + fprintf( file, "\t _%s.AppendNode( (EntityNode*)n );\n", attrnm ); + fprintf( file, "\t}\n" ); + fprintf( file, "\t((EntityNode*)n)->node = (%s*)DEREF( x[i] );\n", nm ); + fprintf( file, "\tstd::cout << \"Assigning entity w/StepFileId: \" << ((EntityNode*)n)->node->STEPfile_id;\n" ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr entity element w/file_id: \" << ((EntityNode*)n)->node->STEPfile_id << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + + fprintf( file, "\ti++;\n" ); + fprintf( file, "\ttrailn = n;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "/*\n" ); + fprintf( file, " if(n)\n" ); + fprintf( file, "\t_%s.DeleteFollowingNodes((EntityNode*)trailn);\n", attrnm ); + fprintf( file, "*/\n" ); + fprintf( file, "}\n" ); + /* ************************************** */ + + } + + if( ( class == Class_Enumeration_Type ) || + ( class == Class_Logical_Type ) || + ( class == Class_Boolean_Type ) ) { + /* ************************************** */ + if( TYPEget_name( bt ) ) { + strcpy( nm, "Sdai" ); + strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); + } + + fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); + fprintf( file, "{\n" ); + fprintf( file, " int countx = x.length();\n" ); + fprintf( file, " SingleLinkNode *trailn = 0;\n" ); + fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); + fprintf( file, " if( countx == 0 )\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\t_%s.Empty();\n", attrnm ); + fprintf( file, "\treturn;\n" ); + fprintf( file, " }\n\n" ); + fprintf( file, " int i = 0;\n" ); + fprintf( file, " while(i < countx)\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tif(n == 0)\n" ); + fprintf( file, "\t{\n" ); + fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); + fprintf( file, "\t _%s.AppendNode( (EnumNode*)n );\n", attrnm ); + fprintf( file, "\t}\n" ); + fprintf( file, "\t((EnumNode*)n)->node->put( (int)x[i] );\n"); + fprintf( file, "\tstd::cout << \"Assigning aggr enum element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() );\n" ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr enumeration/Boolean/Logical element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() ) << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + fprintf( file, "\ti++;\n" ); + fprintf( file, "\ttrailn = n;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "/*\n" ); + fprintf( file, " if(n)\n" ); + fprintf( file, "\t_%s.DeleteFollowingNodes((EnumNode*)trailn);\n", attrnm ); + fprintf( file, "*/\n" ); + fprintf( file, "}\n" ); + /* ************************************** */ + } + + if( class == Class_Select_Type ) { + fprintf( file, "\t{ /*_%s.ShallowCopy (*x); */ }\n", attrnm ); + strcpy( aggrnode_name, "SelectNode" ); + } + + if( class == Class_String_Type ) { /* return("StringAggregate");*/ + /* ************************************** */ + if( TYPEget_name( bt ) ) { + strcpy( nm, "Sdai" ); + strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); + } + + fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); + fprintf( file, "{\n" ); + fprintf( file, " int countx = x.length();\n" ); + fprintf( file, " SingleLinkNode *trailn = 0;\n" ); + fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); + fprintf( file, " if( countx == 0 )\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\t_%s.Empty();\n", attrnm ); + fprintf( file, "\treturn;\n" ); + fprintf( file, " }\n\n" ); + fprintf( file, " int i = 0;\n" ); + fprintf( file, " while(i < countx)\n" ); + fprintf( file, " {\n" ); + fprintf( file, "\tif(n == 0)\n" ); + fprintf( file, "\t{\n" ); + fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); + fprintf( file, "\t _%s.AppendNode( (StringNode*)n );\n", attrnm ); + fprintf( file, "\t}\n" ); + fprintf( file, "\t((StringNode*)n)->value = x[i];\n"); + fprintf( file, "\tstd::cout << \"Assigning aggr string element: \" << ((StringNode*)n)->value.c_str();\n" ); + /* /////////////////////////////////////////// */ + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, "\tif(*logStream)\n\t{\n" ); + fprintf( file, + "\t logStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr string element: \" << ((StringNode*)n)->value.c_str() << std::endl;\n", entnm, attrnm ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, "\t}\n" ); + fprintf( file, "#endif\n" ); + } + /* /////////////////////////////////////////// */ + fprintf( file, "\ti++;\n" ); + fprintf( file, "\ttrailn = n;\n" ); + fprintf( file, "\tn = n->NextNode();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "/*\n" ); + fprintf( file, " if(n)\n" ); + fprintf( file, "\t_%s.DeleteFollowingNodes((EnumNode*)trailn);\n", attrnm ); + fprintf( file, "*/\n" ); + fprintf( file, "}\n" ); + /* ************************************** */ + } + if( class == Class_Binary_Type ) { /* return("BinaryAggregate");*/ + fprintf( file, "\t{ /*_%s.ShallowCopy (*x); */ }\n", attrnm ); + strcpy( aggrnode_name, "BinaryNode" ); + } + /* x-> x-> */ + /* ////////////////////////// */ + } + return; +} + +/****************************************************************** + ** Procedure: ATTRprint_access_method + ** Parameters: const Variable a -- attribute to find the type for + ** FILE* file -- file being written to + ** Returns: name to be used for the type of the c++ access functions + ** Description: prints the access method based on the attribute type + ** i.e. get and put value access functions defined in a class + ** generated for an entity. + ** Side Effects: + ** Status: complete 1/15/91 + ** updated 17-Feb-1992 to print to library file instead of header + ** updated 15-July-1993 to call the get/put head functions by DDH + ******************************************************************/ +void +ATTRprint_access_methods( CONST char * entnm, Variable a, FILE * file ) { + Type t = VARget_type( a ); + Class_Of_Type class; + char ctype [BUFSIZ]; /* type of data member */ + char attrnm [BUFSIZ]; + char membernm[BUFSIZ]; + char funcnm [BUFSIZ]; /* name of member function */ + + char nm [BUFSIZ]; + /* I believe nm has the name of the underlying type without Sdai in + front of it */ + if( TYPEget_name( t ) ) { + strncpy( nm, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - 1 ); + } + + generate_attribute_func_name( a, funcnm ); + /* + generate_attribute_name( a, funcnm ); + funcnm[0] = toupper(funcnm[0]); + */ + + generate_attribute_name( a, attrnm ); + strcpy( membernm, attrnm ); + membernm[0] = toupper( membernm[0] ); + class = TYPEget_type( t ); + /* strncpy (ctype, TYPEget_ctype (t), BUFSIZ);*/ + if( corba_binding ) { + strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); + } else { + strncpy( ctype, AccessType( t ), BUFSIZ ); + } + + if( isAggregate( a ) ) { + AGGRprint_access_methods( entnm, a, file, t, ctype, attrnm ); + return; + } + ATTRprint_access_methods_get_head( entnm, a, file ); + + /* case TYPE_ENTITY: */ + if( class == Class_Entity_Type ) { + + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tlogStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\tif(! (_%s == S_ENTITY_NULL) )\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"reference to Sdai%s entity #\" << _%s->STEPfile_id << std::endl;\n", + nm, attrnm ); + /* funcnm, attrnm);*/ + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"null entity\" << std::endl;\n\t}\n" ); + fprintf( file, "\tlogStream->close();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "#endif\n" ); + /* fprintf (file, " return (%s) _%s;\n}\n", ctype, attrnm); */ + } + if( corba_binding ) { + if( TYPEget_name( t ) ) { + strncpy( nm, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - 1 ); + } + + /* fprintf (file, "{\n if(_%s != 0)\n {\n", attrnm); */ + fprintf( file, " if(_%s != 0)\n {\n", attrnm ); + fprintf( file, "\ttry\n\t{\n" ); + fprintf( file, + "\t const char *hostName = CORBA::Orbix.myHost();\n" ); + fprintf( file, + "\t char markerServer[64];\n" ); + fprintf( file, + "\t sprintf(markerServer, \"%%d:%%s\", _%s->" + "STEPfile_id, serverName);\n\n", attrnm ); + fprintf( file, + "\t std::cout << \"*****\" << markerServer << std::endl;\n\n" ); + fprintf( file, + "\t %s_var x = %s::_bind((const char *)markerServer," + "hostName);\n", nm, nm ); + fprintf( file, + "\t %s::_duplicate(x);\n\n", nm ); + fprintf( file, + "\t std::cout << std::endl << \"x->_refCount(): \" << x->" + "_refCount();\n" ); + fprintf( file, + "\t std::cout << std::endl << \"STEPfile id inside _%s's get " + "function is: \" \n", attrnm ); + fprintf( file, + "\t\t << _%s->STEPfile_id << std::endl;\n", attrnm ); + fprintf( file, + "\t std::cout << \"x's marker name in server's " + "implementation object's attr _%s's get function is: " + "'\" \n", attrnm ); + fprintf( file, + "\t\t << x->_marker() << \"'\" << std::endl << std::endl;\n" ); + fprintf( file, "\t return x;\n\t}\n" ); + fprintf( file, + "\tcatch (CORBA::SystemException &se) {\n" ); + fprintf( file, + "\t std::cerr << \"Unexpected system exception in _%s's " + "get funct: \" << &se;\n", attrnm ); + fprintf( file, + "\t throw;\n" ); + fprintf( file, + "\t}\n\tcatch(...) {\n" ); + fprintf( file, + "\t std::cerr << \"Caught Unknown Exception in _%s's get " + "funct!\" << std::endl;\n", attrnm ); + fprintf( file, + "\t throw;\n\t}\n" ); + + /* + fprintf (file, "\t%s_ptr x = new TIE_%s(Sdai%s) ((Sdai%s*)_%s);\n", + nm, nm, nm, nm, attrnm); + fprintf (file, "\t%s::_duplicate(x);\n", nm); + fprintf (file, "\tstd::cout << \"STEPfile id is: \" << _%s->STEPfile_id << std::endl;\n", attrnm); + */ + fprintf( file, " }\n" ); + fprintf( file, " else\n" ); + fprintf( file, "\tstd::cout << \"nil object ref in attr _%s's put " + "funct\" << std::endl;\n", attrnm ); + fprintf( file, " return %s::_nil();\n}\n", nm ); + } else + /* fprintf (file, "\t{ return (%s) _%s; }\n", ctype, attrnm);*/ + { + fprintf( file, " return (%s) _%s; \n}\n", ctype, attrnm ); + } + + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "\n" ); + /* fprintf (file, "{\n"); */ + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tlogStream->open(SCLLOGFILE,ios::app);\n" ); + + if( corba_binding ) { + fprintf( file, "\tif(x && !((Sdai%s*)(DEREF(x)) == S_ENTITY_NULL) )\n\t{\n", nm ); + } else { + fprintf( file, "\tif(! (x == S_ENTITY_NULL) )\n\t{\n" ); + } + + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", + entnm, funcnm ); + + if( corba_binding ) + fprintf( file, + "\t *logStream << \"reference to Sdai%s entity #\" << ((Sdai%s*)(DEREF(x)))->STEPfile_id << std::endl;\n", + nm, nm ); + else + fprintf( file, + "\t *logStream << \"reference to Sdai%s entity #\" << x->STEPfile_id << std::endl;\n", + nm ); + + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"null entity\" << std::endl;\n\t}\n" ); + fprintf( file, "\tlogStream->close();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "#endif\n" ); + /* fprintf (file, " _%s = x; \n}\n", attrnm ); */ + } + if( corba_binding ) { + fprintf( file, "\n" ); + fprintf( file, " _%s = (Sdai%s*)(DEREF(x)); \n", attrnm, nm ); + fprintf( file, " if(_%s)\n {\n", attrnm ); + fprintf( file, "\tstd::cout << \"STEPfile id inside _%s's put function is: \"\n", attrnm ); + fprintf( file, "\t << _%s->STEPfile_id << std::endl;\n", attrnm ); + fprintf( file, " }\n else\n" ); + fprintf( file, "\tstd::cout << \"nil object ref in _%s's put funct\" << std::endl;\n", attrnm ); + fprintf( file, "}\n" ); + } else { + fprintf( file, " _%s = x; \n}\n", attrnm ); + } + /* fprintf (file, "\t{ _%s = x; }\n", attrnm ); */ + + return; + } + /* case TYPE_LOGICAL: */ + if( ( class == Class_Boolean_Type ) || ( class == Class_Logical_Type ) ) { + + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tlogStream->open(SCLLOGFILE,ios::app);\n" ); + fprintf( file, "\tif(!_%s.is_null())\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << _%s.element_at(_%s.asInt()) << std::endl;\n", + attrnm, attrnm ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n" ); + fprintf( file, "\t logStream->close();\n" ); + fprintf( file, " }\n" ); + fprintf( file, "#endif\n" ); + /* fprintf (file, "\t{ return (const PSDAI::LOGICAL&) _%s; }\n", attrnm);*/ + } + if( corba_binding ) { + if( class == Class_Boolean_Type ) { + fprintf( file, " return (Boolean) _%s;\n}\n", attrnm ); + } else if( class == Class_Logical_Type ) { + fprintf( file, " return (Logical) _%s;\n}\n", attrnm ); + } + } else { + fprintf( file, " return (%s) _%s;\n}\n", ctype, attrnm ); + } + + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\t*logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t*logStream << _%s.element_at(x) << std::endl;\n", attrnm ); + fprintf( file, " }\n" ); + fprintf( file, "#endif\n" ); + + /* fprintf (file, "\t{ return (const PSDAI::LOGICAL&) _%s; }\n", attrnm);*/ + /* fprintf (file, " _%s.put (x); \n}\n", attrnm ); */ + } + fprintf( file, " _%s.put (x); \n}\n", attrnm ); + return; + } + /* case TYPE_ENUM: */ + if( class == Class_Enumeration_Type ) { + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!_%s.is_null())\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << _%s.element_at(_%s.asInt()) << std::endl;\n", + attrnm, attrnm ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + /* fprintf (file, "\t{ return (const %s&) _%s; }\n", ctype, attrnm);*/ + /* fprintf (file, " return (%s) _%s; \n}\n", */ + /* EnumName (TYPEget_name (t)), attrnm); */ + } + fprintf( file, " return (%s) _%s; \n}\n", + EnumName( TYPEget_name( t ) ), attrnm ); + + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\t*logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t*logStream << _%s.element_at(x) << std::endl;\n", attrnm ); + fprintf( file, " }\n" ); + fprintf( file, "#endif\n" ); + + /* fprintf (file, "\t{ return (const PSDAI::LOGICAL&) _%s; }\n", attrnm);*/ + /* fprintf (file, " _%s.put (x); \n}\n", attrnm ); */ + } + fprintf( file, " _%s.put (x); \n}\n", attrnm ); + return; + } + /* case TYPE_SELECT: */ + if( class == Class_Select_Type ) { + fprintf( file, "\t{ return (const %s) &_%s; }\n", ctype, attrnm ); + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "\t{ _%s = x; }\n", attrnm ); + return; + } + /* case TYPE_AGGRETATES: */ + /* handled in AGGRprint_access_methods(entnm, a, file, t, ctype, attrnm) */ + + + /* case STRING:*/ + /* case TYPE_BINARY: */ + if( ( class == Class_String_Type ) || ( class == Class_Binary_Type ) ) { + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!_%s.is_null())\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << _%s.c_str() << std::endl;\n", attrnm ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + + /* fprintf (file, "\t{ return (%s) _%s; }\n", ctype, attrnm);*/ + /* fprintf (file, " return (const %s) _%s; \n}\n", ctype, attrnm); */ + /*DASSTR fprintf (file, "\t{ return (const %s&) _%s; }\n", ctype, attrnm);*/ + } + if( corba_binding ) { + fprintf( file, " return CORBA::string_dupl(_%s); \n}\n", attrnm ); + } else { + fprintf( file, " return (const %s) _%s; \n}\n", ctype, attrnm ); + } + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!x)\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << x << std::endl;\n" ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + + /* fprintf (file, " _%s = x; \n}\n", attrnm ); */ + } + fprintf( file, " _%s = x; \n}\n", attrnm ); + return; + } + /* case TYPE_INTEGER: */ + if( class == Class_Integer_Type ) { + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!(_%s == S_INT_NULL) )\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << _%s << std::endl;\n", attrnm ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + } + /* default: INTEGER */ + /* is the same type as the data member */ + fprintf( file, " return (const %s) _%s; \n}\n", ctype, attrnm ); + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!(x == S_INT_NULL) )\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << x << std::endl;\n" ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + /* default: INTEGER */ + /* is the same type as the data member */ + } + fprintf( file, " _%s = x; \n}\n", attrnm ); + } + + /* case TYPE_REAL: + case TYPE_NUMBER: */ + if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!(_%s == S_REAL_NULL) )\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << _%s << std::endl;\n", attrnm ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + } + fprintf( file, " return (const %s) _%s; \n}\n", ctype, attrnm ); + ATTRprint_access_methods_put_head( entnm, a, file ); + fprintf( file, "{\n" ); + if( print_logging ) { + fprintf( file, "#ifdef SCL_LOGGING\n" ); + fprintf( file, " if(*logStream)\n {\n" ); + fprintf( file, "\tif(!(_%s == S_REAL_NULL) )\n\t{\n", attrnm ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << _%s << std::endl;\n", attrnm ); + fprintf( file, "\t}\n\telse\n\t{\n" ); + fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", + entnm, funcnm ); + fprintf( file, + "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); + fprintf( file, "#endif\n" ); + } + fprintf( file, " _%s = x; \n}\n", attrnm ); + } +} + +/****************************************************************** +** Entity Generation */ + +/****************************************************************** + ** Procedure: ENTITYhead_print + ** Parameters: const Entity entity + ** FILE* file -- file being written to + ** Returns: + ** Description: prints the beginning of the entity class definition for the + ** c++ code and the declaration of extern attr descriptors for + ** the registry. In the .h file + ** Side Effects: generates c++ code + ** Status: good 1/15/91 + ** added registry things 12-Apr-1993 + ******************************************************************/ + +void +ENTITYhead_print( Entity entity, FILE * file, Schema schema ) { + char entnm [BUFSIZ]; + char attrnm [BUFSIZ]; + Linked_List list; + int attr_count_tmp = attr_count; + Entity super = 0; + + strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); + + /* DAS print all the attr descriptors and inverse attr descriptors for an + entity as extern defs in the .h file. */ + LISTdo( ENTITYget_attributes( entity ), v, Variable ) + generate_attribute_name( v, attrnm ); + fprintf( file, "extern %s *%s%d%s%s;\n", + ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), + ATTR_PREFIX, attr_count_tmp++, + ( VARis_derived( v ) ? "D" : ( VARis_type_shifter( v ) ? "R" : ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm ); + + /* **** testing the functions **** */ + /* + if( !(VARis_derived(v) && + VARget_initializer(v) && + VARis_type_shifter(v) && + VARis_overrider(entity, v)) ) + fprintf(file,"// %s Attr is not derived, a type shifter, overrider, no initializer.\n",attrnm); + + if(VARis_derived (v)) + fprintf(file,"// %s Attr is derived\n",attrnm); + if (VARget_initializer (v)) + fprintf(file,"// %s Attr has an initializer\n",attrnm); + if(VARis_type_shifter (v)) + fprintf(file,"// %s Attr is a type shifter\n",attrnm); + if(VARis_overrider (entity, v)) + fprintf(file,"// %s Attr is an overrider\n",attrnm); + */ + /* ****** */ + + LISTod + + fprintf( file, "\nclass %s : ", entnm ); + + /* inherit from either supertype entity class or root class of + all - i.e. SCLP23(Application_instance) */ + + if( multiple_inheritance ) { + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + super = ( Entity )LISTpeek_first( list ); + } + } else { /* the old way */ + super = ENTITYput_superclass( entity ); + } + + if( super ) { + fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); + } else { + fprintf( file, " public SCLP23(Application_instance) {\n" ); + } + +#if 0 + /* this code is old non-working multiple inheritance code */ + + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + LISTdo( list, e, Entity ) + /* if there\'s no super class yet, + or the super class doesn\'t have any attributes + */ + if( ( ! super ) || ( ! ENTITYhas_explicit_attributes( super ) ) ) { + super = e; + ++ super_cnt; + } else { + printf( "WARNING: multiple inheritance not implemented.\n" ); + printf( "\tin ENTITY %s\n\tSUPERTYPE %s IGNORED.\n\n", + ENTITYget_name( entity ), ENTITYget_name( e ) ); + } + LISTod; + fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); + + /* for multiple inheritance + LISTdo (list, e, Entity) + sprintf (buf, " public %s, ", ENTITYget_classname (e)); + move (buf); + LISTod; + sprintf (buf - 2, " {\n"); + move (buf); + fprintf(file,buffer); + */ + } else { /* if entity has no supertypes, it's at top of hierarchy */ + fprintf( file, " public SCLP23(Application_instance) {\n" ); + } +#endif + +} + +/****************************************************************** + ** Procedure: DataMemberPrint + ** Parameters: const Entity entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: prints out the data members for an entity's c++ class + ** definition + ** Side Effects: generates c++ code + ** Status: ok 1/15/91 + ******************************************************************/ + +void +DataMemberPrint( Entity entity, FILE * file, Schema schema ) { + Linked_List attr_list; + char entnm [BUFSIZ]; + char attrnm [BUFSIZ]; + + const char * ctype, * etype; + + strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm */ + + /* print list of attributes in the protected access area */ + + fprintf( file, " protected:\n" ); + + attr_list = ENTITYget_attributes( entity ); + LISTdo( attr_list, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + ctype = TYPEget_ctype( VARget_type( a ) ); + generate_attribute_name( a, attrnm ); + if( !strcmp( ctype, "SCLundefined" ) ) { + printf( "WARNING: in entity %s:\n", ENTITYget_name( entity ) ); + printf( "\tthe type for attribute %s is not fully implemented\n", attrnm ); + } + if( TYPEis_entity( VARget_type( a ) ) ) { + fprintf( file, "\tSCLP23(Application_instance_ptr) _%s ;", attrnm ); + } else { + fprintf( file, "\t%s _%s ;", ctype, attrnm ); + } + if( VARget_optional( a ) ) { + fprintf( file, " // OPTIONAL" ); + } + if( isAggregate( a ) ) { + /* if it's a named type, comment the type */ + if( ( etype = TYPEget_name + ( TYPEget_nonaggregate_base_type( VARget_type( a ) ) ) ) ) { + fprintf( file, "\t // of %s\n", etype ); + } + } + + fprintf( file, "\n" ); + } + + LISTod; +} + +/****************************************************************** + ** Procedure: MemberFunctionSign + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: prints the signature for member functions + of an entity's class definition + ** DAS prints the end of the entity class def and the creation + ** function that the EntityTypeDescriptor uses. + ** Side Effects: prints c++ code to a file + ** Status: ok 1/1/5/91 + ** updated 17-Feb-1992 to print only the signature + and not the function definitions + ******************************************************************/ + +void +MemberFunctionSign( Entity entity, FILE * file ) { + + Linked_List attr_list; + static int entcode = 0; + char entnm [BUFSIZ]; + + /* added for calling multiple_inheritance */ + Linked_List parent_attr_list; + Linked_List parent_list; + int super_cnt = 0; + + strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm */ + + fprintf( file, " public: \n" ); + + /* put in member functions which belong to all entities */ + /* constructor: */ + fprintf( file, "\n %s ( ); \n", entnm ); + + fprintf( file, "\t%s (SCLP23(Application_instance) *se, int *addAttrs = 0); \n", entnm ); + /* copy constructor*/ + fprintf( file, " %s (%s& e ); \n", entnm, entnm ); + /* destructor: */ + fprintf( file, " ~%s ();\n", entnm ); + + /* fprintf (file, " char *Name () { return \"%s\"; }\n", */ + /* PrettyTmpName (ENTITYget_name (entity)));*/ + fprintf( file, " int opcode () { return %d ; } \n", + entcode++ ); + + /* print signature of access functions for attributes */ + attr_list = ENTITYget_attributes( entity ); + LISTdo( attr_list, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + + /* retrieval and assignment */ + ATTRsign_access_methods( a, file ); + } + + LISTod; + + /* //////////////// */ + if( multiple_inheritance ) { + /* could print out access functions for parent attributes not + inherited through C++ inheritance. */ + parent_list = ENTITYget_supertypes( entity ); + if( ! LISTempty( parent_list ) ) { + + LISTdo( parent_list, e, Entity ) + /* if there\'s no super class yet, + or the super class doesn\'t have any attributes + */ + + __attribute__( ( unused ) ) Entity super = e; + super_cnt++; + if( super_cnt == 1 ) { + /* ignore the 1st parent */ + fprintf( file, + "\t/* The first parent's access functions are */\n%s\n", + "\t/* above or covered by inherited functions. */" ); + } else { + fprintf( file, "\n#if 0\n" ); + /* printf("\tin ENTITY %s\n\tadding SUPERTYPE %s\'s member functions. 1\n\n", + ENTITYget_name (entity), ENTITYget_name (e));*/ + + parent_attr_list = ENTITYget_attributes( e ); + LISTdo( parent_attr_list, a2, Variable ) + /* do for EXPLICIT, REDEFINED, and INVERSE attributes - but not DERIVED */ + if( ! VARis_derived( a2 ) ) { + + /* retrieval and assignment */ + ATTRsign_access_methods( a2, file ); + } + LISTod; + fprintf( file, "\n#endif\n" ); + } + LISTod; + } + } + /* //////////////// */ + if( corba_binding ) { + fprintf( file, "\n//\t%s_ptr create_TIE();\n\tIDL_Application_instance_ptr create_TIE();\n", + ENTITYget_CORBAname( entity ) ); + /* + fprintf(file, "\n//\t%s_ptr create_TIE();\n\tP26::Application_instance_ptr create_TIE();\n", + ENTITYget_CORBAname(entity)); + */ + } + fprintf( file, "};\n" ); + if( corba_binding ) { + fprintf( file, "\n// Associate IDL interface generated code with implementation object\nDEF_TIE_%s(%s)\n", ENTITYget_CORBAname( entity ), entnm ); + } + + /* print creation function for class */ + fprintf( file, "\n#if defined(__O3DB__)\n" ); + fprintf( file, "inline SCLP23(Application_instance_ptr) \ncreate_%s () { return (SCLP23(Application_instance_ptr)) new %s ; }\n", + entnm, entnm ); + fprintf( file, "#else\n" ); + fprintf( file, "inline %s *\ncreate_%s () { return new %s ; }\n", + entnm, entnm, entnm ); + fprintf( file, "#endif\n" ); + +} + +/****************************************************************** + ** Procedure: LIBdescribe_entity (entity, file, schema) + ** Parameters: Entity entity -- entity being processed + ** FILE* file -- file being written to + ** Schema schema -- schema being processed + ** Returns: + ** Description: declares the global pointer to the EntityDescriptor + representing a particular entity + ** DAS also prints the attr descs and inverse attr descs + ** This function creates the storage space for the externs defs + ** that were defined in the .h file. These global vars go in + ** the .cc file. + ** Side Effects: prints c++ code to a file + ** Status: ok 12-Apr-1993 + ******************************************************************/ +char * +GetAttrTypeName(Type t) { + char * attr_type; + if (TYPEis_string(t)) + { + attr_type = "STRING"; + } + else if (TYPEis_logical(t)) + { + attr_type = "LOGCIAL"; + } + else if (TYPEis_boolean(t)) + { + attr_type = "BOOLEAN"; + } + else if (TYPEis_real(t)) + { + attr_type = "REAL"; + } + else if (TYPEis_integer(t)) + { + attr_type = "INTEGER"; + } + else + { + attr_type = TYPEget_name(t); + } + return attr_type; +} + +/* +* +* A recursive function to export aggregate to python +* +*/ +void +process_aggregate (FILE *file, Type t) { + Expression lower = AGGR_TYPEget_lower_limit(t); + char *lower_str = EXPRto_string(lower); + Expression upper = AGGR_TYPEget_upper_limit(t); + char *upper_str = NULL; + if (upper == LITERAL_INFINITY) { + upper_str = "None"; + } + else { + upper_str = EXPRto_string(upper); + } + switch(TYPEget_body( t )->type) { + case array_: + fprintf(file,"ARRAY"); + break; + case bag_: + fprintf(file,"BAG"); + break; + case set_: + fprintf(file,"SET"); + break; + case list_: + fprintf(file,"LIST"); + break; + default: + break; + } + fprintf(file,"(%s,%s,",lower_str,upper_str); + //write base type + Type base_type = TYPEget_base_type(t); + if (TYPEis_aggregate(base_type)) { + process_aggregate(file,base_type); + fprintf(file,")"); //close parenthesis + } + else { + char * array_base_type = GetAttrTypeName(TYPEget_base_type(t)); + fprintf(file,"%s)",array_base_type); + } + +} + +void +LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { + int attr_count_tmp = attr_count;//, attr_count_tmp2 = 0; + char attrnm [BUFSIZ], parent_attrnm[BUFSIZ]; + char * attr_type; + bool generate_constructor = true; //by default, generates a python constructor + bool inheritance = false; + Type t; + /* class name + need to use new-style classes for properties to work correctly + so class must inherit from object */ + if (is_python_keyword(ENTITYget_name(entity))) {fprintf(file,"class %s_(",ENTITYget_name(entity));} + else {fprintf(file,"class %s(",ENTITYget_name(entity));} + + /* + * Look for inheritance and super classes + */ + Linked_List list; + list = ENTITYget_supertypes( entity ); + int num_parent = 0; + if( ! LISTempty( list ) ) { + inheritance = true; + LISTdo( list, e, Entity ) + /* if there\'s no super class yet, + or the super class doesn\'t have any attributes + */ + if (num_parent > 0) fprintf(file,","); //separator for parent classes names + if (is_python_keyword(ENTITYget_name(e))) {fprintf(file,"%s_",ENTITYget_name(e));} + else {fprintf(file,"%s",ENTITYget_name(e));} + //fprintf( file, "\t/* parent: %s */\n", ENTITYget_name( e ) ); + num_parent++; + LISTod; + } + else { + //inherit from BaeEntityClass by default, in order to enable decorators + // as well as advanced __repr__ feature + fprintf(file,"BaseEntityClass"); + } + fprintf(file,"):\n"); + /* + * Write docstrings in a Sphinx compliant manner + */ + fprintf(file,"\t'''Entity %s definition.\n",ENTITYget_name(entity)); + LISTdo(ENTITYget_attributes( entity ), v, Variable) + generate_attribute_name( v, attrnm ); + t = VARget_type( v ); + fprintf(file,"\n\t:param %s\n",attrnm); + fprintf(file,"\t:type %s:%s\n",attrnm, GetAttrTypeName(t)); + attr_count_tmp++; + LISTod + fprintf(file,"\t'''\n"); + /* + * Before writing constructor, check if this entity has any attribute + * other wise just a 'pass' statement is enough + */ + attr_count_tmp = 0;//attr_count; + int num_derived_inverse_attr = 0; + LISTdo(ENTITYget_attributes( entity ), v, Variable) + if (VARis_derived(v) || VARget_inverse(v)) { + num_derived_inverse_attr++; + } + else { + attr_count_tmp++; + } + LISTod + if ((attr_count_tmp == 0) && !inheritance) { + fprintf(file,"\t# This class does not define any attribute.\n"); + fprintf(file,"\tpass\n"); + generate_constructor = false; + } + if (false) {} + else { + /* + * write class constructor + */ + if (generate_constructor) { + fprintf(file,"\tdef __init__( self , "); + } + // if inheritance, first write the inherited parameters + list = ENTITYget_supertypes( entity ); + int num_parent = 0, index_attribute = 0; + if( ! LISTempty( list ) ) { + LISTdo( list, e, Entity ) + //num_attributes = get_local_attribute_number(e); //number of attributes for the current superclass + //index_attribute = 0; + /* search attribute names for superclass */ + LISTdo(ENTITYget_attributes( e ), v2, Variable) + //if (index_attributeinitializer ); + fprintf(file,"\t\t\treturn EvalDerivedAttribute(self,'''%s''')\n",expression_string); + free( expression_string ); + } + // fset + fprintf(file,"\t\tdef fset( self, value ):\n"); + t = VARget_type( v ); + attr_type = GetAttrTypeName(t); + + if (!VARis_derived(v) && !VARget_inverse(v)) { + // if the argument is not optional + if (!VARget_optional(v)) { + fprintf(file, "\t\t# Mandatory argument\n"); + fprintf(file,"\t\t\tif value==None:\n"); + fprintf(file,"\t\t\t\traise AssertionError('Argument %s is mantatory and can not be set to None')\n",attrnm); + } + else { + fprintf(file,"\t\t\tif value != None: # OPTIONAL attribute\n\t"); + } + // check wether attr_type is aggr or explicit + if( TYPEis_aggregate( t ) ) { + fprintf(file,"\t\t\tcheck_type(value,"); + process_aggregate(file,t); + fprintf(file,")\n"); + } + else { + fprintf(file,"\t\t\tcheck_type(value,"); + //printf(attr_type); + //is_python_keyword(attr_type);// printf("pou"); + fprintf(file,"%s)\n",attr_type); + } + fprintf(file,"\t\t\tself._%s = value\n",attrnm); + } + // if the attribute is derived, prevent fset to attribute to be set + else if (VARis_derived(v)){ + fprintf(file,"\t\t# DERIVED argument\n"); + fprintf(file,"\t\t\traise AssertionError('Argument %s is DERIVED. It is computed and can not be set to any value')\n",attrnm); + } + else if (VARget_inverse(v)) { + fprintf(file,"\t\t# INVERSE argument\n"); + fprintf(file,"\t\t\traise AssertionError('Argument %s is INVERSE. It is computed and can not be set to any value')\n",attrnm); + } + fprintf(file,"\t\treturn property(**locals())\n"); + LISTod + } +} + + +/****************************************************************** + ** Procedure: ENTITYinc_print + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: drives the generation of the c++ class definition code + ** Side Effects: prints segment of the c++ .h file + ** Status: ok 1/15/91 + ******************************************************************/ +/* +void +ENTITYinc_print( Entity entity, FILE * file, Schema schema ) { + ENTITYhead_print( entity, file, schema ); + DataMemberPrint( entity, file, schema ); + MemberFunctionSign( entity, file ); +} +*/ +/****************************************************************** + ** Procedure: LIBcopy_constructor + ** Parameters: + ** Returns: + ** Description: + ** Side Effects: + ** Status: not used 17-Feb-1992 + ******************************************************************/ +void +LIBcopy_constructor( Entity ent, FILE * file ) { + Linked_List attr_list; + Class_Of_Type class; + Type t; + char buffer [BUFSIZ], + attrnm[BUFSIZ], + *b = buffer; + int count = attr_count; + + String entnm = ENTITYget_classname( ent ); + __attribute__( ( unused ) ) bool opt; + const char * StrToLower( const char * word ); + + /*mjm7/10/91 copy constructor definition */ + fprintf( file, "\t%s::%s(%s& e ) \n", entnm, entnm, entnm ); + fprintf( file, " {" ); + + /* attributes */ + attr_list = ENTITYget_attributes( ent ); + LISTdo( attr_list, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + /* include attribute if it is not derived */ + generate_attribute_name( a, attrnm ); + t = VARget_type( a ); + class = TYPEget_type( t ); + opt = VARget_optional( a ); + + /* 1. initialize everything to NULL (even if not optional) */ + + /* default: to intialize attribute to NULL */ + sprintf( b, "\t_%s = e.%s();\n", attrnm, attrnm ); + + /*mjm7/11/91 case TYPE_STRING */ + if( ( class == Class_String_Type ) || ( class == Class_Binary_Type ) ) { + sprintf( b, "\t_%s = strdup(e.%s());\n", attrnm, attrnm ); + } + + + /* case TYPE_ENTITY: */ + if( class == Class_Entity_Type ) { + sprintf( b, "\t_%s = e.%s();\n", attrnm, attrnm ); + } + /* previous line modified to conform with SDAI C++ Binding for PDES, Inc. Prototyping 5/22/91 CD */ + + /* case TYPE_ENUM: */ + if( class == Class_Enumeration_Type ) { + sprintf( b, "\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); + } + /* case TYPE_SELECT: */ + if( class == Class_Select_Type ) { + sprintf( b, "DDDDDDD\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); + } + /* case TYPE_BOOLEAN */ + if( class == Class_Boolean_Type ) { + sprintf( b, "\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); + } + /* previous line modified to conform with SDAI C++ Binding for PDES, Inc. Prototyping 5/22/91 CD */ + + /* case TYPE_LOGICAL */ + if( class == Class_Logical_Type ) { + sprintf( b, "\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); + } + /* previous line modified to conform with SDAI C++ Binding for PDES, Inc. Prototyping 5/22/91 CD */ + + /* case TYPE_ARRAY: + case TYPE_LIST: + case TYPE_SET: + case TYPE_BAG: */ + if( isAggregateType( t ) ) { + *b = '\0'; + } + + fprintf( file, "%s", b ) ; + + fprintf( file, "\t attributes.push " ); + + /* 2. put attribute on attributes list */ + + /* default: */ + + fprintf( file, "\n\t(new STEPattribute(*%s%d%s, %s &_%s));\n", + ATTR_PREFIX, count, + /* (VARis_derived (t) ? "D" : (VARis_type_shifter (t) ? "R" : (VARget_inverse (t) ? "I" : ""))),*/ + /* (VARis_derived (t) ? "D" : (VARget_inverse (t) ? "I" : "")),*/ + attrnm, + ( TYPEis_entity( t ) ? "(SCLP23(Application_instance_ptr) *)" : "" ), + attrnm ); + ++count; + + } + LISTod; + fprintf( file, " }\n" ); + + +} + +int +get_local_attribute_number( Entity entity ) { + int i = 0; + Linked_List local = ENTITYget_attributes( entity ); + LISTdo( local, a, Variable ) + /* go to the child's first explicit attribute */ + if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) ++i; + LISTod; + return i; +} + +int +get_attribute_number( Entity entity ) { + int i = 0; + int found = 0; + Linked_List local, complete; + complete = ENTITYget_all_attributes( entity ); + local = ENTITYget_attributes( entity ); + + LISTdo( local, a, Variable ) + /* go to the child's first explicit attribute */ + if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) { + LISTdo( complete, p, Variable ) + /* cycle through all the explicit attributes until the + child's attribute is found */ + if( !found && ( ! VARget_inverse( p ) ) && ( ! VARis_derived( p ) ) ) { + if( p != a ) { + ++i; + } else { + found = 1; + } + } + LISTod; + if( found ) { + return i; + } else printf( "Internal error: %s:%d\n" + "Attribute %s not found. \n" + /* In this case, a is a Variable - so macro VARget_name (a) expands * + * to an Expression. The first element of an Expression is a Symbol. * + * The first element of a Symbol is char * name. */ + , __FILE__, __LINE__, VARget_name( a )->symbol.name ); + } + + LISTod; + return -1; +} + +/****************************************************************** + ** Procedure: LIBstructor_print + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: prints the c++ code for entity class's + ** constructor and destructor. goes to .cc file + ** Side Effects: generates codes segment in c++ .cc file + ** Status: ok 1/15/91 + ** Changes: Modified generator to initialize attributes to NULL based + ** on the NULL symbols defined in "SDAI C++ Binding for PDES, + ** Inc. Prototyping" by Stephen Clark. + ** Change Date: 5/22/91 CD + ** Changes: Modified STEPattribute constructors to take fewer arguments + ** 21-Dec-1992 -kcm + ******************************************************************/ +void +LIBstructor_print( Entity entity, FILE * file, Schema schema ) { + Linked_List attr_list; + Type t; + char attrnm [BUFSIZ]; + + Linked_List list; + __attribute__( ( unused ) ) Entity super = 0; + int super_cnt = 0; + Entity principalSuper = 0; + + const char * entnm = ENTITYget_classname( entity ); + int count = attr_count; + int index = 0; + int first = 1; + + /* constructor definition */ + fprintf( file, "%s::%s( ) \n", entnm, entnm ); + fprintf( file, "{\n" ); + + /* super = ENTITYput_superclass (entity); */ + + /* ////MULTIPLE INHERITANCE//////// */ + + if( multiple_inheritance ) { + fprintf( file, "\n" ); + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + LISTdo( list, e, Entity ) + /* if there\'s no super class yet, + or the super class doesn\'t have any attributes + */ + fprintf( file, "\t/* parent: %s */\n", ENTITYget_classname( e ) ); + + super = e; + super_cnt++; + //if( super_cnt == 1 ) { + /* ignore the 1st parent */ + // fprintf( file, + // "\t/* Ignore the first parent since it is */\n %s\n", + // "\t/* part of the main inheritance hierarchy */" ); + // principalSuper = e; /* principal SUPERTYPE */ + //} else { + fprintf( file, " HeadEntity(this); \n" ); + fprintf( file, "#if 0 \n" ); + fprintf( file, + "\t/* Optionally use the following to replace the line following \n" ); + fprintf( file, + "\t the endif. Use this to turn off adding attributes in \n" ); + fprintf( file, + "\t diamond shaped hierarchies for each additional parent at this\n" ); + fprintf( file, + "\t level. You currently must hand edit this for it to work. */\n" ); + fprintf( file, " int attrFlags[3]; // e.g. \n" ); + fprintf( file, " attrFlags[0] = 1; // add parents attrs\n" ); + fprintf( file, + " attrFlags[1] = 1; // add parent of parents attrs\n" ); + fprintf( file, + " attrFlags[2] = 0; // do not add parent of parent of parents attrs\n" ); + fprintf( file, + " // In *imaginary* hierarchy turn off attrFlags[2] since it \n" ); + fprintf( file, + " // would be the parent that has more than one path to it.\n" ); + fprintf( file, + " AppendMultInstance(new %s(this, attrFlags)); \n", + ENTITYget_classname( e ) ); + fprintf( file, "#endif \n" ); + + fprintf( file, " AppendMultInstance(new %s(this)); \n", + ENTITYget_classname( e ) ); + /* fprintf (file, "new %s(this); \n", ENTITYget_classname (e));*/ + + if( super_cnt == 2 ) { + printf( "\nMULTIPLE INHERITANCE for entity: %s\n", + ENTITYget_name( entity ) ); + printf( "\tSUPERTYPE 1: %s (principal supertype)\n", + ENTITYget_name( principalSuper ) ); + //} + printf( "\tSUPERTYPE %d: %s\n", super_cnt, ENTITYget_name( e ) ); + /* printf("\tin ENTITY %s\n\tadding SUPERTYPE %s. cp\n\n", + ENTITYget_name (entity), ENTITYget_name (e));*/ + } + LISTod; + + } else { /* if entity has no supertypes, it's at top of hierarchy */ + fprintf( file, "\t/* no SuperTypes */\n" ); + } + } + /* ////MULTIPLE INHERITANCE//////// */ + + /* Next lines added for independent field - DAR */ + /* if ( ENTITYget_supertypes(entity) || ENTITYget_abstract(entity) ) { + // If entity has supertypes or is abstract it's not independent. + fprintf (file, "\n _independent = 0;\n"); + fprintf (file, " // entity either has supertypes or is abstract\n"); + // Otherwise, keep the default value of 1. + } + */ + /* attributes */ + /* fprintf (file, "\n\tSTEPattribute * a;\n");*/ + + /* what if entity comes from other schema? */ + fprintf( file, "\n eDesc = %s%s%s;\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + attr_list = ENTITYget_attributes( entity ); + + LISTdo( attr_list, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + /* include attribute if it is not derived */ + generate_attribute_name( a, attrnm ); + t = VARget_type( a ); + + /* 1. declare the AttrDescriptor */ + /* this is now in the header */ + /* fprintf(file,"extern AttrDescriptor *%s%d%s;\n",*/ + /* ATTR_PREFIX,count,VARget_name(a));*/ + + /* if the attribute is Explicit, make a STEPattribute */ + /* if (VARis_simple_explicit (a)) {*/ + if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) { + /* 1. create a new STEPattribute */ + + fprintf( file, " " + "%sa = new STEPattribute(*%s%d%s%s, %s &_%s);\n", + ( first ? "STEPattribute *" : "" ), + /* first time through declare a */ + ATTR_PREFIX, count, + ( VARis_type_shifter( a ) ? "R" : "" ), + attrnm, + ( TYPEis_entity( t ) ? "(SCLP23(Application_instance_ptr) *)" : "" ), + attrnm ); + if( first ) { + first = 0 ; + } + /* 2. initialize everything to NULL (even if not optional) */ + + fprintf( file, " a -> set_null ();\n" ); + + /* 3. put attribute on attributes list */ + fprintf( file, " attributes.push (a);\n" ); + + /* if it is redefining another attribute make connection of + redefined attribute to redefining attribute */ + if( VARis_type_shifter( a ) ) { + fprintf( file, " MakeRedefined(a, \"%s\");\n", + VARget_simple_name( a ) ); + } + } + count++; + } + + LISTod; + + attr_list = ENTITYget_all_attributes( entity ); + + LISTdo( attr_list, a, Variable ) + /* if (VARis_overrider (entity, a)) { */ + if( VARis_derived( a ) ) { + fprintf( file, " MakeDerived (\"%s\");\n", + VARget_simple_name( a ) ); + } + LISTod; + fprintf( file, "}\n" ); + + /* copy constructor */ + /* LIBcopy_constructor (entity, file); */ + entnm = ENTITYget_classname( entity ); + fprintf( file, "%s::%s (%s& e ) \n", entnm, entnm, entnm ); + fprintf( file, "\t{ CopyAs((SCLP23(Application_instance_ptr)) &e);\t}\n" ); + + /* print destructor */ + /* currently empty, but should check to see if any attributes need + to be deleted -- attributes will need reference count */ + + entnm = ENTITYget_classname( entity ); + fprintf( file, "%s::~%s () { }\n", entnm, entnm ); + + /* Open OODB reInit function */ + fprintf( file, "\n#ifdef __O3DB__\n" ); + fprintf( file, "void \n%s::oodb_reInit ()\n{", entnm ); + fprintf( file, "\teDesc = %s%s%s;\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + count = attr_count; + attr_list = ENTITYget_attributes( entity ); + index = get_attribute_number( entity ); + + LISTdo( attr_list, a, Variable ) + /* if the attribute is Explicit, assign the Descriptor */ + if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) { + generate_attribute_name( a, attrnm ); + /* 1. assign the Descriptor for the STEPattributes */ + fprintf( file, "\tattributes [%d].aDesc = %s%d%s%s;\n", + index, + ATTR_PREFIX, count, + ( VARis_type_shifter( a ) ? "R" : "" ), + attrnm ); + } + index++, + count++; + LISTod; + fprintf( file, "}\n" + "#endif\n\n" ); + + +} + +/********************/ +/* print the constructor that accepts a SCLP23(Application_instance) as an argument used + when building multiply inherited entities. +*/ + +void +LIBstructor_print_w_args( Entity entity, FILE * file, Schema schema ) { + Linked_List attr_list; + Type t; + char attrnm [BUFSIZ]; + + Linked_List list; + __attribute__( ( unused ) ) Entity super = 0; + int super_cnt = 0; + + /* added for calling parents constructor if there is one */ + char parentnm [BUFSIZ]; + char * parent = 0; + Entity parentEntity = 0; + + const char * entnm; + int count = attr_count; + int first = 1; + + if( multiple_inheritance ) { + + /* //////////// */ + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + parentEntity = ( Entity )LISTpeek_first( list ); + if( parentEntity ) { + strcpy( parentnm, ENTITYget_classname( parentEntity ) ); + parent = parentnm; + } else { + parent = 0; /* no parent */ + } + } else { + parent = 0; /* no parent */ + } + + /* ENTITYget_classname returns a static buffer so don't call it twice + before it gets used - (I didn't write it) - I had to move it below + the above use. DAS */ + entnm = ENTITYget_classname( entity ); + /* constructor definition */ + if( parent ) + fprintf( file, "%s::%s (SCLP23(Application_instance) *se, int *addAttrs) : %s(se, (addAttrs ? &addAttrs[1] : 0)) \n", entnm, entnm, + parentnm ); + else { + fprintf( file, "%s::%s( SCLP23(Application_instance) *se, int *addAttrs)\n", entnm, entnm ); + } + + fprintf( file, "{\n" ); + + /* ////MULTIPLE INHERITANCE//////// */ + /* super = ENTITYput_superclass (entity); */ + + fprintf( file, "\t/* Set this to point to the head entity. */\n" ); + fprintf( file, " HeadEntity(se); \n" ); + + fprintf( file, "\n" ); + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + LISTdo( list, e, Entity ) + /* if there\'s no super class yet, + or the super class doesn\'t have any attributes + */ + fprintf( file, "\t/* parent: %s */\n", ENTITYget_classname( e ) ); + + super = e; + super_cnt++; + if( super_cnt == 1 ) { + /* ignore the 1st parent */ + fprintf( file, + "\t/* Ignore the first parent since it is */\n %s\n", + "\t/* part of the main inheritance hierarchy */" ); + } else { + fprintf( file, "#if 0 \n" ); + fprintf( file, + "\t/* Optionally use the following to replace the line following \n" ); + fprintf( file, + "\t the endif. Use this to turn off adding attributes in \n" ); + fprintf( file, + "\t diamond shaped hierarchies for each additional parent at this\n" ); + fprintf( file, + "\t level. You currently must hand edit this for it to work. */\n" ); + fprintf( file, " int attrFlags[3]; // e.g. \n" ); + fprintf( file, " attrFlags[0] = 1; // add parents attrs\n" ); + fprintf( file, + " attrFlags[1] = 1; // add parent of parents attrs\n" ); + fprintf( file, + " attrFlags[2] = 0; // do not add parent of parent of parents attrs\n" ); + fprintf( file, + " // In *imaginary* hierarchy turn off attrFlags[2] since it \n" ); + fprintf( file, + " // would be the parent that has more than one path to it.\n" ); + fprintf( file, + " se->AppendMultInstance(new %s(se, attrFlags)); \n", + ENTITYget_classname( e ) ); + fprintf( file, "#endif \n" ); + fprintf( file, " se->AppendMultInstance(new %s(se, 0)); \n", + ENTITYget_classname( e ) ); + /* printf("\tin ENTITY %s\n\thandling SUPERTYPE %s cp wArgs\n\n", + ENTITYget_name (entity), ENTITYget_name (e));*/ + } + LISTod; + + } else { /* if entity has no supertypes, it's at top of hierarchy */ + fprintf( file, "\t/* no SuperTypes */\n" ); + } + + /* ////MULTIPLE INHERITANCE//////// */ + + /* attributes */ + /* fprintf (file, "\n STEPattribute * a;\n");*/ + + /* what if entity comes from other schema? */ + fprintf( file, "\n eDesc = %s%s%s;\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + attr_list = ENTITYget_attributes( entity ); + + LISTdo( attr_list, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + /* include attribute if it is not derived */ + generate_attribute_name( a, attrnm ); + t = VARget_type( a ); + + /* 1. declare the AttrDescriptor */ + /* this is now in the header */ + /* fprintf(file,"extern AttrDescriptor *%s%d%s;\n",*/ + /* ATTR_PREFIX,count,VARget_name(a));*/ + + /* if the attribute is Explicit, make a STEPattribute */ + /* if (VARis_simple_explicit (a)) {*/ + if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) { + /* 1. create a new STEPattribute */ + + fprintf( file, " " + "%sa = new STEPattribute(*%s%d%s%s, %s &_%s);\n", + ( first ? "STEPattribute *" : "" ), + /* first time through declare a */ + ATTR_PREFIX, count, + ( VARis_type_shifter( a ) ? "R" : "" ), + attrnm, + ( TYPEis_entity( t ) ? "(SCLP23(Application_instance_ptr) *)" : "" ), + attrnm ); + + if( first ) { + first = 0 ; + } + /* 2. initialize everything to NULL (even if not optional) */ + + fprintf( file, " a -> set_null ();\n" ); + + fprintf( file, + "\t/* Put attribute on this class' %s\n", + "attributes list so the */\n\t/*access functions still work. */" ); + /* 3. put attribute on this class' attributes list so the + access functions still work */ + fprintf( file, " attributes.push (a);\n" ); + fprintf( file, + "\t/* Put attribute on the attributes list %s\n", + "for the */\n\t/* main inheritance heirarchy. */" ); + /* ////MULTIPLE INHERITANCE//////// */ + /* 4. put attribute on attributes list for the main + inheritance heirarchy */ + fprintf( file, " if(!addAttrs || addAttrs[0])\n" ); + fprintf( file, " se->attributes.push (a);\n" ); + + /* if it is redefining another attribute make connection of + redefined attribute to redefining attribute */ + if( VARis_type_shifter( a ) ) { + fprintf( file, " MakeRedefined(a, \"%s\");\n", + VARget_simple_name( a ) ); + } + /* ////MULTIPLE INHERITANCE//////// */ + } + count++; + } + + LISTod; + + attr_list = ENTITYget_all_attributes( entity ); + + LISTdo( attr_list, a, Variable ) + /* if (VARis_overrider (entity, a)) { */ + if( VARis_derived( a ) ) { + fprintf( file, " MakeDerived (\"%s\");\n", + VARget_simple_name( a ) ); + } + LISTod; + fprintf( file, "}\n" ); + } /* end if(multiple_inheritance) */ + +} +/********************/ + +/****************************************************************** + ** Procedure: ENTITYlib_print + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: drives the printing of the code for the class library + ** additional member functions can be generated by writing a routine + ** to generate the code and calling that routine from this procedure + ** Side Effects: generates code segment for c++ library file + ** Status: ok 1/15/91 + ******************************************************************/ + +void +ENTITYlib_print( Entity entity, FILE * file, Schema schema ) { + LIBdescribe_entity( entity, file, schema ); + //LIBstructor_print( entity, file, schema ); + //if( multiple_inheritance ) { + // LIBstructor_print_w_args( entity, file, schema ); + //} + //LIBmemberFunctionPrint( entity, file ); +} + +//FIXME should return bool +/* return 1 if types are predefined by us */ +int +TYPEis_builtin( const Type t ) { + switch( TYPEget_body( t )->type ) { /* dunno if correct*/ + case integer_: + case real_: + case string_: + case binary_: + case boolean_: + case number_: + case logical_: + return 1; + break; + default: + break; + } + return 0; +} + +/* go down through a type'sbase type chain, + Make and print new TypeDescriptors for each type with no name. + + This function should only be called for types that don't have an + associated Express name. Currently this only includes aggregates. + If this changes this function needs to be changed to support the type + that changed. This function prints TypeDescriptors for types + without names and it will go down through the type chain until it hits + a type that has a name. i.e. when it hits a type with a name it stops. + There are only two places where a type can not have a name - both + cases are aggregate types. + 1. an aggregate created in an attr declaration + e.g. names : ARRAY [1:3] of STRING; + 2. an aggregate that is an element of another aggregate. + e.g. TYPE Label = STRING; END_TYPE; + TYPE listSetOfLabel = LIST of SET of Label; END_TYPE; + LIST of SET of Label has a name i.e. listSetOfReal + SET of Label does not have a name and this function should be called + to generate one. + This function will not generate the code to handle Label. + + Type t contains the Type with no Express name that needs to have + TypeDecriptor[s] generated for it. + buf needs to have space declared enough to hold the name of the var + that can be referenced to refer to the type that was created for + Type t. +*/ +void +print_typechain( FILE * f, const Type t, char * buf, Schema schema ) { + /* if we've been called, current type has no name */ + /* nor is it a built-in type */ + /* the type_count variable is there for debugging purposes */ + + const char * ctype = TYPEget_ctype( t ); + Type base = 0; + int count = type_count++; + char typename_buf[MAX_LEN]; + + switch( TYPEget_body( t )->type ) { + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + /* create a new TypeDescriptor variable, e.g. t1, and new space for it */ + fprintf( f, "\t%s * %s%d = new %s;\n", + GetTypeDescriptorName( t ), TD_PREFIX, count, + GetTypeDescriptorName( t ) ); + + fprintf( f, + "\t%s%d->AssignAggrCreator((AggregateCreator) create_%s);%s", + TD_PREFIX, count, ctype, "\t// Creator function \n" ); + if( !TYPEget_head( t ) ) { + if( TYPEget_body( t )->lower ) + fprintf( f, "\t%s%d->Bound1(%d);\n", TD_PREFIX, count, + TYPEget_body( t )->lower->u.integer ); + if( TYPEget_body( t )->upper ) + fprintf( f, "\t%s%d->Bound2(%d);\n", TD_PREFIX, count, + TYPEget_body( t )->upper->u.integer ); + if( TYPEget_body( t )->flags.unique ) + fprintf( f, "\t%s%d->UniqueElements(LTrue);\n", + TD_PREFIX, count ); + if( TYPEget_body( t )->flags.optional ) + fprintf( f, "\t%s%d->OptionalElements(LTrue);\n", + TD_PREFIX, count ); + } + break; + + default: /* this should not happen since only aggregates are allowed to + not have a name. This funct should only be called for aggrs + without names. */ + fprintf( f, "\tTypeDescriptor * %s%d = new TypeDescriptor;\n", + TD_PREFIX, count ); + } + + /* there is no name so name doesn't need to be initialized */ + + fprintf( f, "\t%s%d->FundamentalType(%s);\n", TD_PREFIX, count, + FundamentalType( t, 1 ) ); + fprintf( f, "\t%s%d->Description(\"%s\");\n", TD_PREFIX, count, + TypeDescription( t ) ); + + /* DAS ORIG SCHEMA FIX */ + fprintf( f, "\t%s%d->OriginatingSchema(%s%s);\n", TD_PREFIX, count, + SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + + if( TYPEget_RefTypeVarNm( t, typename_buf, schema ) ) { + fprintf( f, "\t%s%d->ReferentType(%s);\n", TD_PREFIX, count, typename_buf ); + } else { + /* no name, recurse */ + char callee_buffer[MAX_LEN]; + if( TYPEget_body( t ) ) { + base = TYPEget_body( t )->base; + } + print_typechain( f, base, callee_buffer, schema ); + fprintf( f, "\t%s%d->ReferentType(%s);\n", TD_PREFIX, count, callee_buffer ); + } + sprintf( buf, "%s%d", TD_PREFIX, count ); + +} + +/****************************************************************** + ** Procedure: ENTITYincode_print + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: generates code to enter entity in STEP registry + ** This goes to the .init.cc file + ** Side Effects: + ** Status: ok 1/15/91 + ******************************************************************/ +void +ENTITYincode_print( Entity entity, FILE * file, Schema schema ) { +#define entity_name ENTITYget_name(entity) +#define schema_name SCHEMAget_name(schema) + char attrnm [BUFSIZ]; + char dict_attrnm [BUFSIZ]; + const char * super_schema; + char * tmp, *tmp2; + +#ifdef NEWDICT + /* DAS New SDAI Dictionary 5/95 */ + /* insert the entity into the schema descriptor */ + fprintf( file, + "\t((SDAIAGGRH(Set,EntityH))%s%s->Entities())->Add(%s%s%s);\n", + SCHEMA_PREFIX, schema_name, schema_name, ENT_PREFIX, entity_name ); +#endif + + if( ENTITYget_abstract( entity ) ) { + fprintf( file, "\t%s%s%s->AddSupertype_Stmt(\"", + schema_name, ENT_PREFIX, entity_name ); + if( entity->u.entity->subtype_expression ) { + fprintf( file, "ABSTRACT SUPERTYPE OF (" ); + tmp = SUBTYPEto_string( entity->u.entity->subtype_expression ); + tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); + fprintf( file, "%s)\");\n", format_for_stringout( tmp, tmp2 ) ); + free( tmp ); + free( tmp2 ); + } else { + fprintf( file, "ABSTRACT SUPERTYPE\");\n" ); + } + } else { + if( entity->u.entity->subtype_expression ) { + fprintf( file, "\t%s%s%s->AddSupertype_Stmt(\"", + schema_name, ENT_PREFIX, entity_name ); + fprintf( file, "SUPERTYPE OF (" ); + tmp = SUBTYPEto_string( entity->u.entity->subtype_expression ); + tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); + fprintf( file, "%s)\");\n", format_for_stringout( tmp, tmp2 ) ); + free( tmp ); + free( tmp2 ); + } + } + /* + if (entity->u.entity->subtype_expression) { + tmp = SUBTYPEto_string(entity->u.entity->subtype_expression); + tmp2 = (char*)malloc( sizeof(char) * (strlen(tmp)+BUFSIZ) ); + fprintf(file,"\t%s%s%s->AddSupertype_Stmt(\"(%s)\");\n", + schema_name,ENT_PREFIX,entity_name,format_for_stringout(tmp,tmp2)); + free(tmp); + free(tmp2); + } + */ + /* + LISTdo(ENTITYget_subtypes(entity),sub,Entity) + fprintf(file," %s%s%s->AddSubtype(%s%s%s);\n", + schema_name,ENT_PREFIX,entity_name, + schema_name,ENT_PREFIX,ENTITYget_name(sub)); + LISTod + */ + LISTdo( ENTITYget_supertypes( entity ), sup, Entity ) + /* set the owning schema of the supertype */ + super_schema = SCHEMAget_name( ENTITYget_schema( sup ) ); + /* print the supertype list for this entity */ + fprintf( file, " %s%s%s->AddSupertype(%s%s%s);\n", + schema_name, ENT_PREFIX, entity_name, + super_schema, + ENT_PREFIX, ENTITYget_name( sup ) ); + + /* add this entity to the subtype list of it's supertype */ + fprintf( file, " %s%s%s->AddSubtype(%s%s%s);\n", + super_schema, + ENT_PREFIX, ENTITYget_name( sup ), + schema_name, ENT_PREFIX, entity_name ); + LISTod + + LISTdo( ENTITYget_attributes( entity ), v, Variable ) + generate_attribute_name( v, attrnm ); + /* do EXPLICIT and DERIVED attributes first */ + /* if ( ! VARget_inverse (v)) {*/ + /* first make sure that type descriptor exists */ + if( TYPEget_name( v->type ) ) { + if( ( !TYPEget_head( v->type ) ) && + ( TYPEget_body( v->type )->type == entity_ ) ) { + /* fprintf(file, "\t%s%d%s%s = new %sAttrDescriptor(\"%s\",%s%s%s,%s,%s,%s,*%s%s%s);\n", */ + fprintf( file, "\t%s%d%s%s =\n\t new %s" + "(\"%s\",%s%s%s,\n\t %s,%s%s,\n\t *%s%s%s);\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm, + + ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), + + /* attribute name param */ + generate_dict_attr_name( v, dict_attrnm ), + + /* following assumes we are not in a nested */ + /* entity otherwise we should search upward */ + /* for schema */ + /* attribute's type */ + TYPEget_name( + TYPEget_body( v->type )->entity->superscope ), + ENT_PREFIX, TYPEget_name( v->type ), + + ( VARget_optional( v ) ? "LTrue" : "LFalse" ), + + ( VARget_unique( v ) ? "LTrue" : "LFalse" ), + + /* Support REDEFINED */ + ( VARget_inverse( v ) ? "" : + ( VARis_derived( v ) ? ", AttrType_Deriving" : + ( VARis_type_shifter( v ) ? ", AttrType_Redefining" : ", AttrType_Explicit" ) ) ), + + schema_name, ENT_PREFIX, TYPEget_name( entity ) + ); + } else { + /* type reference */ + /* fprintf(file," %s%d%s%s = new %sAttrDescriptor(\"%s\",%s%s%s,%s,%s,%s,*%s%s%s);\n",*/ + fprintf( file, " %s%d%s%s =\n\t new %s" + "(\"%s\",%s%s%s,\n\t %s,%s%s,\n\t *%s%s%s);\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm, + + ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), + + /* attribute name param */ + generate_dict_attr_name( v, dict_attrnm ), + + SCHEMAget_name( v->type->superscope ), + TD_PREFIX, TYPEget_name( v->type ), + + ( VARget_optional( v ) ? "LTrue" : "LFalse" ), + + ( VARget_unique( v ) ? "LTrue" : "LFalse" ), + + ( VARget_inverse( v ) ? "" : + ( VARis_derived( v ) ? ", AttrType_Deriving" : + ( VARis_type_shifter( v ) ? ", AttrType_Redefining" : ", AttrType_Explicit" ) ) ), + + schema_name, ENT_PREFIX, TYPEget_name( entity ) + ); + } + } else if( TYPEis_builtin( v->type ) ) { + /* the type wasn\'t named -- it must be built in or aggregate */ + + /* fprintf(file," %s%d%s%s = new %sAttrDescriptor(\"%s\",%s%s,%s,%s,%s,*%s%s%s);\n",*/ + fprintf( file, " %s%d%s%s =\n\t new %s" + "(\"%s\",%s%s,\n\t %s,%s%s,\n\t *%s%s%s);\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm, + ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), + /* attribute name param */ + generate_dict_attr_name( v, dict_attrnm ), + /* not sure about 0 here */ TD_PREFIX, FundamentalType( v->type, 0 ), + ( VARget_optional( v ) ? "LTrue" : + "LFalse" ), + ( VARget_unique( v ) ? "LTrue" : + "LFalse" ), + ( VARget_inverse( v ) ? "" : + ( VARis_derived( v ) ? ", AttrType_Deriving" : + ( VARis_type_shifter( v ) ? + ", AttrType_Redefining" : + ", AttrType_Explicit" ) ) ), + schema_name, ENT_PREFIX, TYPEget_name( entity ) + ); + } else { + /* manufacture new one(s) on the spot */ + char typename_buf[MAX_LEN]; + print_typechain( file, v->type, typename_buf, schema ); + /* fprintf(file," %s%d%s%s = new %sAttrDescriptor(\"%s\",%s,%s,%s,%s,*%s%s%s);\n",*/ + fprintf( file, " %s%d%s%s =\n\t new %s" + "(\"%s\",%s,%s,%s%s,\n\t *%s%s%s);\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm, + ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), + /* attribute name param */ + generate_dict_attr_name( v, dict_attrnm ), + typename_buf, + ( VARget_optional( v ) ? "LTrue" : + "LFalse" ), + ( VARget_unique( v ) ? "LTrue" : + "LFalse" ), + ( VARget_inverse( v ) ? "" : + ( VARis_derived( v ) ? ", AttrType_Deriving" : + ( VARis_type_shifter( v ) ? + ", AttrType_Redefining" : + ", AttrType_Explicit" ) ) ), + schema_name, ENT_PREFIX, TYPEget_name( entity ) + ); + } + + fprintf( file, " %s%s%s->Add%sAttr (%s%d%s%s);\n", + schema_name, ENT_PREFIX, TYPEget_name( entity ), + ( VARget_inverse( v ) ? "Inverse" : "Explicit" ), + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm ); + + if( VARis_derived( v ) && v->initializer ) { + tmp = EXPRto_string( v->initializer ); + tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); + fprintf( file, "\t%s%d%s%s->initializer_(\"%s\");\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm, format_for_stringout( tmp, tmp2 ) ); + free( tmp ); + free( tmp2 ); + } + if( VARget_inverse( v ) ) { + fprintf( file, "\t%s%d%s%s->inverted_attr_id_(\"%s\");\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm, v->inverse_attribute->name->symbol.name ); + if( v->type->symbol.name ) { + fprintf( file, + "\t%s%d%s%s->inverted_entity_id_(\"%s\");\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, + v->type->symbol.name ); + fprintf( file, "// inverse entity 1 %s\n", v->type->symbol.name ); + } else { + /* fprintf(file,"// inverse entity %s",TYPE_body_out(v->type));*/ + switch( TYPEget_body( v->type )->type ) { + case entity_: + fprintf( file, + "\t%s%d%s%s->inverted_entity_id_(\"%s\");\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, + TYPEget_body( v->type )->entity->symbol.name ); + fprintf( file, "// inverse entity 2 %s\n", TYPEget_body( v->type )->entity->symbol.name ); + break; + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + fprintf( file, + "\t%s%d%s%s->inverted_entity_id_(\"%s\");\n", + ATTR_PREFIX, attr_count, + ( VARis_derived( v ) ? "D" : + ( VARis_type_shifter( v ) ? "R" : + ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, + TYPEget_body( v->type )->base->symbol.name ); + fprintf( file, "// inverse entity 3 %s\n", TYPEget_body( v->type )->base->symbol.name ); + break; + default: + printf( "Error in %s, line %d: type %d not handled by switch statement.", __FILE__, __LINE__, TYPEget_body( v->type )->type ); + abort(); + } + } + } +attr_count++; + +LISTod + +fprintf( file, "\treg.AddEntity (*%s%s%s);\n", + schema_name, ENT_PREFIX, entity_name ); + +#undef schema_name +} + +/****************************************************************** + ** Procedure: ENTITYPrint + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: drives the functions for printing out code in lib, + ** include, and initialization files for a specific entity class + ** Side Effects: generates code in 3 files + ** Status: complete 1/15/91 + ******************************************************************/ + + +void +ENTITYPrint( Entity entity, FILES * files, Schema schema ) { + char * n = ENTITYget_name( entity ); + DEBUG( "Entering ENTITYPrint for %s\n", n ); + fprintf( files->lib, "\n####################\n # ENTITY %s #\n####################\n", n ); + ENTITYlib_print( entity, files -> lib, schema ); + DEBUG( "DONE ENTITYPrint\n" ) ; +} + +void +MODELPrintConstructorBody( Entity entity, FILES * files, Schema schema + /*, int index*/ ) { + const char * n; + DEBUG( "Entering MODELPrintConstructorBody for %s\n", n ); + + n = ENTITYget_classname( entity ); + + fprintf( files->lib, " eep = new SCLP23(Entity_extent);\n" ); + + + fprintf( files->lib, " eep->definition_(%s%s%s);\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + fprintf( files->lib, " _folders.Append(eep);\n\n" ); + + /* + fprintf (files->lib, " %s__set_var SdaiModel_contents_%s::%s_get_extents()\n", + n, SCHEMAget_name(schema), n); + + fprintf(files->create," %s%s%s = new EntityDescriptor(\"%s\",%s%s,%s, (Creator) create_%s);\n", + + PrettyTmpName (ENTITYget_name(entity)), + SCHEMA_PREFIX,SCHEMAget_name(schema), + (ENTITYget_abstract(entity)?"LTrue":"LFalse"), + ENTITYget_classname (entity) + ); + + + fprintf (files->lib, + "{\n return (%s__set_var)((_folders.retrieve(%d))->instances_());\n}\n", + n, index); + */ +} + +void +MODELPrint( Entity entity, FILES * files, Schema schema, int index ) { + + const char * n; + DEBUG( "Entering MODELPrint for %s\n", n ); + + n = ENTITYget_classname( entity ); + fprintf( files->lib, "\n%s__set_var SdaiModel_contents_%s::%s_get_extents()\n", + n, SCHEMAget_name( schema ), n ); + fprintf( files->lib, + "{\n return (%s__set_var)((_folders.retrieve(%d))->instances_());\n}\n", + n, index ); + /* + fprintf (files->lib, + "{\n return (%s__set_var)((_folders[%d])->instances_());\n}\n", + n, index); + */ + + /* //////////////// */ + /* + fprintf (files->inc, "\n/////////\t ENTITY %s\n\n", n); + ENTITYinc_print (entity, files -> inc,schema); + fprintf (files->inc, "\n/////////\t END_ENTITY %s\n\n", n); + + fprintf (files->lib, "\n/////////\t ENTITY %s\n\n", n); + ENTITYlib_print (entity, files -> lib,schema); + fprintf (files->lib, "\n/////////\t END_ENTITY %s\n\n", n); + + fprintf (files->init, "\n/////////\t ENTITY %s\n\n", n); + ENTITYincode_print (entity, files -> init, schema); + fprintf (files->init, "/////////\t END_ENTITY %s\n", n); + */ + DEBUG( "DONE MODELPrint\n" ) ; +} + +/* +getEntityDescVarName(Entity entity) +{ + SCHEMAget_name(schema),ENT_PREFIX,ENTITYget_name(entity), +} +*/ + +/* print in include file: class forward prototype, class typedefs, and + extern EntityDescriptor. `externMap' = 1 if entity must be instantiated + with external mapping (see Part 21, sect 11.2.5.1). */ +void +ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap ) { + const char * n; + Linked_List wheres; + /* char buf[BUFSIZ],buf2[BUFSIZ]; */ + char * whereRule, *whereRule_formatted = ""; + int whereRule_formatted_size = 0; + char * ptr, *ptr2; + char * uniqRule, *uniqRule_formatted; + Linked_List uniqs; + int i; + + fprintf( files->create, "\t%s%s%s = new EntityDescriptor(\n\t\t", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + fprintf( files->create, " \"%s\", %s%s, %s, ", + PrettyTmpName( ENTITYget_name( entity ) ), + SCHEMA_PREFIX, SCHEMAget_name( schema ), + ( ENTITYget_abstract( entity ) ? "LTrue" : + "LFalse" ) ); + fprintf( files->create, "%s,\n\t\t", externMap ? "LTrue" : + "LFalse" ); + + fprintf( files->create, " (Creator) create_%s );\n", + ENTITYget_classname( entity ) ); + /* add the entity to the Schema dictionary entry */ + fprintf( files->create, "\t%s%s->AddEntity(%s%s%s);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ), SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + wheres = TYPEget_where( entity ); + + if( wheres ) { + fprintf( files->create, + "\t%s%s%s->_where_rules = new Where_rule__list;\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + LISTdo( wheres, w, Where ) + whereRule = EXPRto_string( w->expr ); + ptr2 = whereRule; + + if( whereRule_formatted_size == 0 ) { + whereRule_formatted_size = 3 * BUFSIZ; + whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); + } else if( ( strlen( whereRule ) + 300 ) > whereRule_formatted_size ) { + free( whereRule_formatted ); + whereRule_formatted_size = strlen( whereRule ) + BUFSIZ; + whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); + } + whereRule_formatted[0] = '\0'; + /* + printf("whereRule length: %d\n",strlen(whereRule)); + printf("whereRule_formatted size: %d\n",whereRule_formatted_size); + */ + if( w->label ) { + strcpy( whereRule_formatted, w->label->name ); + strcat( whereRule_formatted, ": (" ); + ptr = whereRule_formatted + strlen( whereRule_formatted ); + while( *ptr2 ) { + if( *ptr2 == '\n' ) { + ; + } else if( *ptr2 == '\\' ) { + *ptr = '\\'; + ptr++; + *ptr = '\\'; + ptr++; + + } else if( *ptr2 == '(' ) { + *ptr = '\\'; + ptr++; + *ptr = 'n'; + ptr++; + *ptr = '\\'; + ptr++; + *ptr = 't'; + ptr++; + *ptr = *ptr2; + ptr++; + } else { + *ptr = *ptr2; + ptr++; + } + ptr2++; + } + *ptr = '\0'; + + strcat( ptr, ");\\n" ); + } else { + /* no label */ + strcpy( whereRule_formatted, "(" ); + ptr = whereRule_formatted + strlen( whereRule_formatted ); + + while( *ptr2 ) { + if( *ptr2 == '\n' ) { + ; + } else if( *ptr2 == '\\' ) { + *ptr = '\\'; + ptr++; + *ptr = '\\'; + ptr++; + + } else if( *ptr2 == '(' ) { + *ptr = '\\'; + ptr++; + *ptr = 'n'; + ptr++; + *ptr = '\\'; + ptr++; + *ptr = 't'; + ptr++; + *ptr = *ptr2; + ptr++; + } else { + *ptr = *ptr2; + ptr++; + } + ptr2++; + } + *ptr = '\0'; + strcat( ptr, ");\\n" ); + } + fprintf( files->create, "\twr = new Where_rule(\"%s\");\n", whereRule_formatted ); + fprintf( files->create, "\t%s%s%s->_where_rules->Append(wr);\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + free( whereRule ); + ptr2 = whereRule = 0; + LISTod + } + + uniqs = entity->u.entity->unique; + + if( uniqs ) { + fprintf( files->create, + "\t%s%s%s->_uniqueness_rules = new Uniqueness_rule__set;\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + + if( whereRule_formatted_size == 0 ) { + uniqRule_formatted = ( char * )malloc( sizeof( char ) * 2 * BUFSIZ ); + whereRule_formatted = uniqRule_formatted; + } else { + uniqRule_formatted = whereRule_formatted; + } + + /*******/ + /* + DASBUG + * take care of qualified attribute names like SELF\entity.attrname + * add parent entity to the uniqueness rule + * change EntityDescriptor::generate_express() to generate the UNIQUE clause + */ + LISTdo( uniqs, list, Linked_List ) + i = 0; + fprintf( files->create, "\tur = new Uniqueness_rule(\"" ); + LISTdo( list, v, Variable ) + i++; + if( i == 1 ) { + /* print label if present */ + if( v ) { + fprintf( files->create, "%s : ", StrToUpper( ( ( Symbol * )v )->name ) ); + } + } else { + if( i > 2 ) { + fprintf( files->create, ", " ); + } + uniqRule = EXPRto_string( v->name ); + fprintf( files->create, "%s", uniqRule ); + } + LISTod + fprintf( files->create, ";\\n\");\n" ); + fprintf( files->create, "\t%s%s%s->_uniqueness_rules->Append(ur);\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + LISTod + /********/ + + } + + if( whereRule_formatted_size > 0 ) { + free( whereRule_formatted ); + } + + n = ENTITYget_classname( entity ); + fprintf( files->classes, "\nclass %s;\n", n ); + fprintf( files->classes, "typedef %s * \t%sH;\n", n, n ); + fprintf( files->classes, "typedef %s * \t%s_ptr;\n", n, n ); + fprintf( files->classes, "typedef %s_ptr\t%s_var;\n", n, n ); + + fprintf( files->classes, + "#define %s__set \tSCLP23(DAObject__set)\n", n ); + + fprintf( files->classes, + "#define %s__set_var \tSCLP23(DAObject__set_var)\n", n ); + + fprintf( files ->classes, "extern EntityDescriptor \t*%s%s%s;\n", + SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); + +} + +void +MODELprint_new( Entity entity, FILES * files, Schema schema ) { + const char * n; + + n = ENTITYget_classname( entity ); + fprintf( files->inc, "\n %s__set_var %s_get_extents();\n", n, n ); + /* + fprintf(files->create," %s%s%s = new EntityDescriptor(\"%s\",%s%s,%s, (Creator) create_%s);\n", + SCHEMAget_name(schema),ENT_PREFIX,ENTITYget_name(entity), + PrettyTmpName (ENTITYget_name(entity)), + SCHEMA_PREFIX,SCHEMAget_name(schema), + (ENTITYget_abstract(entity)?"LTrue":"LFalse"), + ENTITYget_classname (entity) + ); + */ + /* + fprintf(files ->inc,"extern EntityDescriptor \t*%s%s%s;\n", + SCHEMAget_name(schema),ENT_PREFIX,ENTITYget_name(entity)); + */ + +} + +/****************************************************************** + ** TYPE GENERATION **/ + + +/****************************************************************** + ** Procedure: TYPEprint_enum + ** Parameters: const Type type - type to print + ** FILE* f - file on which to print + ** Returns: + ** Requires: TYPEget_class(type) == TYPE_ENUM + ** Description: prints code to represent an enumerated type in c++ + ** Side Effects: prints to header file + ** Status: ok 1/15/91 + ** Changes: Modified to check for appropiate key words as described + ** in "SDAI C++ Binding for PDES, Inc. Prototyping" by + ** Stephen Clark. + ** - Changed to match CD2 Part 23, 1/14/97 DAS + ** Change Date: 5/22/91 CD + ******************************************************************/ +const char * +EnumCElementName( Type type, Expression expr ) { + + static char buf [BUFSIZ]; + sprintf( buf, "%s__", + EnumName( TYPEget_name( type ) ) ); + strcat( buf, StrToLower( EXPget_name( expr ) ) ); + + return buf; +} + +char * +CheckEnumSymbol( char * s ) { + + static char b [BUFSIZ]; + if( strcmp( s, "sdaiTRUE" ) + && strcmp( s, "sdaiFALSE" ) + && strcmp( s, "sdaiUNKNOWN" ) ) { + /* if the symbol is not a reserved one */ + return ( s ); + + } else { + strcpy( b, s ); + strcat( b, "_" ); + printf( "** warning: the enumerated value %s is already being used ", s ); + printf( " and has been changed to %s **\n", b ); + return ( b ); + } +} + +void +TYPEenum_lib_print( const Type type, FILE * f ) { + DictionaryEntry de; + Expression expr; + //const char * n; /* pointer to class name */ + char c_enum_ele [BUFSIZ]; + if (is_python_keyword(TYPEget_name( type ))) { + fprintf( f, "# ENUMERATION TYPE %s_\n", TYPEget_name( type ) ); + fprintf(f,"%s_ = ENUMERATION([",TYPEget_name( type )); + } + else { + fprintf( f, "# ENUMERATION TYPE %s\n", TYPEget_name( type ) ); + fprintf(f,"%s = ENUMERATION([",TYPEget_name( type )); + } + /* set up the dictionary info */ + + //fprintf( f, "const char * \n%s::element_at (int n) const {\n", n ); + //fprintf( f, " switch (n) {\n" ); + DICTdo_type_init( ENUM_TYPEget_items( type ), &de, OBJ_ENUM ); + while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { + strncpy( c_enum_ele, EnumCElementName( type, expr ), BUFSIZ ); + if (is_python_keyword(EXPget_name(expr))) { + fprintf(f,"\n\t'%s_',",EXPget_name(expr)); + } + else { + fprintf(f,"\n\t'%s',",EXPget_name(expr)); + } + } + fprintf(f,"\n\t])\n"); +} + + +void Type_Description( const Type, char * ); + +/* return printable version of entire type definition */ +/* return it in static buffer */ +char * +TypeDescription( const Type t ) { + static char buf[4000]; + + buf[0] = '\0'; + + if( TYPEget_head( t ) ) { + Type_Description( TYPEget_head( t ), buf ); + } else { + TypeBody_Description( TYPEget_body( t ), buf ); + } + + /* should also print out where clause here */ + + return buf + 1; +} + +void strcat_expr( Expression e, char * buf ) { + if( e == LITERAL_INFINITY ) { + strcat( buf, "?" ); + } else if( e == LITERAL_PI ) { + strcat( buf, "PI" ); + } else if( e == LITERAL_E ) { + strcat( buf, "E" ); + } else if( e == LITERAL_ZERO ) { + strcat( buf, "0" ); + } else if( e == LITERAL_ONE ) { + strcat( buf, "1" ); + } else if( TYPEget_name( e ) ) { + strcat( buf, TYPEget_name( e ) ); + } else if( TYPEget_body( e->type )->type == integer_ ) { + char tmpbuf[30]; + sprintf( tmpbuf, "%d", e->u.integer ); + strcat( buf, tmpbuf ); + } else { + strcat( buf, "??" ); + } +} + +/* print t's bounds to end of buf */ +void +strcat_bounds( TypeBody b, char * buf ) { + if( !b->upper ) { + return; + } + + strcat( buf, " [" ); + strcat_expr( b->lower, buf ); + strcat( buf, ":" ); + strcat_expr( b->upper, buf ); + strcat( buf, "]" ); +} + +void +TypeBody_Description( TypeBody body, char * buf ) { + char * s; + + switch( body->type ) { + case integer_: + strcat( buf, " INTEGER" ); + break; + case real_: + strcat( buf, " REAL" ); + break; + case string_: + strcat( buf, " STRING" ); + break; + case binary_: + strcat( buf, " BINARY" ); + break; + case boolean_: + strcat( buf, " BOOLEAN" ); + break; + case logical_: + strcat( buf, " LOGICAL" ); + break; + case number_: + strcat( buf, " NUMBER" ); + break; + case entity_: + strcat( buf, " " ); + strcat( buf, PrettyTmpName( TYPEget_name( body->entity ) ) ); + break; + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + switch( body->type ) { + /* ignore the aggregate bounds for now */ + case aggregate_: + strcat( buf, " AGGREGATE OF" ); + break; + case array_: + strcat( buf, " ARRAY" ); + strcat_bounds( body, buf ); + strcat( buf, " OF" ); + if( body->flags.optional ) { + strcat( buf, " OPTIONAL" ); + } + if( body->flags.unique ) { + strcat( buf, " UNIQUE" ); + } + break; + case bag_: + strcat( buf, " BAG" ); + strcat_bounds( body, buf ); + strcat( buf, " OF" ); + break; + case set_: + strcat( buf, " SET" ); + strcat_bounds( body, buf ); + strcat( buf, " OF" ); + break; + case list_: + strcat( buf, " LIST" ); + strcat_bounds( body, buf ); + strcat( buf, " OF" ); + if( body->flags.unique ) { + strcat( buf, " UNIQUE" ); + } + break; + default: + printf( "Error in %s, line %d: type %d not handled by switch statement.", __FILE__, __LINE__, body->type ); + abort(); + } + + Type_Description( body->base, buf ); + break; + case enumeration_: + strcat( buf, " ENUMERATION of (" ); + LISTdo( body->list, e, Expression ) + strcat( buf, ENUMget_name( e ) ); + strcat( buf, ", " ); + LISTod + /* find last comma and replace with ')' */ + s = strrchr( buf, ',' ); + if( s ) { + strcpy( s, ")" ); + } + break; + + case select_: + strcat( buf, " SELECT (" ); + LISTdo( body->list, t, Type ) + strcat( buf, PrettyTmpName( TYPEget_name( t ) ) ); + strcat( buf, ", " ); + LISTod + /* find last comma and replace with ')' */ + s = strrchr( buf, ',' ); + if( s ) { + strcpy( s, ")" ); + } + break; + default: + strcat( buf, " UNKNOWN" ); + } + + if( body->precision ) { + strcat( buf, " (" ); + strcat_expr( body->precision, buf ); + strcat( buf, ")" ); + } + if( body->flags.fixed ) { + strcat( buf, " FIXED" ); + } +} + +void +Type_Description( const Type t, char * buf ) { + if( TYPEget_name( t ) ) { + strcat( buf, " " ); + strcat( buf, TYPEget_name( t ) ); + /* strcat(buf,PrettyTmpName (TYPEget_name(t)));*/ + } else { + TypeBody_Description( TYPEget_body( t ), buf ); + } +} + +/************************************************************************** + ** Procedure: TYPEprint_typedefs + ** Parameters: const Type type + ** Returns: + ** Description: + ** Prints in Sdaiclasses.h typedefs, forward declarations, and externs + ** for user-defined types. Only a fraction of the typedefs and decla- + ** rations are needed in Sdaiclasses.h. Enum's and selects must actu- + ** ally be defined before objects (such as entities) which use it can + ** be defined. So forward declarations will not serve any purpose. + ** Other redefined types and aggregate types may be declared here. + ** Side Effects: + ** Status: 16-Mar-1993 kcm; updated 04-Feb-1997 dar + **************************************************************************/ +void +TYPEprint_typedefs( Type t, FILE * classes ) { + char nm [BUFSIZ]; + Type i; + + /* Print the typedef statement (poss also a forward class def: */ + if( TYPEis_enumeration( t ) ) { + /* For enums and sels (else clause below), we need forward decl's so + // that if we later come across a type which is an aggregate of one of + // them, we'll be able to process it. For selects, we also need a decl + // of the class itself, while for enum's we don't. Objects which con- + // tain an enum can't be generated until the enum is generated. (The + // same is basically true for the select, but a sel containing an ent + // containing a sel needs the forward decl (trust me ;-) ). */ + if( !TYPEget_head( t ) ) { + /* Only print this enum if it is an actual type and not a redefi- + // nition of another enum. (Those are printed at the end of the + // classes file - after all the actual enum's. They must be + // printed last since they depend on the others.) */ + strncpy( nm, TYPEget_ctype( t ), BUFSIZ ); + fprintf( classes, "class %ss;\n", nm ); + } + } else if( TYPEis_select( t ) ) { + if( !TYPEget_head( t ) ) { + /* Same comment as above. */ + strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ ); + fprintf( classes, "class %s;\n", nm ); + fprintf( classes, "typedef %s * %s_ptr;\n", nm, nm ); + fprintf( classes, "class %ss;\n", nm ); + fprintf( classes, "typedef %ss * %ss_ptr;\n", nm, nm ); + } + } else { + if( TYPEis_aggregate( t ) ) { + i = TYPEget_base_type( t ); + if( TYPEis_enumeration( i ) || TYPEis_select( i ) ) { + /* One exceptional case - a 1d aggregate of an enum or select. + // We must wait till the enum/sel itself has been processed. + // To ensure this, we process all such 1d aggrs in a special + // loop at the end (in multpass.c). 2d aggrs (or higher), how- + // ever, can be processed now - they only require GenericAggr + // for their definition here. */ + goto externln; + } + } + /* At this point, we'll print typedefs for types which are redefined + // fundamental types and their aggregates, and for 2D aggregates(aggre- + // gates of aggregates) of enum's and selects. */ + strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); + fprintf( classes, "typedef %s \t%s;\n", TYPEget_ctype( t ), nm ); + if( TYPEis_aggregate( t ) ) { + fprintf( classes, "typedef %s * \t%sH;\n", nm, nm ); + fprintf( classes, "typedef %s * \t%s_ptr;\n", nm, nm ); + fprintf( classes, "typedef %s_ptr \t%s_var;\n", nm, nm ); + } + } + +externln: + /* Print the extern statement: */ + strncpy( nm, TYPEtd_name( t ), BUFSIZ ); + fprintf( classes, "extern %s \t*%s;\n", GetTypeDescriptorName( t ), nm ); +} + +/* return 1 if it is a multidimensional aggregate at the level passed in + otherwise return 0; If it refers to a type that is a multidimensional + aggregate 0 is still returned. */ +int +isMultiDimAggregateType( const Type t ) { + if( TYPEget_body( t )->base ) + if( isAggregateType( TYPEget_body( t )->base ) ) { + return 1; + } + return 0; +} + +/* Get the TypeDescriptor variable name that t's TypeDescriptor references (if + possible). + pass space in through buf, buff will be filled in with the name of the + TypeDescriptor (TD) that needs to be referenced by the TD that is + generated for Type t. Return 1 if buf has been filled in with the name + of a TD. Return 0 if it hasn't for these reasons: Enumeration TDs don't + reference another TD, select TDs reference several TDs and are handled + separately, Multidimensional aggregates generate unique intermediate TD + variables that are referenced - when these don't have an Express related + name this function can't know about them - e.g. + TYPE listSetAggr = LIST OF SET OF STRING; This function won't fill in the + name that listSetAggr's ListTypeDescriptor will reference. + TYPE arrListSetAggr = ARRAY [1:4] of listSetAggr; This function will + return the name of the TD that arrlistSetAggr's ArrayTypeDescriptor should + reference since it has an Express name associated with it. +*/ +int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { + + /* It looks like TYPEget_head(t) is true when processing a type + that refers to another type. e.g. when processing "name" in: + TYPE name = label; ENDTYPE; TYPE label = STRING; ENDTYPE; DAS */ + if( TYPEget_head( t ) ) { + /* this means that it is defined in an Express TYPE stmt and + it refers to another Express TYPE stmt */ + /* it would be a reference_ type */ + /* a TypeDescriptor of the form t_ */ + sprintf( buf, "%s%s%s", + SCHEMAget_name( TYPEget_head( t )->superscope ), + TYPEprefix( t ), TYPEget_name( TYPEget_head( t ) ) ); + return 1; + } else { + switch( TYPEget_body( t )->type ) { + case integer_: + case real_: + case boolean_: + case logical_: + case string_: + case binary_: + case number_: + /* one of the SCL builtin TypeDescriptors of the form + t_STRING_TYPE, or t_REAL_TYPE */ + sprintf( buf, "%s%s", TD_PREFIX, FundamentalType( t, 0 ) ); + return 1; + break; + + case enumeration_: /* enums don't have a referent type */ + case select_: /* selects are handled differently elsewhere, they + refer to several TypeDescriptors */ + return 0; + break; + + case entity_: + sprintf( buf, "%s", TYPEtd_name( t ) ); + /* following assumes we are not in a nested entity */ + /* otherwise we should search upward for schema */ + /* TYPEget_name(TYPEget_body(t)->entity->superscope), + ENT_PREFIX,TYPEget_name(t) ); */ + return 1; + break; + + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + /* referent TypeDescriptor will be the one for the element unless it + is a multidimensional aggregate then return 0 */ + + if( isMultiDimAggregateType( t ) ) { + if( TYPEget_name( TYPEget_body( t )->base ) ) { + sprintf( buf, "%s%s%s", + SCHEMAget_name( TYPEget_body( t )->base->superscope ), + TYPEprefix( t ), TYPEget_name( TYPEget_body( t )->base ) ); + return 1; + } + + /* if the multi aggr doesn't have a name then we are out of scope + of what this function can do */ + return 0; + } else { + /* for a single dimensional aggregate return TypeDescriptor + for element */ + /* being an aggregate implies that base below is not 0 */ + + if( TYPEget_body( TYPEget_body( t )->base )->type == enumeration_ || + TYPEget_body( TYPEget_body( t )->base )->type == select_ ) { + + sprintf( buf, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); + return 1; + } else if( TYPEget_name( TYPEget_body( t )->base ) ) { + if( TYPEget_body( TYPEget_body( t )->base )->type == entity_ ) { + sprintf( buf, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); + return 1; + } + sprintf( buf, "%s%s%s", + SCHEMAget_name( TYPEget_body( t )->base->superscope ), + TYPEprefix( t ), TYPEget_name( TYPEget_body( t )->base ) ); + return 1; + } + return TYPEget_RefTypeVarNm( TYPEget_body( t )->base, buf, schema ); + } + break; + default: + return 0; + } + } + /* return 0; // this stmt will never be reached */ +} + + +/***** + print stuff for types that are declared in Express TYPE statements... i.e. + extern descriptor declaration in .h file - MOVED BY DAR to TYPEprint_type- + defs - in order to print all the Sdaiclasses.h stuff in fedex_plus's + first pass through each schema. + descriptor definition in the .cc file + initialize it in the .init.cc file (DAR - all initialization done in fn + TYPEprint_init() (below) which is done in fedex_plus's 1st pass only.) +*****/ + +void +TYPEprint_descriptions( const Type type, FILES * files, Schema schema ) { + char tdnm [BUFSIZ], + typename_buf [MAX_LEN], + base [BUFSIZ], + nm [BUFSIZ]; + Type i; + + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + + /* define type descriptor pointer */ + /* put extern def in header, put the real definition in .cc file */ + + /* put extern def in header (DAR - moved to TYPEprint_typedef's - + * see fn header comments.)*/ + /* + fprintf(files->inc,"extern %s \t*%s;\n", + GetTypeDescriptorName(type), tdnm); + */ + + /* in source - declare the real definition of the pointer */ + /* i.e. in the .cc file */ + if( TYPEis_enumeration( type ) && ( i = TYPEget_ancestor( type ) ) != NULL ) { + /* If we're a renamed enum type, just print a few typedef's to the + // original and some specialized create functions: */ + strncpy( base, StrToLower(EnumName( TYPEget_name( i ) )), BUFSIZ ); + strncpy( nm, StrToLower(EnumName( TYPEget_name( type ) )), BUFSIZ ); + fprintf( files->lib, "%s = %s\n",nm,base ); + return; + } + + if( TYPEget_RefTypeVarNm( type, typename_buf, schema ) ) + { + fprintf(files->lib, "%s = ",TYPEget_name(type)); + char * output = FundamentalType(type,0); + if (!strcmp(output,"ARRAY_TYPE")) { + process_aggregate(files->lib,type); + fprintf(files->lib,"\n"); + } + else { + fprintf(files->lib,"%s\n",output); + } + } + else { + switch( TYPEget_body( type )->type ) { + case enumeration_: + TYPEenum_lib_print( type, files -> lib ); + break; + + case select_: + //TYPEselect_lib_print (type, files -> lib); + break; + default: + break; + } + } +} + + +static void +printEnumCreateHdr( FILE * inc, const Type type ) +/* + * Prints a bunch of lines for enumeration creation functions (i.e., "cre- + * ate_SdaiEnum1()"). Since this is done both for an enum and for "copies" + * of it (when "TYPE enum2 = enum1"), I placed this code in a separate fn. + */ +{ + const char * nm = TYPEget_ctype( type ); + + fprintf( inc, " SCLP23(Enum) * create_%s ();\n", nm ); +} + +static void +printEnumCreateBody( FILE * lib, const Type type ) +/* + * See header comment above by printEnumCreateHdr. + */ +{ + const char * nm = TYPEget_ctype( type ); + char tdnm[BUFSIZ]; + + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + + fprintf( lib, "\nSCLP23(Enum) * \ncreate_%s () \n{\n", nm ); + fprintf( lib, " return new %s( \"\", %s );\n}\n\n", nm, tdnm ); +} + +static void +printEnumAggrCrHdr( FILE * inc, const Type type ) +/* + * Similar to printEnumCreateHdr above for the enum aggregate. + */ +{ + const char * n = TYPEget_ctype( type ); + /* const char *n = ClassName( TYPEget_name(type) ));*/ + + fprintf( inc, " STEPaggregate * create_%ss ();\n", n ); +} + +static void +printEnumAggrCrBody( FILE * lib, const Type type ) { + const char * n = TYPEget_ctype( type ); + char tdnm[BUFSIZ]; + + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + + fprintf( lib, "\nSTEPaggregate * \ncreate_%ss ()\n{\n", n ); + fprintf( lib, " return new %ss( %s );\n}\n", n, tdnm ); +} + +void +TYPEprint_init( const Type type, FILE * ifile, Schema schema ) { + char tdnm [BUFSIZ]; + char typename_buf[MAX_LEN]; + + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + + if( isAggregateType( type ) ) { + if( !TYPEget_head( type ) ) { + if( TYPEget_body( type )->lower ) + fprintf( ifile, "\t%s->Bound1(%d);\n", tdnm, + TYPEget_body( type )->lower->u.integer ); + if( TYPEget_body( type )->upper ) + fprintf( ifile, "\t%s->Bound2(%d);\n", tdnm, + TYPEget_body( type )->upper->u.integer ); + if( TYPEget_body( type )->flags.unique ) { + fprintf( ifile, "\t%s->UniqueElements(\"LTrue\");\n", tdnm ); + } + /* fprintf(ifile, "\t%s->UniqueElements(%d);\n", tdnm, + TYPEget_body(type)->flags.unique); */ + if( TYPEget_body( type )->flags.optional ) { + fprintf( ifile, "\t%s->OptionalElements(\"LTrue\");\n", tdnm ); + } + /* fprintf(ifile, "\t%s->OptionalElements(%d);\n", tdnm, + TYPEget_body(type)->flags.optional);*/ + } + } + + /* fill in the TD's values in the SchemaInit function (it is already + declared with basic values) */ + + if( TYPEget_RefTypeVarNm( type, typename_buf, schema ) ) { + fprintf( ifile, "\t%s->ReferentType(%s);\n", tdnm, typename_buf ); + } else { + switch( TYPEget_body( type )->type ) { + case aggregate_: /* aggregate_ should not happen? DAS */ + case array_: + case bag_: + case set_: + case list_: { + + if( isMultiDimAggregateType( type ) ) { + print_typechain( ifile, TYPEget_body( type )->base, + typename_buf, schema ); + fprintf( ifile, " %s->ReferentType(%s);\n", tdnm, + typename_buf ); + } + break; + } + default: + break; + } + } + + /* DAR - moved fn call below from TYPEselect_print to here to put all init + ** info together. */ + if( TYPEis_select( type ) ) { + TYPEselect_init_print( type, ifile, schema ); + } +#ifdef NEWDICT + /* DAS New SDAI Dictionary 5/95 */ + /* insert the type into the schema descriptor */ + fprintf( ifile, + "\t((SDAIAGGRH(Set,DefinedTypeH))%s%s->Types())->Add((DefinedTypeH)%s);\n", + SCHEMA_PREFIX, SCHEMAget_name( schema ), tdnm ); +#endif + /* insert into type dictionary */ + fprintf( ifile, "\treg.AddType (*%s);\n", tdnm ); +} + +/* print name, fundamental type, and description initialization function + calls */ + +void +TYPEprint_nm_ft_desc( Schema schema, const Type type, FILE * f, char * endChars ) { + + fprintf( f, "\t\t \"%s\",\t// Name\n", + PrettyTmpName( TYPEget_name( type ) ) ); + fprintf( f, "\t\t %s,\t// FundamentalType\n", + FundamentalType( type, 1 ) ); + fprintf( f, "\t\t %s%s,\t// Originating Schema\n", + SCHEMA_PREFIX, SCHEMAget_name( schema ) ); + fprintf( f, "\t\t \"%s\"%s\t// Description\n", + TypeDescription( type ), endChars ); +} + + +/* new space for a variable of type TypeDescriptor (or subtype). This + function is called for Types that have an Express name. */ + +void +TYPEprint_new( const Type type, FILE * create, Schema schema ) { + Linked_List wheres; + char * whereRule, *whereRule_formatted = ""; + int whereRule_formatted_size = 0; + char * ptr, *ptr2; + + Type tmpType = TYPEget_head( type ); + Type bodyType = tmpType; + + /* define type definition */ + /* in source - the real definition of the TypeDescriptor */ + + if( TYPEis_select( type ) ) { + fprintf( create, + "\t%s = new SelectTypeDescriptor (\n\t\t ~%s,\t//unique elements,\n", + TYPEtd_name( type ), + /* ! any_duplicates_in_select (SEL_TYPEget_items(type)) );*/ + /* unique_types (SEL_TYPEget_items (type) ) );*/ + non_unique_types_string( type ) ); + /* DAS ORIG SCHEMA FIX */ + TYPEprint_nm_ft_desc( schema, type, create, "," ); + + fprintf( create, + "\t\t (SelectCreator) create_%s);\t// Creator function\n", + SelectName( TYPEget_name( type ) ) ); + } else + /*DASSSS if (TYPEget_name(t)) { + strcat(buf," "); + strcat(buf,PrettyTmpName (TYPEget_name(t))); + */ + switch( TYPEget_body( type )->type ) { + + + case boolean_: + + fprintf( create, "\t%s = new EnumTypeDescriptor (\n", + TYPEtd_name( type ) ); + + /* fill in it's values */ + TYPEprint_nm_ft_desc( schema, type, create, "," ); + fprintf( create, + "\t\t (EnumCreator) create_BOOLEAN);\t// Creator function\n" ); + break; + + case logical_: + + fprintf( create, "\t%s = new EnumTypeDescriptor (\n", + TYPEtd_name( type ) ); + + /* fill in it's values */ + TYPEprint_nm_ft_desc( schema, type, create, "," ); + fprintf( create, + "\t\t (EnumCreator) create_LOGICAL);\t// Creator function\n" ); + break; + + case enumeration_: + + fprintf( create, "\t%s = new EnumTypeDescriptor (\n", + TYPEtd_name( type ) ); + + /* fill in it's values */ + TYPEprint_nm_ft_desc( schema, type, create, "," ); + /* + fprintf(create, + "\t\t (EnumCreator) create_%s);\t// Creator function\n", + TYPEget_ctype(type) ); + */ + /* DASCUR */ + + /* get the type name of the underlying type - it is the type that + needs to get created */ + + tmpType = TYPEget_head( type ); + if( tmpType ) { + + bodyType = tmpType; + + while( tmpType ) { + bodyType = tmpType; + tmpType = TYPEget_head( tmpType ); + } + + fprintf( create, + "\t\t (EnumCreator) create_%s);\t// Creator function\n", + TYPEget_ctype( bodyType ) ); + } else + fprintf( create, + "\t\t (EnumCreator) create_%s);\t// Creator function\n", + TYPEget_ctype( type ) ); + break; + + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + + fprintf( create, "\n\t%s = new %s (\n", + TYPEtd_name( type ), GetTypeDescriptorName( type ) ); + + /* fill in it's values */ + TYPEprint_nm_ft_desc( schema, type, create, "," ); + + fprintf( create, + "\t\t (AggregateCreator) create_%s);\t// Creator function\n\n", + ClassName( TYPEget_name( type ) ) ); + break; + + default: + fprintf( create, "\t%s = new TypeDescriptor (\n", + TYPEtd_name( type ) ); + + /* fill in it's values */ + TYPEprint_nm_ft_desc( schema, type, create, ");" ); + + break; + } + /* add the type to the Schema dictionary entry */ + fprintf( create, "\t%s%s->AddType(%s);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ), TYPEtd_name( type ) ); + + + wheres = type->where; + + if( wheres ) { + fprintf( create, "\t%s->_where_rules = new Where_rule__list;\n", + TYPEtd_name( type ) ); + + LISTdo( wheres, w, Where ) + whereRule = EXPRto_string( w->expr ); + ptr2 = whereRule; + + if( whereRule_formatted_size == 0 ) { + whereRule_formatted_size = 3 * BUFSIZ; + whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); + } else if( ( strlen( whereRule ) + 300 ) > whereRule_formatted_size ) { + free( whereRule_formatted ); + whereRule_formatted_size = strlen( whereRule ) + BUFSIZ; + whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); + } + whereRule_formatted[0] = '\0'; + if( w->label ) { + strcpy( whereRule_formatted, w->label->name ); + strcat( whereRule_formatted, ": (" ); + ptr = whereRule_formatted + strlen( whereRule_formatted ); + while( *ptr2 ) { + if( *ptr2 == '\n' ) { + ; + } else if( *ptr2 == '\\' ) { + *ptr = '\\'; + ptr++; + *ptr = '\\'; + ptr++; + + } else if( *ptr2 == '(' ) { + /* *ptr = '\\'; ptr++; + *ptr = 'n'; ptr++; + *ptr = '\\'; ptr++; + *ptr = 't'; ptr++; */ + *ptr = *ptr2; + ptr++; + } else { + *ptr = *ptr2; + ptr++; + } + ptr2++; + } + *ptr = '\0'; + + strcat( ptr, ");\\n" ); + } else { + /* no label */ + strcpy( whereRule_formatted, "(" ); + ptr = whereRule_formatted + strlen( whereRule_formatted ); + + while( *ptr2 ) { + if( *ptr2 == '\n' ) { + ; + } else if( *ptr2 == '\\' ) { + *ptr = '\\'; + ptr++; + *ptr = '\\'; + ptr++; + + } else if( *ptr2 == '(' ) { + /* *ptr = '\\'; ptr++; + *ptr = 'n'; ptr++; + *ptr = '\\'; ptr++; + *ptr = 't'; ptr++; */ + *ptr = *ptr2; + ptr++; + } else { + *ptr = *ptr2; + ptr++; + } + ptr2++; + } + *ptr = '\0'; + strcat( ptr, ");\\n" ); + } + fprintf( create, "\twr = new Where_rule(\"%s\");\n", whereRule_formatted ); + fprintf( create, "\t%s->_where_rules->Append(wr);\n", + TYPEtd_name( type ) ); + + free( whereRule ); + ptr2 = whereRule = 0; + LISTod + free( whereRule_formatted ); + } +} + +/* + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + case select_: + case enumeration_: + case boolean_: + case logical_: + case integer_: + case real_: + case number_: + case string_: + case binary_: + case number_: + case generic_: + case entity_: +*/ diff --git a/src/fedex_python/src/classes_wrapper_python.cc b/src/fedex_python/src/classes_wrapper_python.cc new file mode 100644 index 000000000..f0b8c9f6e --- /dev/null +++ b/src/fedex_python/src/classes_wrapper_python.cc @@ -0,0 +1,553 @@ +#include +#include +#include + +#include "complexSupport.h" +extern int corba_binding; + +void use_ref( Schema, Express, FILES * ); + +void +create_builtin_type_decl( FILES * files, char * name ) { + //fprintf( files->incall, "extern TypeDescriptor *%s%s_TYPE;\n", + // TD_PREFIX, name ); +} + +void +create_builtin_type_defn( FILES * files, char * name ) { + //fprintf( files->initall, "\t%s%s_TYPE = TypeDescriptor (", + // TD_PREFIX, name ); + //fprintf( files->initall, "\"%s\", %s_TYPE, \"%s\");\n", + // PrettyTmpName( name ), StrToUpper( name ), StrToLower( name ) ); +} + +/****************************************************************** + ** Procedure: print_file_header + ** Parameters: const Schema schema - top-level schema being printed + ** FILE* file - file on which to print header + ** Returns: + ** Description: handles file related tasks that need to be done once + ** at the beginning of processing. + ** In this case the file schema.h is initiated + ** Status: ok 1/15/91 + ******************************************************************/ + +void +print_file_header( Express express, FILES * files ) { + //files -> incall = FILEcreate( "schema.h" ); + + /* prevent RCS from expanding this! */ + //fprintf( files->incall, "import sdai\n" ); + //fprintf( files->incall, "import Registry\n" ); + + //fprintf( files->incall, "\n#include \n" ); + //fprintf( files->incall, "\n#include \n" ); + //fprintf( files->incall, "\n#include \n" ); + //fprintf( files->incall, "\n#include \n" ); + + //fprintf( files->incall, "\n#include \n" ); + //fprintf( files->incall, "import Sdaiclasses\n" ); + //fprintf( files->incall, "extern void SchemaInit (Registry &);\n" ); + //fprintf( files->incall, "extern void InitSchemasAndEnts (Registry &);\n" ); + + //files -> initall = FILEcreate( "schema.py" ); + //fprintf( files->initall, "/* %cId$ */ \n", '\044' ); + //fprintf( files->initall, "#include \n" ); + //fprintf( files->initall, "import schema\n" ); + //fprintf( files-> initall, "class Registry:\n" ); + + //fprintf( files->initall, "\tdef SchemaInit (Registry reg)\n{\n" ); + //fprintf( files->initall, "\t extern void InitSchemasAndEnts " ); + //fprintf( files->initall, "(Registry & r);\n" ); + //fprintf( files->initall, "\t InitSchemasAndEnts (reg);\n" ); + + // This file will contain instantiation statements for all the schemas and + // entities in the express file. (They must all be in separate function + // called first by SchemaInit() so that all entities will exist + //files -> create = FILEcreate( "SdaiAll.py" ); + //fprintf( files->create, "/* %cId$ */ \n", '\044' ); + //fprintf( files->create, "#include \n" ); + //fprintf( files->create, "import schema" ); + //fprintf( files->create, "\nvoid\nInitSchemasAndEnts (Registry & reg)\n{\n" ); + + // This file declares all entity classes as incomplete types. This will + // allow all the .h files to reference all .h's. We can then have e.g., + // entX from schemaA have attribute attr1 = entY from schemaB. + //files -> classes = FILEcreate( "Sdaiclasses.h" ); + //fprintf( files->classes, "/* %cId$ */ \n", '$' ); + //fprintf( files->classes, "#include \n" ); + + /* create built-in types */ + /* no need to generate + create_builtin_type_decl(files,"INTEGER"); + create_builtin_type_decl(files,"REAL"); + create_builtin_type_decl(files,"STRING"); + create_builtin_type_decl(files,"BINARY"); + create_builtin_type_decl(files,"BOOLEAN"); + create_builtin_type_decl(files,"LOGICAL"); + create_builtin_type_decl(files,"NUMBER"); + create_builtin_type_decl(files,"GENERIC"); + */ + /* create built-in types */ + /* no need to generate + create_builtin_type_defn(files,"INTEGER"); + create_builtin_type_defn(files,"REAL"); + create_builtin_type_defn(files,"STRING"); + create_builtin_type_defn(files,"BINARY"); + create_builtin_type_defn(files,"BOOLEAN"); + create_builtin_type_defn(files,"LOGICAL"); + create_builtin_type_defn(files,"NUMBER"); + create_builtin_type_defn(files,"GENERIC"); + */ + +} + +/****************************************************************** + ** Procedure: print_file_trailer + ** Parameters: const Schema schema - top-level schema printed + ** FILE* file - file on which to print trailer + ** Returns: + ** Description: handles cleaning up things at end of processing + ** Status: ok 1/15/91 + ******************************************************************/ + +/*ARGSUSED*/ +void +print_file_trailer( Express express, FILES * files ) { + //FILEclose( files->incall ); + //FILEclose( files->initall ); + //fprintf( files->create, "}\n\n" ); + //FILEclose( files->create ); + //fprintf( files->classes, "\n" ); + //FILEclose( files->classes ); +} + +/****************************************************************** + ** SCHEMA SECTION **/ + +/****************************************************************** + ** Procedure: SCOPEPrint + ** Parameters: const Scope scope - scope to print + ** FILE* file - file on which to print + ** Returns: + ** Description: cycles through the scopes of the input Express schema + ** Side Effects: calls functions for processing entities and types + ** Status: working 1/15/91 + ** -- it's still not clear how include files should be organized + ** and what the relationship is between this organization and the + ** organization of the schemas in the input Express + ******************************************************************/ + +void +SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model, + ComplexCollect * col, int cnt ) { + Linked_List list = SCOPEget_entities_superclass_order( scope ); + DictionaryEntry de; + Type i; + int redefs = 0;// index = 0; + + /* fill in the values for the type descriptors */ + /* and print the enumerations */ + //fprintf( files -> inc, "\n/*\t************** TYPES \t*/\n" ); + //fprintf( files -> lib, "\n/*\t************** TYPES \t*/\n" ); + SCOPEdo_types( scope, t, de ) + // First check for one exception: Say enumeration type B is defined + // to be a rename of enum A. If A is in this schema but has not been + // processed yet, we must wait till it's processed first. The reason + // is because B will basically be defined with a couple of typedefs to + // the classes which represent A. (To simplify, we wait even if A is + // in another schema, so long as it's been processed.) + if( ( t->search_id == CANPROCESS ) + && ( TYPEis_enumeration( t ) ) + && ( ( i = TYPEget_ancestor( t ) ) != NULL ) + && ( i->search_id >= CANPROCESS ) ) { + redefs = 1; + } + SCOPEod + + SCOPEdo_types( scope, t, de ) + // Do the non-redefined enumerations: + if( ( t->search_id == CANPROCESS ) + && !( TYPEis_enumeration( t ) && TYPEget_head( t ) ) ) { + TYPEprint_descriptions( t, files, schema ); + if( !TYPEis_select( t ) ) { + // Selects have a lot more processing and are done below. + t->search_id = PROCESSED; + } + } + SCOPEod; + + if( redefs ) { + // Here we process redefined enumerations. See note, 2 loops ago. + SCOPEdo_types( scope, t, de ) + if( t->search_id == CANPROCESS && TYPEis_enumeration( t ) ) { + TYPEprint_descriptions( t, files, schema ); + t->search_id = PROCESSED; + } + SCOPEod; + } + // Write Schema Classes for each entity + // This must be done *before* typedefs are defined + LISTdo( list, e, Entity ); + if( e->search_id == CANPROCESS ) { + ENTITYPrint( e, files, schema ); + e->search_id = PROCESSED; + } + LISTod; + /* do the select definitions next, since they depend on the others */ + //fprintf( files->inc, "\n//\t***** Build the SELECT Types \t\n" ); + // Note - say we have sel B, rename of sel A (as above by enum's). Here + // we don't have to worry about printing B before A. This is checked in + // TYPEselect_print(). + SCOPEdo_types( scope, t, de ) + if( t->search_id == CANPROCESS ) { + // Only selects haven't been processed yet and may still be set to + // CANPROCESS. + TYPEselect_print( t, files, schema ); + t->search_id = PROCESSED; + } + SCOPEod; + LISTfree( list ); +} + + +void +PrintModelContentsSchema( Scope scope, FILES * files, Schema schema, + Express model ) { + Linked_List list; + char nm[BUFSIZ]; + DictionaryEntry de; + + //fprintf( files -> inc, "\n/*\t************** TYPES \t*/\n" ); + // Types should be exported to schema_name.DefinedDataTypes + //fprintf( files -> lib, "\n/*\t************** TYPES \t*/\n" ); + //fprintf( files -> init, "\n/*\t************** TYPES \t*/\n" ); + + /* do \'new\'s for types descriptors */ + SCOPEdo_types( scope, t, de ) + //TYPEprint_new( t, files->create, schema ); + SCOPEod; + + /* do \'new\'s for entity descriptors */ + list = SCOPEget_entities_superclass_order( scope ); + //fprintf( files->init, "\n\t//\t***** Describe the Entities \t*/\n" ); + fprintf( files->inc, "\n//\t***** Describe the Entities \t\n" ); + LISTdo( list, e, Entity ); + ENTITYput_superclass( e ); /* find supertype to use for single */ + ENTITYprint_new( e, files, schema, 0 ); /* inheritance */ + LISTod; + + // Print Entity Classes + LISTdo( list, e, Entity ); + ENTITYPrint( e, files, schema ); + LISTod; + /* fill in the values for the type descriptors */ + /* and print the enumerations */ + //fprintf(files->lib,"register_defined_types():\n"); + fprintf( files->inc, "\n//\t***** Describe the Other Types \t\n" ); + SCOPEdo_types( scope, t, de ) + TYPEprint_descriptions( t, files, schema ); + if( TYPEis_select( t ) ) { + /* do the select aggregates here */ + strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ ); + fprintf( files->inc, "class %s;\ntypedef %s * %sH;\n", nm, nm, nm ); + fprintf( files->inc, + "typedef %s * %s_ptr;\ntypedef %s_ptr %s_var;\n\n", + nm, nm, nm, nm ); + fprintf( files->inc, "class %ss;\ntypedef %ss * %ssH;\n", nm, nm, nm ); + fprintf( files->inc, + "typedef %ss * %ss_ptr;\ntypedef %ss_ptr %ss_var;\n\n", + nm, nm, nm, nm ); + } + SCOPEod; + + /* build the typedefs */ + SCOPEdo_types( scope, t, de ) + if( !( TYPEis_select( t ) ) ) { + TYPEprint_typedefs( t, files ->inc ); + } + SCOPEod; + + /* do the select definitions next, since they depend on the others */ + fprintf( files->inc, "\n//\t***** Build the SELECT Types \t\n" ); + //fprintf( files->init, "\n//\t***** Add the TypeDescriptor's to the" + // " SELECT Types \t\n" ); + SCOPEdo_types( scope, t, de ) + if( TYPEis_select( t ) ) { + TYPEselect_print( t, files, schema ); + } + SCOPEod; + +LISTfree( list ); +} + + + +/****************************************************************** + ** Procedure: SCHEMAprint + ** Parameters: const Schema schema - schema to print + ** FILES *file - file on which to print + ** Express model - fedex rep of entire EXPRESS file + ** ComplexCollect col - all the complex entity info pertaining + ** to this EXPRESS file + ** int suffix - suffix to use for generated cc files + ** Returns: + ** Description: handles initialization of files specific to schemas + ** Side Effects: + ** Status: + ******************************************************************/ + +void +SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol, + int suffix ) { + char schnm[MAX_LEN], sufnm[MAX_LEN], fnm[MAX_LEN], *np; + /* sufnm = schema name + suffix */ + FILE * libfile, + //*incfile, + //*schemafile = files->incall, + // *schemainit = files->initall, + *initfile + // *createall = files->create + ; + Rule r; + Function f; + Procedure p; + DictionaryEntry de; + char * tmpstr = 0; + unsigned int tmpstr_size = 0; + /********** create files based on name of schema ***********/ + /* return if failure */ + /* 1. header file */ + //sprintf( schnm, "%s%s", SCHEMA_FILE_PREFIX, + // StrToUpper( SCHEMAget_name( schema ) ) ); + sprintf( schnm, "%s", SCHEMAget_name( schema ) ); + if( suffix == 0 ) { + sprintf( sufnm, "%s", schnm ); + } else { + sprintf( sufnm, "%s_%d", schnm, suffix ); + } + sprintf( fnm, "%s.h", sufnm ); + + //if( !( incfile = ( files -> inc ) = FILEcreate( fnm ) ) ) { + // return; + //} + /* Generate local to SCHEMA.init.cc file */ + /* fprintf(incfile,"Schema *%s%s;\n",*/ + /* SCHEMA_PREFIX,SCHEMAget_name(schema));*/ + + /* fprintf (incfile, "extern void %sInit (Registry & r);\n", schnm);*/ + /* fprintf (incfile, "extern void SchemaInit (Registry & r);\n");*/ + + np = fnm + strlen( fnm ) - 1; /* point to end of constant part of string */ + + /* 2. class source file */ + sprintf( np, "py" ); + //if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { + if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { + return; + } + //fprintf( libfile, "/* %cId$ */ \n", '$' ); + fprintf(libfile,"from SCL.SCLBase import *\n"); + fprintf(libfile,"from SCL.SimpleDataTypes import *\n"); + fprintf(libfile,"from SCL.ConstructedDataTypes import *\n"); + fprintf(libfile,"from SCL.AggregationDataType import *\n"); + fprintf(libfile,"from SCL.TypeChecker import check_type\n"); + fprintf(libfile,"from SCL.Expr import *\n"); + + /********** do the schemas ***********/ + + /* really, create calls for entity constructors */ + SCOPEPrint( schema, files, schema, model, ( ComplexCollect * )complexCol, + suffix ); + + /********** close the files ***********/ + FILEclose( libfile ); + //FILEclose( incfile ); + //if( schema->search_id == PROCESSED ) { + // fprintf( initfile, "\n}\n" ); + // FILEclose( initfile ); + //} else { + // fclose( initfile ); + //} +} + +/****************************************************************** + ** Procedure: getMCPrint + ** Parameters: + Express express - in memory representation of an express model + FILE* schema_h - generated schema.h file + FILE* schema_cc - schema.cc file + ** Returns: + ** Description: drives functions to generate code for all the schemas + ** in an Express model into one set of files -- works with + ** print_schemas_combined + ** Side Effects: generates code + ** Status: 24-Feb-1992 new -kcm + ******************************************************************/ +void +getMCPrint( Express express, FILE * schema_h, FILE * schema_cc ) { + DictionaryEntry de; + Schema schema; + + fprintf( schema_h, + "\nSCLP23(Model_contents_ptr) GetModelContents(char *schemaName);\n" ); + fprintf( schema_cc, "%s%s%s%s", + "// Generate a function to be called by Model to help it\n", + "// create the necessary Model_contents without the\n", + "// dictionary (Registry) handle since it doesn't have a\n", + "// predetermined way to access to the handle.\n" ); + fprintf( schema_cc, + "\nSCLP23(Model_contents_ptr) GetModelContents(char *schemaName)\n{\n" ); + DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA ); + schema = ( Scope )DICTdo( &de ); + fprintf( schema_cc, + " if(!strcmp(schemaName, \"%s\"))\n", + SCHEMAget_name( schema ) ); + fprintf( schema_cc, + " return (SCLP23(Model_contents_ptr)) new SdaiModel_contents_%s; \n", + SCHEMAget_name( schema ) ); + while( ( schema = ( Scope )DICTdo( &de ) ) != 0 ) { + fprintf( schema_cc, + " else if(!strcmp(schemaName, \"%s\"))\n", + SCHEMAget_name( schema ) ); + fprintf( schema_cc, + " return (SCLP23(Model_contents_ptr)) new SdaiModel_contents_%s; \n", + SCHEMAget_name( schema ) ); + } + fprintf( schema_cc, "}\n" ); +} + +/****************************************************************** + ** Procedure: EXPRESSPrint + ** Parameters: + Express express -- in memory representation of an express model + FILES* files -- set of output files to print to + ** Returns: + ** Description: drives functions to generate code for all the schemas + ** in an Express model into one set of files -- works with + ** print_schemas_combined + ** Side Effects: generates code + ** Status: 24-Feb-1992 new -kcm + ******************************************************************/ +void +EXPRESSPrint( Express express, ComplexCollect & col, FILES * files ) { + char fnm [MAX_LEN], *np; + const char * schnm; /* schnm is really "express name" */ + FILE * libfile; + //FILE * incfile; + //FILE * schemafile = files -> incall; + //FILE * schemainit = files -> initall; + FILE * initfile; + /* new */ + Schema schema; + DictionaryEntry de; + + + /********** create files based on name of schema ***********/ + /* return if failure */ + /* 1. header file */ + sprintf( fnm, "%s.h", schnm = ClassName( EXPRESSget_basename( express ) ) ); + //if( !( incfile = ( files -> inc ) = FILEcreate( fnm ) ) ) { + // return; + //} + //fprintf( incfile, "/* %cId$ */\n", '$' ); + + //fprintf( incfile, "#ifdef __O3DB__\n" ); + //fprintf( incfile, "#include \n" ); + //fprintf( incfile, "#endif\n\n" ); + //fprintf( incfile, "#include \n" ); + /* fprintf (incfile, "#include \n");*/ + /* fprintf (incfile, "extern void %sInit (Registry & r);\n", schnm);*/ + + //np = fnm + strlen( fnm ) - 1; /* point to end of constant part of string */ + + /* 2. class source file */ + //sprintf( np, "cc" ); + if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { + return; + } + //fprintf( libfile, "/* %cId$ */\n", '$' ); + //fprintf( libfile, "#include <%s.h> n", schnm ); + + /* 3. source code to initialize entity registry */ + /* prints header of file for input function */ + + //sprintf( np, "init.cc" ); + //if( !( initfile = ( files -> init ) = FILEcreate( fnm ) ) ) { + // return; + //} + //fprintf( initfile, "/* $Id%d */\n", '$' ); + //fprintf( initfile, "#include <%s.h>\n\n", schnm ); + //fprintf( initfile, "void \n%sInit (Registry& reg)\n{\n", schnm ); + + /********** record in files relating to entire input ***********/ + + /* add to schema's include and initialization file */ + //fprintf( schemafile, "#include <%s.h>\n\n", schnm ); + //fprintf( schemafile, "extern void %sInit (Registry & r);\n", schnm ); + //fprintf( schemainit, "\t extern void %sInit (Registry & r);\n", schnm ); + //fprintf( schemainit, "\t %sInit (reg);\n", schnm ); + + /********** do all schemas ***********/ + DICTdo_init( express->symbol_table, &de ); + while( 0 != ( schema = ( Scope )DICTdo( &de ) ) ) { + SCOPEPrint( schema, files, schema, express, &col, 0 ); + } + + + /********** close the files ***********/ + FILEclose( libfile ); + //FILEclose( incfile ); + //fprintf( initfile, "\n}\n" ); + //FILEclose( initfile ); + +} + +/****************************************************************** + ** Procedure: print_schemas_combined + ** Parameters: + Express express -- in memory representation of an express model + FILES* files -- set of output files to print to + ** Returns: + ** Description: drives functions to generate code for all the schemas + ** in an Express model into one set of files -- works with EXPRESSPrint + ** Side Effects: generates code + ** Status: 24-Feb-1992 new -kcm + ******************************************************************/ + +void +print_schemas_combined( Express express, ComplexCollect & col, FILES * files ) { + + EXPRESSPrint( express, col, files ); +} + +/* +** Procedure: print_file +** Parameters: const Schema schema - top-level schema to print +** FILE* file - file on which to print +** Returns: void +** Description: this function calls one of two different functions +** depending on whether the output should be combined into a single +** set of files or a separate set for each schema +** +*/ + +void +print_file( Express express ) { + extern void RESOLUTIONsucceed( void ); + int separate_schemas = 1; + ComplexCollect col( express ); + + File_holder files; + + resolution_success(); + + print_file_header( express, &files ); + if( separate_schemas ) { + print_schemas_separate( express, ( void * )&col, &files ); + } else { + print_schemas_combined( express, col, &files ); + } + print_file_trailer( express, &files ); + //print_complex( col, ( const char * )"compstructs.cc" ); +} diff --git a/src/fedex_python/src/fedex_main_python.c b/src/fedex_python/src/fedex_main_python.c new file mode 100644 index 000000000..11e73c77a --- /dev/null +++ b/src/fedex_python/src/fedex_main_python.c @@ -0,0 +1,134 @@ + +/************************************************************************ +** Driver for Fed-X Express parser. +************************************************************************/ + +/* + * This software was developed by U.S. Government employees as part of + * their official duties and is not subject to copyright. + * + * $Log: fedex_main.c,v $ + * Revision 3.0.1.3 1997/11/05 23:12:18 sauderd + * Adding a new state DP3.1 and associated revision + * + * Revision 3.0.1.2 1997/09/26 15:59:10 sauderd + * Finished implementing the -a option (changed from -e) to generate the early + * bound access functions the old way. Implemented the change to generate them + * the new correct way by default. + * + * Revision 3.0.1.1 1997/09/18 21:18:41 sauderd + * Added a -e or -E option to generate attribute get and put functions the old + * way (without an underscore). It sets the variable old_accessors. This doesn't + * currently do anything. It needs to be implemented to generate attr funcs + * correctly. + * + * Revision 3.0.1.0 1997/04/16 19:29:03 dar + * Setting the first branch + * + * Revision 3.0 1997/04/16 19:29:02 dar + * STEP Class Library Pre Release 3.0 + * + * Revision 2.1.0.5 1997/03/11 15:33:59 sauderd + * Changed code so that if fedex_plus is passed the -c or -C option it would + * generate implementation objects for Orbix (CORBA). Look for code that is + * inside stmts such as if(corba_binding) + * + * Revision 2.1.0.4 1996/09/25 22:56:55 sauderd + * Added a command line argument for logging SCL use. The option added is -l or + * -L. It also says the option in the usage stmt when you run fedex_plus without + * an argument. Added the options to the EXPRESSgetopt_options string. + * + * Revision 2.1.0.3 1996/06/18 18:14:17 sauderd + * Changed the line that gets printed when you run fedex_plus with no + * arguments to include the option for single inheritance. + * + * Revision 2.1.0.2 1995/05/19 22:40:03 sauderd + * Added a command line argument -s or -S for generating code based on the old + * method as opposed to the new method of multiple inheritance. + * + * Revision 2.1.0.1 1995/05/16 19:52:18 lubell + * setting state to dp21 + * + * Revision 2.1.0.0 1995/05/12 18:53:48 lubell + * setting branch + * + * Revision 2.1 1995/05/12 18:53:47 lubell + * changing version to 2.1 + * + * Revision 1.7 1995/03/16 20:58:50 sauderd + * ? changes. + * + * Revision 1.6 1992/09/29 15:46:55 libes + * added messages for KC + * + * Revision 1.5 1992/08/27 23:28:52 libes + * moved Descriptor "new"s to precede assignments + * punted SELECT type + * + * Revision 1.4 1992/08/19 18:49:59 libes + * registry support + * + * Revision 1.3 1992/06/05 19:55:28 libes + * Added * to typedefs. Replaced warning kludges with ERRORoption. + */ + +#include +#include +#include "../express/express.h" +#include "../express/resolve.h" + +extern void print_fedex_version( void ); + +static void fedex_plus_usage( void ) { + fprintf( stderr, "usage: %s [-v] [-d # | -d 9 -l nnn -u nnn] [-n] [-p ] {-w|-i } express_file\n", EXPRESSprogram_name ); + //fprintf( stderr, "where\t-s or -S uses only single inheritance in the generated C++ classes\n" ); + //fprintf( stderr, "\t-a or -A generates the early bound access functions for entity classes the old way (without an underscore)\n" ); + //fprintf( stderr, "\t-c or -C generates C++ classes for use with CORBA (Orbix)\n" ); + //fprintf( stderr, "\t-L prints logging code in the generated C++ classes\n" ); + fprintf( stderr, "\t-v produces the version description below\n" ); + fprintf( stderr, "\t-d turns on debugging (\"-d 0\" describes this further\n" ); + //fprintf( stderr, "\t-p turns on printing when processing certain objects (see below)\n" ); + //fprintf( stderr, "\t-n do not pause for internal errors (useful with delta script)\n" ); + fprintf( stderr, "\t-w warning enable\n" ); + fprintf( stderr, "\t-i warning ignore\n" ); + fprintf( stderr, "and is one of:\n" ); + fprintf( stderr, "\tnone\n\tall\n" ); + LISTdo( ERRORwarnings, opt, Error_Warning ) + fprintf( stderr, "\t%s\n", opt->name ); + LISTod + fprintf( stderr, "and is one or more of:\n" ); + fprintf( stderr, " e entity\n" ); + fprintf( stderr, " p procedure\n" ); + fprintf( stderr, " r rule\n" ); + fprintf( stderr, " f function\n" ); + fprintf( stderr, " t type\n" ); + fprintf( stderr, " s schema or file\n" ); + fprintf( stderr, " # pass #\n" ); + fprintf( stderr, " E everything (all of the above)\n" ); + print_fedex_version(); + exit( 2 ); +} + +int Handle_FedPlus_Args( int, char * ); +void print_file( Express ); + +void resolution_success( void ) { + printf( "Resolution successful.\nWriting python module..." ); +} + +int success( Express model ) { + printf( "Done.\n" ); + return( 0 ); +} + +/* This function is called from main() which is part of the NIST Express + Toolkit. It assigns 2 pointers to functions which are called in main() */ +void EXPRESSinit_init() { + EXPRESSbackend = print_file; + EXPRESSsucceed = success; + EXPRESSgetopt = Handle_FedPlus_Args; + /* so the function getopt (see man 3 getopt) will not report an error */ + strcat( EXPRESSgetopt_options, "sSLcCaA" ); + ERRORusage_function = fedex_plus_usage; +} + diff --git a/src/fedex_python/src/multpass_python.c b/src/fedex_python/src/multpass_python.c new file mode 100644 index 000000000..e07141574 --- /dev/null +++ b/src/fedex_python/src/multpass_python.c @@ -0,0 +1,729 @@ +/***************************************************************************** + * multpass.c * + * * + * Description: * + * Adds multi-schema support enhancement to fedex_plus parser. Allows the * + * generation of C++ representations for multiple EXPRESS schemas without * + * creating conflicting header files. Previously, fedex_plus would gene- * + * rate a single set of files (.h, .cc, .init.cc) for each schema found in * + * the processed EXPRESS file. A number of problem situations occurred: * + * * + * (1) Two schemas which USE or REFERENCE entities from one another. If * + * e.g. schema A USEs entity 1 from schema B and defines ent 2 subtype * + * of 1, and schema B USEs ent 2 from A and defines ents 1 and 3 sub- * + * type of 2, neither include file could be compiled first. * + * (2) An entity which has a select or enumeration attribute which is de- * + * fined in another schema. * + * (3) A select type which has a select or enum member item which is de- * + * fined in another schema. + * (4) An enumeration type which is a redefinition of an enum defined in * + * another schema. * + * * + * The functions in multpass.c provide for the processing of each schema * + * in multiple passes. At each pass, only entities and types which are * + * not dependent on undefined objects are processed. With each pass, more * + * entities and types become defined and more dependent entities and types * + * will become processable. At each state of processing, a separate set * + * of C++ files is generated. Lastly, multpass processes certain aggre- * + * gate and redefined objects after all the fundamental types are defined. * + * * + * Created by: David Rosenfeld * + * Date: 04/09/97 * + *****************************************************************************/ + +#include +#include "classes.h" + +#define FALSE 0 +#define TRUE 1 + +int isAggregateType( const Type t ); + +/* Local function prototypes: */ +static void initializeMarks( Express ); +static void unsetObjs( Schema ); +static int checkTypes( Schema ); +static int checkEnts( Schema ); +static void markDescs( Entity ); +static int checkItem( Type, Scope, Schema, int *, int ); +static int ENUMcanBeProcessed( Type, Schema ); +static int inSchema( Scope, Scope ); +static void addRenameTypedefs( Schema, FILE * ); +static void addAggrTypedefs( Schema , FILE * ); +static void addUseRefNames( Schema, FILE * ); + +void print_schemas_separate( Express express, void * complexCol, FILES * files ) +/* + * Generates the C++ files corresponding to a list of schemas. Does so in + * multiple passes through the schemas. In each pass it checks for enti- + * ties which are subtypes of entites in other schemas which have not yet + * been processed. Such entities cannot be processed in that pass until + * their supertypes have been defined. It also checks for entities which + * have enum or select attributes which have not been processed, and for + * select types which have enum or select items (or entities containing + * enums) which have not been processed. + */ +{ + int complete = FALSE, val1, val2, suffix; + DictionaryEntry de; + Schema schema; + + /* First set all marks we'll be using to UNPROCESSED/NOTKNOWN: */ + initializeMarks( express ); + + //FIXME SdaiAll.cc:12:24: warning: unused variable ā€˜is’ [-Wunused-variable] (also for ui & ri) + //fprintf( files->create, " Interface_spec_ptr is;\n Used_item_ptr ui;\n Referenced_item_ptr ri;\n Uniqueness_rule_ptr ur;\n Where_rule_ptr wr;\n Global_rule_ptr gr;\n" ); + while( !complete ) { + complete = TRUE; + DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA ); + while( ( schema = ( Scope )DICTdo( &de ) ) != 0 ) { + if( schema->search_id == UNPROCESSED ) { + /* i.e., if the schema has more ents/types to process in it */ + unsetObjs( schema ); + /* Unset the ones which had search_id = CANTPROCESS. We're + // going to check that again since things may have changed by + // this pass. The ones with search_id = PROCESSED do not + // change since we're done with them. */ + schema->search_id = PROCESSED; + /* We assume this is the case unless something goes wrong. */ + val1 = checkTypes( schema ); + val2 = checkEnts( schema ); + /* The check functions recheck all the ents, types, USEd, and + // REFs which are still NOTKNOWN to see if we can process any + // more this pass. If any returns TRUE, we'll process again + // this round. */ + if( val1 || val2 ) { + if( schema->search_id == UNPROCESSED || + *( int * )schema->clientData > 0 ) { + /* What we're trying to determine here is if we will + // need to print multiple files for this schema. If + // we're already beyond a first file (2nd condition) + // or we're at the first but there are more entities + // which couldn't be processed yet (and thus search_id + // was still set to UNPROCESSED), this schema will be + // printed in multiple files. If so, SCHEMAprint() + // will create files with the suffixes "_1", "_2", etc. + // If not, no file suffix will be added. */ + suffix = ++*( int * )schema->clientData; + SCHEMAprint( schema, files, express, complexCol, + suffix ); + } else { + SCHEMAprint( schema, files, express, complexCol, 0 ); + } + } + complete = complete && ( schema->search_id == PROCESSED ); + /* Job's not complete so long as schema still has entities it + // had to skip. */ + } + } + } + + /******************* + *******************/ + + DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA ); + while( ( schema = ( Scope )DICTdo( &de ) ) != 0 ) { + //fprintf( files->create, + // "\t//////////////// USE statements\n" ); + //USEREFout( schema, schema->u.schema->usedict, schema->u.schema->use_schemas, "USE", files->create ); + + //fprintf( files->create, + // "\t//////////////// REFERENCE statements\n" ); + //USEREFout( schema, schema->u.schema->refdict, schema->u.schema->ref_schemas, "REFERENCE", files->create ); + } + /***************** + *****************/ + /* Before closing, we have three more situations to deal with (i.e., three + // types of declarations etc. which could only be printed at the end). + // Each is explained in the header section of its respective function. */ + DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA ); + while( ( schema = ( Scope )DICTdo( &de ) ) != 0 ) { + /* (These two tasks are totally unrelated but are done in the same loop + // for efficiency.) */ + addRenameTypedefs( schema, files->classes ); + addUseRefNames( schema, files->create ); + } + /* Third situation: (Must be dealt with after first, see header comments + // of addAggrTypedefs.) */ + DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA ); + while( ( schema = ( Scope )DICTdo( &de ) ) != 0 ) { + addAggrTypedefs( schema, files->classes ); + } + + /* On our way out, print the necessary statements to add support for + // complex entities. (The 1st line below is a part of SchemaInit(), + // which hasn't been closed yet. (That's done on 2nd line below.)) */ + //fprintf( files->initall, "\t reg.SetCompCollect( gencomplex() );\n" ); + //fprintf( files->initall, "}\n\n" ); + //fprintf( files->incall, "\n#include \n" ); + //fprintf( files->incall, "ComplexCollect *gencomplex();\n" ); + + /* Function GetModelContents() is printed at the end of the schema.xx + // files. This is done in a separate loop through the schemas, in function + // below. */ + //getMCPrint( express, files->incall, files->initall ); +} + +static void initializeMarks( Express express ) +/* + * Set all schema->search_id's to UNPROCESSED, meaning we haven't processed + * all the ents and types in it yet. Also, put an int=0 in each schema's + * clientData field. We'll use it to record what # file we're generating + * for each schema. Set all entity and type search_id's to NOTKNOWN mean- + * we don't know if we can process it yet. (An ent & select type may have + * an attribute/item which comes from another schema. All other types can + * be processed the first time, but that will be caught in checkTypes().) + */ +{ + DictionaryEntry de_sch, de_ent, de_type; + Schema schema; + + DICTdo_type_init( express->symbol_table, &de_sch, OBJ_SCHEMA ); + while( ( schema = ( Scope )DICTdo( &de_sch ) ) != 0 ) { + schema->search_id = UNPROCESSED; + schema->clientData = ( int * )malloc( sizeof( int ) ); + *( int * )schema->clientData = 0; + SCOPEdo_entities( schema, ent, de_ent ) + ent->search_id = NOTKNOWN; + SCOPEod + SCOPEdo_types( schema, t, de_type ) + t->search_id = NOTKNOWN; + SCOPEod + } +} + +static void unsetObjs( Schema schema ) +/* + * Resets all the ents & types of schema which had been set to CANTPROCRSS + * to NOTKNOWN. This function is called every time print_schemas_separate + * iterates through the schemas, printing to file what can be printed. At + * each pass we re-examine what ents/types can be processed. Ones which + * couldn't be processed at the last pass may be processable now. Ents/ + * types which have already been marked PROCESSED will not have to be + * revisited, and are not changed. + */ +{ + DictionaryEntry de; + + SCOPEdo_types( schema, t, de ) + if( t->search_id == CANTPROCESS ) { + t->search_id = NOTKNOWN; + } + SCOPEod + SCOPEdo_entities( schema, ent, de ) + if( ent->search_id == CANTPROCESS ) { + ent->search_id = NOTKNOWN; + } + SCOPEod +} + +static int checkTypes( Schema schema ) +/* + * Goes through the types contained in this schema checking for ones which + * can't be processed. This may be the case if: (1) We have a select type + * which has enumeration or select items which have not yet been defined + * (are defined in a different schema we haven't processed yet). (2) We + * have a select which has an entity item which contains unprocessed enums. + * (Unproc'ed selects, however, do not pose a problem here for reasons + * beyond the scope.) (3) We have an enum type which is a redefinition of + * an enum not yet defined. If we find any such type, we set its mark to + * CANTPROCESS. If some types in schema *can* be processed now, we return + * TRUE. (See relevant header comments of checkEnts() below.) + */ +{ + DictionaryEntry de; + int retval = FALSE, unknowncnt; + Type i; + Entity ent; + Linked_List attribs; + + do { + unknowncnt = 0; + SCOPEdo_types( schema, type, de ) + if( type->search_id != NOTKNOWN ) { + continue; + } + /* We're only interested in the ones which haven't been processed + // already or accepted (set to CANPROCESS in a previous pass thru + // the do loop) already. */ + type->search_id = CANPROCESS; + /* Assume this until disproven. */ + + if( TYPEis_enumeration( type ) && TYPEget_head( type ) ) { + i = TYPEget_ancestor( type ); + if( !sameSchema( i, type ) && i->search_id != PROCESSED ) { + /* Note - if, however, i is in same schema, we're safe: We + // know it'll be processed this pass because enum's are + // always processed on the first pass. (We do have to take + // care to process the original enum before the redefined. + // This is done in SCOPEPrint, in classes_wrapper.cc.) */ + type->search_id = CANTPROCESS; + schema->search_id = UNPROCESSED; + } + } else if( TYPEis_select( type ) ) { + LISTdo( SEL_TYPEget_items( type ), i, Type ) + if( !TYPEis_entity( i ) ) { + if( checkItem( i, type, schema, &unknowncnt, 0 ) ) { + break; + } + /* checkItem does most of the work of determining if + // an item of a select will make the select type un- + // processable. It checks for conditions which would + // make this true and sets values in type, schema, and + // unknowncnt accordingly. (See checkItem's commenting + // below.) It also return TRUE if i has made type un- + // processable. If so, we break - there's no point + // checking the other items of type any more. */ + } else { + /* Check if our select has an entity item which itself + // has unprocessed selects or enums. */ + ent = ENT_TYPEget_entity( i ); + if( ent->search_id == PROCESSED ) { + continue; + } + /* If entity has been processed already, things must be + // okay. (Note - but if it hasn't been processed yet we + // may still be able to process type. This is because + // a sel type will only contain a pointer to an entity- + // item (and we can create a pointer to a not-yet-pro- + // cessed object), while it will contain actual objects + // for the enum and select attributes of ent.) */ + attribs = ENTITYget_all_attributes( ent ); + LISTdo( attribs, attr, Variable ) + if( checkItem( attr->type, type, schema, + &unknowncnt, 1 ) ) { + break; + } + LISTod + LISTfree( attribs ); + } + LISTod + /* One more condition - if we're a select which is a rename of + // another select - we must also make sure the original select + // is in this schema or has been processed. Since a rename- + // select is defined with typedef's to the original, we can't + // do that if the original hasn't been defined. */ + if( ( type->search_id == CANPROCESS ) + && ( ( i = TYPEget_ancestor( type ) ) != NULL ) + && ( !sameSchema( i, type ) ) + && ( i->search_id != PROCESSED ) ) { + type->search_id = CANTPROCESS; + schema->search_id = UNPROCESSED; + } + } + + if( type->search_id == CANPROCESS ) { + /* NOTE - This condition will be met if type isn't a select or + // enum at all and above if was never entered (and it's our + // first pass so type hasn't been processed). So for non-enums + // and selects, checkTypes() will simply check the type off and + // go on. */ + retval = TRUE; + } + SCOPEod + } while( unknowncnt > 0 ); + /* We loop to deal with the following situation: Say sel A contains enum B + // as an item, but A appears earlier in the EXPRESS file than B. In such a + // case, we really can process A now since it doesn't depend on anything + // which won't be processed till later. But when we first reach A, item B + // will have value NOTKNOWN, and at the time we won't know if B will be set + // to CANPROCESS when we get to it. To deal with this, checkItem() below + // increments unknowncnt for every item which is in this schema and still + // has search_id = NOTKNOWN. (Not if id = CANTPROCESS, which means we've + // tried already this pass and B still can't be processed.) Here, we keep + // looping until all the unknowns are resolved. (It may take may passes if + // selX has item selY which has item selZ.) (I take all the trouble with + // this so as not to generate mult files in unnecessary cases where e.g. + // the EXPRESS is in a single schema.) */ + + return retval; +} + +static int checkEnts( Schema schema ) +/* + * Goes through the entities contained in this schema checking for ones + * which can't be processed. It checks for two situations: (1) If we find + * an entity which is a subtype of a not-yet-processed entity in another + * schema. (2) If an entity has an attribute which is an enumeration or + * select type (which is implemented by fedex_plus as a C++ class), and the + * enum or select class has not yet been defined. For each entity which + * satisfies one of the above conditions, we set its mark and the marks of + * all its subtype descendents to CANTPROCESS. Later, when C++ files are + * generated for this schema, the ents marked CANTPROCESS will be skipped. + * checkEnts() will return TRUE if there are some ents/types which *can* be + * processed now. This will tell later functions that there are some pro- + * cessable entities at this pass and C++ files should be generated. (Some + * of the inline commenting of checkTypes() is applicable here and is not + * repeated.) + */ +{ + DictionaryEntry de; + int retval = FALSE, ignore = 0; + + /* Loop through schema's entities: */ + SCOPEdo_entities( schema, ent, de ) + if( ent->search_id != NOTKNOWN ) { + continue; + } + /* ent->search_id may = CANTPROCESS signifying we've already determined + // that this ent is dependent on an undefined external one. (It got + // its mark already because it was the descendent of a parent entity we + // already checked and rejected.) ent->search_id may = PROCESSED. In + // such a case there of course is also nothing to check now. */ + ent->search_id = CANPROCESS; + + /* First traverse ent's supertypes. If any is from a different schema + // and is not yet defined, ent will have to wait. */ + LISTdo( ENTITYget_supertypes( ent ), super, Entity ) + if( ( !sameSchema( ent, super ) ) + && ( super->search_id != PROCESSED ) ) { + markDescs( ent ); + schema->search_id = UNPROCESSED; + break; + /* Exit the LISTdo loop. Since we found an unprocessed + // parent, we're done with this entity. */ + } + LISTod + + /* Next traverse ent's attributes, looking for attributes which are + // not yet defined (more explanation in checkItem()). */ + if( ent->search_id == CANPROCESS ) { + /* Only do next test if ent hasn't already failed the 1st. */ + LISTdo( ENTITYget_attributes( ent ), attr, Variable ) + if( checkItem( attr->type, ent, schema, &ignore, 0 ) ) { + markDescs( ent ); + break; + } + LISTod + } + + if( ent->search_id == CANPROCESS ) { + /* If ent's mark still = CANPROCESS and not CANTPROCESS, it + // must still be processable. Set retval to TRUE signifying + // that there are ent's we'll be able to process. */ + retval = TRUE; + } + SCOPEod + /* NOTE - We don't have to loop here as in checkTypes() (see long comment + // there). It was necessary there because we may have processed type + // sel1 before its member enum1. Whereas here, since all types are done + // before selects (checkTypes() is called before checkEnts()), there is + // no such concern. */ + + return retval; +} + +static void markDescs( Entity ent ) +/* + * Sets the mark value of ent and all its subtypes to CANTPROCESS. This + * function is called if we've determined that ent is a subtype of an + * entity defined in a different schema which has not yet been processed. + */ +{ + ent->search_id = CANTPROCESS; + LISTdo( ENTITYget_subtypes( ent ), sub, Entity ) + markDescs( sub ); + LISTod +} + +static int checkItem( Type t, Scope parent, Schema schema, int * unknowncnt, + int noSel ) +/* + * Function with a lot of side effects: Checks if type t, a member of + * `parent' makes parent unprocessable. parent may be an entity and t is + * its attribute. parent may be a select type and t is one of its items. + * parent may be a select type and t an attribute of one of its entity + * items. Lastly, parent may be an aggregate and t its base type. t will + * make parent unprocessable if it is an enum or sel which hasn't been + * processed yet, see inline commenting. If so, parent->search_id is set + * to CANTPROCESS, and schema->search_id is set to UNPROCESSED (i.e., we're + * not done yet). Also, if one of parent's items is still NOTKNOWN (caused + * if it's in our schema and we haven't gotten to it yet - see comment, end + * of checkTypes()), parent is set to NOTKNOWN and unknowncnt is incremen- + * ted to tell us that we'll have to try parent again after its item has + * been processed (i.e., we have to repeat the do-loop in checkTypes()). + * checkItem returns TRUE if parent became unprocessable; FALSE otherwise. + * + * NOTE: noSel deals with the following: Say selA has member entX. If + * entX has attribute enumP, it creates a problem, while if entX has attr + * selB, it is not. When using checkItem for an ent member of a select, + * noSel is set to 1 to tell it to worry about t if it's an enum but not + * if it's a select. + */ +{ + Type i = t; + + if( isAggregateType( t ) ) { + i = TYPEget_base_type( t ); + /* NOTE - If t is a 2D aggregate or higher, we do not go down to its + // lowest base type. An item which is a higher dimension aggregates + // does not make its parent unprocessable. All an e.g. entity needs + // defined to have a 2D aggr attribute is GenericAggregate (built in) + // and a typedef for a pointer to the type name, which is declared in + // Sdaiclasses.h. */ + } + + if( TYPEis_enumeration( i ) && !ENUMcanBeProcessed( i, schema ) ) { + /* Enum's are usually processed on the first try. ENUMcanBeProcessed() + // checks for cases of renamed enum's, which must wait for the enum i + // is a rename of. */ + if( parent->search_id == NOTKNOWN ) { + /* We had thought parent's val was going to be NOTKNOWN - i.e., + // dependent on other selects in this schema which haven't been + // processed. When we set it to NOTKNOWN we also incremented + // unknowncnt. Now we see it's not going to be unknown so we + // decrement the count: */ + ( *unknowncnt )--; + } + parent->search_id = CANTPROCESS; + schema->search_id = UNPROCESSED; + return TRUE; + } else if( TYPEis_select( i ) && !noSel ) { + if( !sameSchema( i, parent ) ) { + if( i->search_id != PROCESSED ) { + if( parent->search_id == NOTKNOWN ) { + ( *unknowncnt )--; + } + parent->search_id = CANTPROCESS; + schema->search_id = UNPROCESSED; + return TRUE; + } + } else { + /* We have another sel in the same schema. This gets complicated - + // it may be processable but we just haven't gotten to it yet. So + // we may have to wait on parent. */ + if( i->search_id == CANTPROCESS ) { + /* We *have* checked i already and it can't be processed. */ + if( parent->search_id == NOTKNOWN ) { + ( *unknowncnt )--; + } + parent->search_id = CANTPROCESS; + schema->search_id = UNPROCESSED; + return TRUE; + } else if( i->search_id == NOTKNOWN ) { + /* We haven't processed i this pass. */ + if( parent->search_id != NOTKNOWN ) { + parent->search_id = NOTKNOWN; + /* We lower parent's value. But don't return TRUE. That + // would tell checkTypes() that there's nothing more to + // check. But checkTypes should keep looping thru the re- + // maining items of parent - maybe one of them will tell us + // that parent definitely can't be processed this pass. */ + ( *unknowncnt )++; + } + } + } + } + return FALSE; +} + +static int ENUMcanBeProcessed( Type e, Schema s ) +/* + * Tells us if an enumeration type has been processed already, or if not + * will be processed this pass through schema s. As always, I take great + * pains to avoid breaking up a schema into >1 file unnecessarily. In + * cases where a user is building a library based on a single schema, we + * shouldn't cause him to suffer side-effects of the mult schema support, + * because of a case that "looks like" it may require multiple files. + */ +{ + Type a; + + if( !inSchema( e, s ) ) { + /* If e is not in s - the schema we're processing now - things are + // fairly simple. Nothing is going to change by the time we finish + // with this schema. Base the return val on whether or not e *was* + // processed already. */ + return ( e->search_id == PROCESSED ); + } + + if( e->search_id != NOTKNOWN ) { + /* Next case: e is in our schema, but either it's been processed + // already, or we've determined that it can or can't be processed. + // This case is also relatively simple - we have nothing more to + // figure out here. */ + return ( e->search_id >= CANPROCESS ); + /* PROC/CANPROC - TRUE; UNPROC'ED/CANTPROC - FALSE */ + } + + /* Remaining case: e is in our schema and still = NOTKNOWN. I.e., we + // haven't gotten to e this pass and don't yet know whether it'll be + // processable. Figure that out now: */ + if( ( a = TYPEget_ancestor( e ) ) == NULL ) { + /* If e is not a rename of anything, it should be processed now. */ + return TRUE; + } + if( inSchema( a, s ) || a->search_id == PROCESSED ) { + /* If e's ancestor (the one it's a rename of) is in our schema it will + // be processed now. If not, it must have been processed already. */ + return TRUE; + } + return FALSE; +} + +int sameSchema( Scope sc1, Scope sc2 ) +/* + * Checks if sc1 and sc2 are in the same superscope. Normally called for + * two types to see if they're in the same schema. + */ +{ + return ( !strcmp( SCOPEget_name( sc1->superscope ), + SCOPEget_name( sc2->superscope ) ) ); +} + +static int inSchema( Scope scope, Scope super ) +/* + * Checks if scope is contained in super's scope. + */ +{ + return ( !strcmp( SCOPEget_name( scope->superscope ), + SCOPEget_name( super ) ) ); +} + +static void addRenameTypedefs( Schema schema, FILE * classes ) +/* + * Prints typedefs at the end of Sdaiclasses.h for enumeration or select + * types which are renamed from other enum/sel's. Since the original e/s + * may be in any schema, this must be done at the end of all the schemas. + * (Actually, for the enum only the aggregate class name is written in + * Sdaiclasses.h (needs to have forward declarations here).) + */ +{ + DictionaryEntry de; + Type i; + char nm[BUFSIZ], basenm[BUFSIZ]; + static int firsttime = TRUE; + + SCOPEdo_types( schema, t, de ) + if( ( TYPEis_enumeration( t ) || TYPEis_select( t ) ) + && ( ( i = TYPEget_ancestor( t ) ) != NULL ) ) { + /* I.e., t is a renamed enum/sel type. i is set to the orig enum/ + // sel t is based on (in case it's a rename of a rename etc). */ + if( firsttime ) { + printf( "\n// Renamed enum and select\n" ); + //printf( " types (from all schemas):\n" ); + firsttime = FALSE; + } + if( TYPEis_enumeration( t ) ) { + strncpy( nm, TYPEget_ctype( t ), BUFSIZ - 1 ); + strncpy( basenm, TYPEget_ctype( i ), BUFSIZ - 1 ); + //fprintf( classes, "typedef %ss\t%ss;\n", basenm, nm ); + } else { + strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ - 1 ); + strncpy( basenm, SelectName( TYPEget_name( i ) ), BUFSIZ - 1 ); + printf( "typedef %s %s;\n", basenm, nm ); + //fprintf( "typedef %s * %s_ptr;\n", nm, nm ); + //fprintf( classes, "typedef %ss %ss;\n", basenm, nm ); + //fprintf( classes, "typedef %ss * %ss_ptr;\n", nm, nm ); + } + } + SCOPEod +} + +static void addAggrTypedefs( Schema schema, FILE * classes ) +/* + * Print typedefs at the end of Sdiaclasses.h for aggregates of enum's and + * selects. Since the underlying enum/sel may appear in any schema, this + * must be done at the end of all the schemas. Note that this function is + * called after addRenameTypedefs() since an aggregate may also be based on + * one of the renamed enum/sel's defined there. + */ +{ + DictionaryEntry de; + Type i; + static int firsttime = TRUE; + char nm[BUFSIZ]; + + SCOPEdo_types( schema, t, de ) + if( TYPEis_aggregate( t ) ) { + i = TYPEget_base_type( t ); + if( TYPEis_enumeration( i ) || TYPEis_select( i ) ) { + /* This if will pass if t was a 1D aggregate only. They are + // the only types which had to wait for their underlying type. + // 2D aggr's and higher only need type GenericAggr defined + // which is built-in. */ + if( firsttime ) { + fprintf( classes, "\n// Aggregate types (from all sche" ); + fprintf( classes, "mas) which depend on other types:\n" ); + firsttime = FALSE; + } + strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); + fprintf( classes, "typedef %s\t%s;\n", + TYPEget_ctype( t ), nm ); + fprintf( classes, "typedef %s *\t%sH;\n", nm, nm ); + fprintf( classes, "typedef %s *\t%s_ptr;\n", nm, nm ); + } + } + SCOPEod +} + +static void addUseRefNames( Schema schema, FILE * create ) +/* + * Checks the USE and REFERENCE dicts contained in schema. If either dict + * contains items (types or entities) which are renamed in this schema, + * code is written to add another member to the "altNames" list of the + * corresponding TypeDescriptor or EntityDescriptor object in the SCL. The + * list will be used in the SCL to use the correct name of this type or + * entity when reading and writing files. + */ +{ + Dictionary useRefDict; + DictionaryEntry de; + Rename * rnm; + char * oldnm, schNm[BUFSIZ]; + static int firsttime = TRUE; + + if( ( useRefDict = schema->u.schema->usedict ) != NULL ) { + DICTdo_init( useRefDict, &de ); + while( ( rnm = ( Rename * )DICTdo( &de ) ) != 0 ) { + oldnm = ( ( Scope )rnm->object )->symbol.name; + if( ( strcmp( oldnm, rnm->nnew->name ) ) ) { + /* strcmp != 0, so old and new names different. + // Note: can't just check if nnew != old. That wouldn't + // catch following: schema C USEs obj Y from schema B + // (not renamed). B USEd it from schema A and renamed it + // from X. nnew would = old, but name would not be same + // as rnm->object's name. */ + if( firsttime ) { + fprintf( create, "\t// Alternate names for types and " ); + fprintf( create, "entities when used in other schemas:\n" ); + firsttime = FALSE; + } + if( rnm->type == OBJ_TYPE ) { + fprintf( create, "\t%s", TYPEtd_name( ( Type )rnm->object ) ); + } else { + /* must be an entity */ + fprintf( create, "\t%s%s%s", + SCOPEget_name( ( ( Entity )rnm->object )->superscope ), + ENT_PREFIX, ENTITYget_name( ( Entity )rnm->object ) ); + } + strcpy( schNm, PrettyTmpName( SCHEMAget_name( schema ) ) ); + fprintf( create, "->addAltName( \"%s\", \"%s\" );\n", + schNm, PrettyTmpName( rnm->nnew->name ) ); + } + } + } + if( ( useRefDict = schema->u.schema->refdict ) != NULL ) { + DICTdo_init( useRefDict, &de ); + while( ( rnm = ( Rename * )DICTdo( &de ) ) != 0 ) { + oldnm = ( ( Scope )rnm->object )->symbol.name; + if( ( strcmp( oldnm, rnm->nnew->name ) ) ) { + if( firsttime ) { + fprintf( create, "\t// Alternate names for types and " ); + fprintf( create, "entities when used in other schemas:\n" ); + firsttime = FALSE; + } + if( rnm->type == OBJ_TYPE ) { + fprintf( create, "\t%s", TYPEtd_name( ( Type )rnm->object ) ); + } else { + fprintf( create, "\t%s%s%s", + SCOPEget_name( ( ( Entity )rnm->object )->superscope ), + ENT_PREFIX, ENTITYget_name( ( Entity )rnm->object ) ); + } + strcpy( schNm, PrettyTmpName( SCHEMAget_name( schema ) ) ); + fprintf( create, "->addAltName( \"%s\", \"%s\" );\n", + schNm, PrettyTmpName( rnm->nnew->name ) ); + } + } + } +} diff --git a/src/fedex_python/src/selects_python.c b/src/fedex_python/src/selects_python.c new file mode 100644 index 000000000..78dcc8e22 --- /dev/null +++ b/src/fedex_python/src/selects_python.c @@ -0,0 +1,1946 @@ +/******************************************************************* +** FedEx parser output module for generating C++ class definitions +** December 5, 1989 +** release 2 17-Feb-1992 +** release 3 March 1993 +** release 4 December 1993 +** K. C. Morris +** +** Development of FedEx was funded by the United States Government, +** and is not subject to copyright. + +******************************************************************* +The conventions used in this binding follow the proposed specification +for the STEP Standard Data Access Interface as defined in document +N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7. +*******************************************************************/ + +extern int multiple_inheritance; + +/************************************************************************** +******** The functions in this file generate C++ code for representing +******** EXPRESS SELECT types. +**************************************************************************/ +#include +#include "classes.h" + +int isAggregateType( const Type t ); +char * generate_attribute_name( Variable a, char * out ); +char * FundamentalType( const Type t, int report_reftypes ); +void ATTRsign_access_methods( Variable a, FILE * file ); +char * generate_attribute_func_name( Variable a, char * out ); +void ATTRprint_access_methods_get_head( const char * classnm, Variable a, FILE * file ); +void ATTRprint_access_methods_put_head( const char * entnm, Variable a, FILE * file ); + +#define BASE_SELECT "SCLP23(Select)" + +#define TYPEis_primitive(t) ( !( TYPEis_entity(t) || \ + TYPEis_select (t) || \ + TYPEis_aggregate(t) ) ) + +#define TYPEis_numeric(t) ( ((t)->u.type->body->type == real_) || \ + ((t)->u.type->body->type == integer_) || \ + ((t)->u.type->body->type == number_) ) +#define PRINT_BUG_REPORT \ + fprintf( f, " std::cerr << __FILE__ << \":\" << __LINE__ << \": ERROR" \ + " in schema library: \\n\" \n\t<< _POC_ << \"\\n\\n\";\n"); + +#define PRINT_SELECTBUG_WARNING(f) \ + fprintf( (f), "\n severity( SEVERITY_WARNING );\n" ); \ + fprintf( (f), " std::cerr << __FILE__ << \":\" << __LINE__ << \": "); \ + fprintf( (f), "WARNING: possible misuse of\"\n << \" SELECT "); \ + fprintf( (f), "TYPE from schema library.\\n\";\n"); \ + fprintf( (f), " Error( \"Mismatch in underlying type.\" );\n" ); + +#define print_error_msg() \ + fprintf( f, "\n severity( SEVERITY_BUG );\n" ); \ + PRINT_BUG_REPORT \ + fprintf( f, " Error( \"This 'argument' is of the incorrect type\" );\n" ); + +#define TRUE 1 +#define FALSE 0 + +static void initSelItems( const Type, FILE * ); + +const char * +SEL_ITEMget_enumtype( Type t ) { + return StrToUpper( TYPEget_name( t ) ); +} + + +/****************************************************************** + ** Procedure: TYPEget_utype + ** Parameters: Type t + ** Returns: type used to represent the underlying type in a select class + ** Description: + ** Side Effects: + ** Status: + ******************************************************************/ + +const char * +TYPEget_utype( Type t ) { + /* + static char b [BUFSIZ]; + strncpy (b, TYPEget_ctype (t), BUFSIZ-2); + if (TYPEis_select (t)) strcat (b, "H"); + */ + return ( TYPEis_entity( t ) ? "SCLP23(Application_instance_ptr)" : TYPEget_ctype( t ) ); +} + +/******************* +LISTmember + +determines if the given entity is a member of the list. +RETURNS the member if it is a member; otherwise 0 is returned. +*******************/ +Generic +LISTmember( const Linked_List list, Generic e ) { + Link node; + for( node = list->mark->next; node != list->mark; node = node->next ) + if( e == node -> data ) { + return e; + } + return ( 0 ); +} + +/******************* + compareOrigTypes + + Specialized function to catch if two enumerations, two selects, or two aggrs + of either, are of the same type. The issue is that e.g. select B may be a + rename of sel A (i.e., TYPE B = A;). Such renamed types are implemented by + fedex_plus with typedefs, so that they are in fact the same type. TYPEget_- + ctype() is used for most type comparisons and does not consider renamed types + equivalent. This function is called in instances when they should be consi- + dered equivalent. One such case is the generation of duplicate lists. + *******************/ +static int +compareOrigTypes( Type a, Type b ) { + Type t, u; + + if( ( TYPEis_select( a ) && TYPEis_select( b ) ) + || ( TYPEis_enumeration( a ) && TYPEis_enumeration( b ) ) ) { + t = a; + u = b; + } else if( TYPEis_aggregate( a ) && TYPEis_aggregate( b ) ) { + t = TYPEget_base_type( a ); + u = TYPEget_base_type( b ); + if( !( ( TYPEis_select( t ) && TYPEis_select( u ) ) + || ( TYPEis_enumeration( t ) && TYPEis_enumeration( u ) ) ) ) { + return FALSE; + /* Only go further with 1D aggregates of sels or enums. Note that + // for 2D aggrs and higher we do not continue. These are all recog- + // nized to be the same type ("GenericAggregate") by TYPEget_ctype(), + // and do not have to be handled specially here. */ + } + } else { + return FALSE; + } + + if( TYPEget_head( t ) ) { + t = TYPEget_ancestor( t ); + } + if( TYPEget_head( u ) ) { + u = TYPEget_ancestor( u ); + } + return ( !strcmp( TYPEget_name( t ), TYPEget_name( u ) ) ); +} + +/******************* + utype_member + + determines if the given "link's" underlying type is a member of the list. + RETURNS the underlying type if it is a member; otherwise 0 is returned. + + If "rename" is TRUE, we also consider check to match in certain cases where + list already has an item that check is a renaming of (see header comments to + compareOrigTypes() above). + *******************/ +const char * +utype_member( const Linked_List list, const Type check, int rename ) { + static char r [BUFSIZ]; + + LISTdo( list, t, Type ) + strncpy( r, TYPEget_utype( t ), BUFSIZ ); + if( strcmp( r, TYPEget_utype( check ) ) == 0 ) { + return r; + } + if( rename && compareOrigTypes( check, t ) ) { + return r; + } + LISTod; + return 0; +} + +/** +*** SELgetnew_dmlist (const Type type) +*** Returns a list of types which have unique underlying types +*** The returned list includes all the types which have a data members +*** in the select type. +*** +*** The list that is returned needs to be freed by the caller. +***/ + + +Linked_List +SELgetnew_dmlist( const Type type ) { + Linked_List complete = SEL_TYPEget_items( type ); + Linked_List newlist = LISTcreate(); + + LISTdo( complete, t, Type ) + + /* if t\'s underlying type is not already in newlist, */ + if( ! utype_member( newlist, t, 0 ) ) { + LISTadd_last( newlist, t ); + } + + LISTod; + + return newlist; + +} + +const char * +SEL_ITEMget_dmtype( Type t, const Linked_List l ) { + const char * r = utype_member( l, t, 0 ); + return StrToLower( r ? r : TYPEget_utype( t ) ); + +} + + +/** +*** SEL_ITEMget_dmname (Type t) +*** Returns the name of the data member in the select class for the item of +*** the select having the type t. +*** Logical and boolean are handled as exceptions because TYPEget_utype() +*** returns "PSDAI::..." for them which is not a legal variable name. +***/ + +const char * +SEL_ITEMget_dmname( Type t ) { + Class_Of_Type class = TYPEget_type( t ); + + if( class == Class_Integer_Type ) { + return "integer"; + } + if( class == Class_Real_Type ) { + return "real"; + } + if( class == Class_Number_Type ) { + return "real"; + } + if( class == Class_String_Type ) { + return "string"; + } + if( class == Class_Binary_Type ) { + return "binary"; + } + if( class == Class_Logical_Type ) { + return "logical"; + } + if( class == Class_Boolean_Type ) { + return "boolean"; + } + if( class == Class_Entity_Type ) { + return "app_inst"; + } + return ( StrToLower( TYPEget_utype( t ) ) ); +} + +/******************* +duplicate_in_express_list + +determines if the given "link's" underlying type is a multiple member +of the list. + RETURNS 1 if true, else 0. +*******************/ +int +duplicate_in_express_list( const Linked_List list, const Type check ) { + if( TYPEis_entity( check ) ) { + return FALSE; + } + /* entities are never the same */ + + LISTdo( list, t, Type ) + if( t == check ) { + ; /* don\'t compare check to itself */ + } else { + return TRUE; /* other things in the list conflict */ + } + LISTod; + return FALSE; +} + +/******************* +unique_types ( const Linked_List list ) + +determines if any of the types in a select type resolve to the same +underlying Express type. +RETURNS 1 if true, else 0. +*******************/ +int +unique_types( const Linked_List list ) { + LISTdo( list, t, Type ) + if( duplicate_in_express_list( list, t ) ) { + return FALSE; + } + LISTod; + return TRUE; +} + + +/******************* +duplicate_utype_member + +determines if the given "link's" C++ representation is used again in the list. + RETURNS 1 if true, else 0. +*******************/ +int +duplicate_utype_member( const Linked_List list, const Type check ) { + char b [BUFSIZ]; + + if( TYPEis_entity( check ) ) { + return FALSE; + } + /* entities are never the same */ + + LISTdo( list, t, Type ) + if( t == check ) { + ; + } + /* don\'t compare check to itself */ + else { /* continue looking */ + strncpy( b, TYPEget_utype( t ), BUFSIZ ); + if( ( !strcmp( b, TYPEget_utype( check ) ) ) + || ( compareOrigTypes( t, check ) ) ) + /* if the underlying types are the same */ + { + return TRUE; + } + if( ! strcmp( b, "SCLP23(Integer)" ) && + ( ! strcmp( TYPEget_utype( check ), "SCLP23(Real)" ) ) ) + /* integer\'s and real\'s are not unique */ + { + return TRUE; + } + } + LISTod; + return FALSE; +} + +/******************* +any_duplicates_in_select + +determines if any of the types in a select type resolve to the same +C++ representation for the underlying Express type. +RETURNS 1 if true, else 0. +*******************/ +int +any_duplicates_in_select( const Linked_List list ) { + LISTdo( list, t, Type ) + if( duplicate_utype_member( list, t ) ) { + return TRUE; + } + LISTod; + return FALSE; +} + +/******************* +find_duplicate_list + +finds an instance of each kind of duplicate type found in the given list. +This list is returned as dup_list. If a duplicate exists, the function +returns TRUE, else FALSE. +list should be unbound before calling, and freed afterwards. +*******************/ +int +find_duplicate_list( const Type type, Linked_List * duplicate_list ) { + Linked_List temp; /** temporary list for comparison **/ + + *duplicate_list = LISTcreate(); + if( any_duplicates_in_select( SEL_TYPEget_items( type ) ) ) { + /** if there is a dup somewhere **/ + temp = LISTcreate(); + LISTdo( SEL_TYPEget_items( type ), u, Type ) + if( !utype_member( *duplicate_list, u, 1 ) ) { + /** if not already a duplicate **/ + if( utype_member( temp, u, 1 ) ) { + LISTadd_first( *duplicate_list, u ); + } else { + LISTadd_first( temp, u ); + } + } + LISTod; + LISTfree( temp ); + return TRUE; + } + return FALSE; +} + +/******************* +non_unique_types_string ( const Type type ) + +returns a string containing the non-unique EXPRESS types deriveable +from a select. the returned string is in the form (TYPE | TYPE |...) +*******************/ +/* In the functions below, we use a vector of ints to count paths in the + select-graph to base types. The names in this enum correspond to the + indices in the vector, i.e., tvec[treal] == tvec[1], and contains the + number of paths to REAL in the graph +*/ + +enum __types { + tint = 0, /* INTEGER */ + treal, /* REAL */ + tstring, /* STRING */ + tbinary, /* BINARY */ + tenum, /* ENUMERATION, also LOGICAL, BOOLEAN */ + tselect, /* SELECT */ + tentity, /* ENTITY */ + taggr, /* AGGREGATE, also ARRAY, BAG, SET, LIST */ + tnumber /* NUMBER */ +}; + +/* This function gets called recursively, to follow a select-graph to its + leaves. It passes around the vector described above, to track paths to + the leaf nodes. +*/ +void +non_unique_types_vector( const Type type, int * tvec ) { + LISTdo( SEL_TYPEget_items( type ), t, Type ) + switch( TYPEget_body( t )->type ) { + case integer_: + tvec[tint]++; + break; + case real_: + tvec[treal]++; + break; + case string_: + tvec[tstring]++; + break; + case binary_: + tvec[tbinary]++; + break; + case enumeration_: + case logical_: + case boolean_: + tvec[tenum]++; + break; + case select_: + /* SELECT, ergo recurse! */ + non_unique_types_vector( t, tvec ); + break; + case entity_: + tvec[tentity]++; + break; + case aggregate_: + case array_: + case list_: + case bag_: + case set_: + tvec[taggr]++; + break; + case number_: + tvec[tnumber]++; + break; + default: + printf( "Error in %s, line %d: type %d not handled by switch statement.", __FILE__, __LINE__, TYPEget_body( t )->type ); + abort(); + } + LISTod; +} + +/* Uses non_unique_types_vector on the select to get a vector of base-type + reference counts, then uses that to make a string of types, of the form + (FOO_TYPE | BAR_TYPE | BAZ_TYPE), where FOO, BAR, and BAZ are EXPRESS + types. If all types are unique, the string (0) is generated. +*/ +char * +non_unique_types_string( const Type type ) { + int tvec[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + char * typestr; + int first = 1; + int i; + + non_unique_types_vector( type, tvec ); + + /* build type string from vector */ + typestr = ( char * )malloc( BUFSIZ ); + typestr[0] = '\0'; + strcat( typestr, ( char * )"(" ); + for( i = 0; i <= tnumber; i++ ) { + if( tvec[i] < 2 ) { + continue; /* skip, this one is unique */ + } + + if( !first ) { + strcat( typestr, ( char * )" | " ); + } else { + first = 0; + } + switch( i ) { + case tint : + strcat( typestr, ( char * )"sdaiINTEGER" ); + break; + case treal : + strcat( typestr, ( char * )"sdaiREAL" ); + break; + case tstring: + strcat( typestr, ( char * )"sdaiSTRING" ); + break; + case tbinary: + strcat( typestr, ( char * )"sdaiBINARY" ); + break; + case tenum : + strcat( typestr, ( char * )"sdaiENUMERATION" ); + break; + case tentity: + strcat( typestr, ( char * )"sdaiINSTANCE" ); + break; + case taggr : + strcat( typestr, ( char * )"sdaiAGGR" ); + break; + case tnumber: + strcat( typestr, ( char * )"sdaiNUMBER" ); + break; + } + } + if( first ) { + strcat( typestr, ( char * )"0" ); + } + strcat( typestr, ( char * )")" ); + return typestr; +} + + + +/****************************************************************** + ** Procedure: ATTR_LISTmember + ** Parameters: Linked_List l, Variable check + ** Returns: the attribute if an attribute with the same name as "check" + ** is on the list, 0 otherwise + ** Description: checks to see if an attribute is a member of the list + ** Side Effects: + ** Status: 26-Oct-1993 done + ******************************************************************/ + +Variable +ATTR_LISTmember( Linked_List l, Variable check ) { + char nm [BUFSIZ]; + char cur [BUFSIZ]; + + generate_attribute_name( check, nm ); + LISTdo( l, a, Variable ) + generate_attribute_name( a, cur ); + if( ! strcmp( nm, cur ) ) { + return check; + } + LISTod; + return ( 0 ); +} + + +/****************************************************************** + ** Procedure: SEL_TYPEgetnew_attribute_list + ** Parameters: const Type type + ** Returns: Returns a list of all the attributes for a select type. + ** The list is the union of all the attributes of the underlying types. + ** Description: + ** Side Effects: +*** The list that is returned needs to be freed by the caller. + ** Status: + ******************************************************************/ + +Linked_List +SEL_TYPEgetnew_attribute_list( const Type type ) { + Linked_List complete = SEL_TYPEget_items( type ); + Linked_List newlist = LISTcreate(); + Linked_List attrs; + Entity cur; + + LISTdo( complete, t, Type ) + if( TYPEis_entity( t ) ) { + cur = ENT_TYPEget_entity( t ); + attrs = ENTITYget_all_attributes( cur ); + LISTdo( attrs, a, Variable ) + if( ! ATTR_LISTmember( newlist, a ) ) { + LISTadd_first( newlist, a ); + } + LISTod; + } + LISTod; + return newlist; +} + +/******************* +TYPEselect_inc_print_vars prints the class 'definition', that is, the objects + and the constructor(s)/destructor for a select class. +********************/ +void +TYPEselect_inc_print_vars( const Type type, FILE * f, Linked_List dups ) { + int size, j; + Linked_List data_members = SELgetnew_dmlist( type ); + char dmname [BUFSIZ], + classnm [BUFSIZ], + tdnm [BUFSIZ]; + + strncpy( classnm, SelectName( TYPEget_name( type ) ), BUFSIZ ); + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + size = strlen( classnm ) + 2; /* for formatting output */ + + fprintf( f, "\n////////// SELECT TYPE %s\n", + SelectName( TYPEget_name( type ) ) ); + /* fprintf( f, "class %s;\n"*/ + /* "typedef %s * %sH;\n\n",*/ + /* classnm, classnm, classnm);*/ + fprintf( f, "class %s : public " BASE_SELECT " {\n", classnm ); + fprintf( f, " protected:\n" ); + /* fprintf( f, " \tunion { \n" ); */ + fprintf( f, "/* \tunion { */\n" ); + fprintf( f, "\t// types in SELECT \n" ); + LISTdo( SEL_TYPEget_items( type ), t, Type ) + fprintf( f, "\t// %s\t-- %s\n", + SEL_ITEMget_enumtype( t ), FundamentalType( t, 0 ) ); + LISTod; + + LISTdo( data_members, t, Type ) + strncpy( dmname, SEL_ITEMget_dmname( t ), BUFSIZ ); + fprintf( f, "\t %s _%s;\n", TYPEget_utype( t ), dmname ); + LISTod; + + /* fprintf( f, " \t} ;" );*/ + fprintf( f, "/* \t} ; */" ); + fprintf( f, " /* unnamed union of select items */\n" ); + + fprintf( f, "\n public:\n" ); + fprintf( f, + "\tvirtual const TypeDescriptor * AssignEntity (SCLP23(Application_instance) * se);\n" + "\tvirtual SCLP23(Select) * NewSelect ();\n" + ); + + fprintf( f, "\n\tvirtual BASE_TYPE ValueType() const;\n" ); + + fprintf( f, "\n\n// STEP Part 21\n" ); + fprintf( f, "\tvirtual void STEPwrite_content (ostream& out =std::cout,\n" + "\t\t\t\t\tconst char *currSch =0) const;\n" ); + fprintf( f, "\tvirtual void STEPwrite_verbose (ostream& out =std::cout,\n" + "\t\t\t\t\tconst char *currSch =0) const;\n" ); + fprintf( f, "\tvirtual Severity STEPread_content (istream& in =cin,\n" + "\t\tInstMgr * instances =0, const char *utype =0,\n" + "\t\tint addFileId =0, const char *currSch =0);\n" ); + + /* read StrToVal_content */ + fprintf( f, "\tvirtual Severity StrToVal_content " + "(const char *,\n\t\tInstMgr * instances =0);\n" ); + + /* constructor(s) */ + fprintf( f, "\n// STEP Part 22: SDAI\n" ); + fprintf( f, "\n// constructors\n" ); + fprintf( f, "\t%s( const SelectTypeDescriptor * =%s );\n", + classnm, tdnm ); + + fprintf( f, "\t// part 1\n" ); + + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if( ( TYPEis_entity( t ) ) + || ( !utype_member( dups, t, 1 ) ) ) { + /** if an entity or not in the dup list **/ + fprintf( f, "\t%s( const %s&,\n\t", + SelectName( TYPEget_name( type ) ), AccessType( t ) ); + for( j = 0; j < size; j++ ) { + fprintf( f, " " ); + } + fprintf( f, "const SelectTypeDescriptor * =%s );\n", tdnm ); + } + LISTod; + LISTdo( dups, t, Type ) + if( ! TYPEis_entity( t ) ) { /* entities were done already */ + fprintf( f, "\t%s( const %s&,\n\t", + SelectName( TYPEget_name( type ) ), + isAggregateType( t ) ? AccessType( t ) : TYPEget_utype( t ) ); + for( j = 0; j < size; j++ ) { + fprintf( f, " " ); + } + fprintf( f, "const SelectTypeDescriptor * =%s );\n", tdnm ); + } + LISTod; + + /* destructor */ + fprintf( f, "\tvirtual ~%s();\n", classnm ); + LISTfree( data_members ); +} + +/******************* +TYPEselect_inc_print prints the class member function declarations of a select +class. +*******************/ +void +TYPEselect_inc_print( const Type type, FILE * f ) { + char n[BUFSIZ]; /* class name */ + char tdnm [BUFSIZ]; /* TypeDescriptor name */ + Linked_List dups; + int dup_result; + Linked_List attrs; + + dup_result = find_duplicate_list( type, &dups ); + strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ ); + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + TYPEselect_inc_print_vars( type, f, dups ); + + fprintf( f, "\n\t// part 2\n" ); + + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if( ( TYPEis_entity( t ) ) + || ( !utype_member( dups, t, 1 ) ) ) { + /** if an entity or not in the dup list **/ + fprintf( f, "\toperator %s();\n", AccessType( t ) ); + } + LISTod; + LISTdo( dups, t, Type ) + /* do the dups once only */ + if( ! TYPEis_entity( t ) ) /* entities were done already */ + fprintf( f, "\toperator %s ();\n", + ( TYPEis_aggregate( t ) || TYPEis_select( t ) ) ? + AccessType( t ) : TYPEget_utype( t ) ); + LISTod; + + fprintf( f, "\n\t// part 3\n" ); + attrs = SEL_TYPEgetnew_attribute_list( type ); + /* get the list of unique attributes from the entity items */ + LISTdo( attrs, a, Variable ) + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + ATTRsign_access_methods( a, f ); + } + LISTod; + LISTfree( attrs ); + + fprintf( f, "\n\t// part 4\n" ); + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if( ( TYPEis_entity( t ) ) + || ( !utype_member( dups, t, 1 ) ) ) { + /** if an entity or not in the dup list **/ + fprintf( f, "\t%s& operator =( const %s& );\n", + SelectName( TYPEget_name( type ) ), AccessType( t ) ); + } + LISTod; + LISTdo( dups, t, Type ) + if( ! TYPEis_entity( t ) ) { /* entities were done already */ + fprintf( f, "\t%s& operator =( const %s& );\n", + SelectName( TYPEget_name( type ) ), + isAggregateType( t ) ? AccessType( t ) : TYPEget_utype( t ) ); + } + LISTod; + + fprintf( f, "\t// not in SDAI\n" + "\t%s& ShallowCopy ( const %s& );\n", + n, n ); + + fprintf( f, "\n#ifdef COMPILER_DEFINES_OPERATOR_EQ\n#else\n" ); + fprintf( f, "\t%s& operator =( %s * const & );\n", n, n ); + fprintf( f, "\tSCLP23(Select)& operator =( const SCLP23(Select)& );\n" ); + /* fprintf( f, "\t%s& operator =( const %s& );\n", n, n );*/ + fprintf( f, "#endif\n" ); + + fprintf( f, "\n\t// part 5\n" ); + LISTdo( SEL_TYPEget_items( type ), t, Type ) + fprintf( f, "\tLogical Is%s() const;\n", + FirstToUpper( TYPEget_name( t ) ) ); + LISTod; + + fprintf( f, "\n\t// part 6 ... UnderlyingTypeName () implemented in" + " SCLP23(Select) class ...\n" ); + /* fprintf( f, "\tSCLP23(String) UnderlyingTypeName() const;\n" );*/ + /* fprintf( f, "\tconst EntityDescriptor * CurrentUnderlyingType();\n" );*/ + + if( dup_result ) { + /** if there are duplicate underlying types **/ + fprintf( f, "\n\t// part 7\n" ); + fprintf( f, "\tconst TypeDescriptor *" + "SetUnderlyingType ( const TypeDescriptor * td );\n"); + } else { + fprintf( f, "\n\t// part 7 ... NONE\tonly for complex selects...\n" ); + } + +#ifdef PART8 + fprintf( f, "\n\t// part 8\n" ); + fprintf( f, "\t%s* operator->();\n", n ); +#endif + + fprintf( f, "};\n" ); + + fprintf( f, "\ninline SCLP23(Select) * create_%s () { return new %s; }\n", n, n ); + + /* DAR - moved from SCOPEPrint() */ + fprintf( f, "typedef %s * %sH;\n", n, n ); + fprintf( f, "typedef %s_ptr %s_var;\n\n", n, n ); + + /* print things for aggregate class */ + fprintf( f, "\nclass %ss : public SelectAggregate {\n", n ); + fprintf( f, " protected:\n" ); + fprintf( f, " SelectTypeDescriptor *sel_type;\n\n" ); + fprintf( f, " public:\n" ); + fprintf( f, " %ss( SelectTypeDescriptor * =%s );\n", n, tdnm ); + fprintf( f, " ~%ss();\n", n ); + fprintf( f, " virtual SingleLinkNode * NewNode()\n" ); + fprintf( f, "\t { return new SelectNode (new %s( sel_type )); }\n", n ); + fprintf( f, "};\n" ); + + /* DAS creation function for select aggregate class */ + fprintf( f, "inline STEPaggregate * create_%ss () { return new %ss; }\n", + n, n ); + + fprintf( f, "typedef %ss_ptr %ss_var;\n", n, n ); + + fprintf( f, "\n///// END SELECT TYPE %s\n\n", TYPEget_name( type ) ); + + LISTfree( dups ); +} + + +/******************* +TYPEselect_lib_print_part_one prints constructor(s)/destructor of a select +class. +*******************/ +void +TYPEselect_lib_print_part_one( const Type type, FILE * f, Schema schema, + Linked_List dups, char * n ) { +#define schema_name SCHEMAget_name(schema) + char tdnm[BUFSIZ], + nm[BUFSIZ]; + int size = strlen( n ) * 2 + 4, j; /* size - for formatting output */ + + strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); + strncpy( nm, SelectName( TYPEget_name( type ) ), BUFSIZ ); + + /* constructor(s) */ + /* null constructor */ + fprintf( f, "\n// STEP Part 22: SDAI\n" ); + fprintf( f, "\n\t// part 0\n" ); + fprintf( f, "%s::%s( const SelectTypeDescriptor *typedescript )\n", n, n ); + fprintf( f, " : " BASE_SELECT " (typedescript)" ); + /* Initialize the select members with their correct typedescriptors: */ + initSelItems( type, f ); + fprintf( f, "\n{\n" ); + fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); + fprintf( f, "\t*logStream << \"DAVE ERR entering %s constructor.\" << std::endl;\n", n ); + fprintf( f, " }\n#endif\n" ); + /* fprintf( f, "#ifdef WE_WANT_TO_HAVE_THIS_CONSTRUCTOR\n" );*/ + fprintf( f, " nullify();\n" ); + /* fprintf( f, "#endif\n" );*/ + fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); + fprintf( f, "//\t*logStream << \"DAVE ERR exiting %s constructor.\" << std::endl;\n", n ); + fprintf( f, " }\n#endif\n" ); + fprintf( f, "}\n" ); + + /* constructors with underlying types */ + fprintf( f, "\n\t// part 1\n" ); + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if( ( TYPEis_entity( t ) ) + || ( !utype_member( dups, t, 1 ) ) ) { + /* if there is not more than one underlying type that maps to the same + * base type print out the constructor using the type from the TYPE + * statement as the underlying type. Also skip enums/sels which are + * renames of other items. That would create redundant constructors + * since renames are typedef'ed to the original type. + */ + fprintf( f, "%s::%s( const %s& o,\n", n, n, AccessType( t ) ); + for( j = 0; j < size; j++ ) { + fprintf( f, " " ); + } + /* Did this for the heck of it, and to show how easy it would have + been to make it all pretty - DAR. ;-) */ + fprintf( f, "const SelectTypeDescriptor *typedescript )\n" ); + + fprintf( f, " : " BASE_SELECT " (typedescript, %s)", + TYPEtd_name( t ) ); + initSelItems( type, f ); + fprintf( f, "\n{\n" ); + fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); + fprintf( f, + "\t*logStream << \"DAVE ERR entering %s constructor.\"" + " << std::endl;\n", n ); + fprintf( f, " }\n#endif\n" ); + + if( isAggregateType( t ) ) { + fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); + } else { + fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); + } + fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); + fprintf( f, + "//\t*logStream << \"DAVE ERR exiting %s constructor.\"" + " << std::endl;\n", n ); + fprintf( f, " }\n#endif\n" ); + + fprintf( f, "}\n\n" ); + } + LISTod; + LISTdo( dups, t, Type ) + /* if there is more than one underlying type that maps to the + * same base type, print a constructor using the base type. + */ + if( ! TYPEis_entity( t ) ) { /* entities were done already */ + if( isAggregateType( t ) ) { + fprintf( f, "%s::%s( const %s& o,\n", n, n, AccessType( t ) ); + for( j = 0; j < size; j++ ) { + fprintf( f, " " ); + } + fprintf( f, "const SelectTypeDescriptor *typedescript )\n" ); + fprintf( f, " : " BASE_SELECT " ( typedescript, %s )", + TYPEtd_name( t ) ); + initSelItems( type, f ); + fprintf( f, "\n{\n" ); + fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); + fprintf( f, + "\t*logStream << \"DAVE ERR entering %s constructor.\"" + " << std::endl;\n", n ); + fprintf( f, " }\n#endif\n" ); + fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); + } else { + fprintf( f, "%s::%s( const %s& o,\n", n, n, TYPEget_utype( t ) ); + for( j = 0; j < size; j++ ) { + fprintf( f, " " ); + } + fprintf( f, "const SelectTypeDescriptor *typedescript )\n" ); + fprintf( f, " : " BASE_SELECT " ( typedescript, %s )", + TYPEtd_name( t ) ); + initSelItems( type, f ); + fprintf( f, "\n{\n" ); + fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); + } + fprintf( f, + "// NOTE: Underlying type defaults to %s instead of NULL\n", + TYPEtd_name( t ) ); + fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); + fprintf( f, + "//\t*logStream << \"DAVE ERR exiting %s constructor.\"" + " << std::endl;\n", n ); + fprintf( f, " }\n#endif\n" ); + fprintf( f, "}\n\n" ); + } + LISTod; + + fprintf( f, "%s::~%s()\n{\n", n, n ); + fprintf( f, "}\n\n" ); + + fprintf( f, "%ss::%ss( SelectTypeDescriptor *s)\n" + " : SelectAggregate(), sel_type(s)\n{\n}\n\n", n, n ); + fprintf( f, "%ss::~%ss() { }\n\n", n, n ); +#undef schema_name +} + +static void +initSelItems( const Type type, FILE * f ) +/* + * Creates initialization functions for the select items of a select. The + * selects must have their typedescriptors set properly. If a select is a + * renaming of another select ("TYPE selB = selA") its td would default to + * selA's, so it must be set specifically. + */ +{ + Linked_List data_members = SELgetnew_dmlist( type ); + + LISTdo( data_members, t, Type ) + if( TYPEis_select( t ) ) { + fprintf( f, ",\n _%s (%s)", SEL_ITEMget_dmname( t ), + TYPEtd_name( t ) ); + } + LISTod; +} + +Linked_List +ENTITYget_expanded_entities( Entity e, Linked_List l ) { + Linked_List supers; + int super_cnt = 0; + Entity super; + + if( ! LISTmember( l, e ) ) { + LISTadd_first( l, e ); + } + + if( multiple_inheritance ) { + supers = ENTITYget_supertypes( e ); + LISTdo( supers, s, Entity ) + /* ignore the more than one supertype + since multiple inheritance isn\'t implemented */ + if( super_cnt == 0 ) { + ENTITYget_expanded_entities( s, l ); + } + ++ super_cnt; + LISTod; + } else { + /* ignore the more than one supertype + since multiple inheritance isn\'t implemented */ + super = ENTITYget_superclass( e ); + ENTITYget_expanded_entities( super, l ); + } + return l; +} + +Linked_List +SELget_entity_itemlist( const Type type ) { + Linked_List complete = SEL_TYPEget_items( type ); + Linked_List newlist = LISTcreate(); + Entity cur; + + LISTdo( complete, t, Type ) + if( TYPEis_entity( t ) ) { + cur = ENT_TYPEget_entity( t ); + ENTITYget_expanded_entities( cur, newlist ); + } + LISTod; + return newlist; + +} + +static int +memberOfEntPrimary( Entity ent, Variable uattr ) +/* + * Specialized function used in function TYPEselect_lib_print_part_three + * below. Calls a function to check if an attribute of an entity belongs + * to its primary path (is its own attr, that of its first super, that of + * its first super's first super etc), and does necessary housekeeping. + */ +{ + Linked_List attrlist = LISTcreate(); + int result; + + ENTITYget_first_attribs( ent, attrlist ); + result = ( LISTmember( attrlist, uattr ) != 0 ); + LIST_destroy( attrlist ); + return result; +} + +/******************* +TYPEselect_lib_print_part_three prints part 3) of the SDAI C++ binding for +a select class -- access functions for the data members of underlying entity +types. +*******************/ +void +TYPEselect_lib_print_part_three( const Type type, FILE * f, Schema schema, + char * classnm ) { +#define ENTITYget_type(e) ((e)->u.entity->type) + + char uent[BUFSIZ], /* name of underlying entity type */ + utype[BUFSIZ], /* underlying type name */ + attrnm [BUFSIZ], /* attribute name -> data member = _attrnm */ + funcnm[BUFSIZ]; /* access function name = Attrnm */ + Linked_List items = SEL_TYPEget_items( type ); + /* all the items in the select type */ + Linked_List attrs = SEL_TYPEgetnew_attribute_list( type ); + /* list of attributes with unique names */ + Entity ent; + Variable uattr; /* attribute in underlying type */ + + fprintf( f, "\n\t// part 3\n" ); + + LISTdo( attrs, a, Variable ) + /* go through all the unique attributes */ + if( VARget_initializer( a ) == EXPRESSION_NULL ) { + /* only do for explicit attributes */ + generate_attribute_func_name( a, funcnm ); + generate_attribute_name( a, attrnm ); + /* + strncpy (funcnm, attrnm, BUFSIZ); + funcnm [0] = toupper (funcnm[0]); + */ + /* use the ctype since utype will be the same for all entities */ + strncpy( utype, TYPEget_ctype( VARget_type( a ) ), BUFSIZ ); + + /* get method */ + ATTRprint_access_methods_get_head( classnm, a, f ); + fprintf( f, "{\n" ); + + LISTdo( items, t, Type ) + if( TYPEis_entity( t ) && + ( uattr = ENTITYget_named_attribute + ( ( ent = ENT_TYPEget_entity( t ) ), + ( char * ) StrToLower( attrnm ) ) ) ) + + { + /* for the select items which have the current attribute */ + + /* if ( !multiple_inheritance ) { */ + if( !memberOfEntPrimary( ent, uattr ) ) { + /* If multiple inheritance is not supported, we must addi- + tionally check that uattr is a member of the entity's + primary inheritance path (i.e., the entity, its first + supertype, the super's first super, etc). The above + `if' is commented out, because currently mult inher is + not supported to the extent of handling accessor func- + tions for non-primary supertypes. */ + continue; + } + /* } */ + + if( ! VARis_derived( uattr ) ) { + + if( !strcmp( utype, TYPEget_ctype( VARget_type( uattr ) ) ) ) { + /* check to make sure the underlying attribute\'s type is + the same as the current attribute. + */ + + strncpy( uent, TYPEget_ctype( t ), BUFSIZ ); + + /* if the underlying type is that item\'s type + call the underlying_item\'s member function */ + fprintf( f, + " if( CurrentUnderlyingType () == %s ) \n\t// %s\n", + TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) ) ); + fprintf( f, "\treturn ((%s) _%s) ->%s();\n", + uent, SEL_ITEMget_dmname( t ), funcnm ); + + } else { + /* types are not the same issue a warning */ + fprintf( stderr, + "WARNING: in SELECT TYPE %s: \n\tambiguous " + "attribute \"%s\" from underlying type \"%s\".\n\n", + TYPEget_name( type ), attrnm, TYPEget_name( t ) ); + fprintf( f, " // %s\n\t// attribute access function" + " has a different return type\n", + StrToUpper( TYPEget_name( t ) ) ); + } + + } else /* derived attributes */ + fprintf( f, " // for %s attribute is derived\n", + StrToUpper( TYPEget_name( t ) ) ); + } + LISTod; + PRINT_BUG_REPORT + + /* If the return type is an enumeration class then you can\'t + return NULL. Instead I made the return type the + enumeration value. This causes a WARNING about going from + int (NULL) to the enumeration type. To get rid of the + WARNING you could add an explicit cast (using the code + commented out below. + + Another option is to have the return type be the + enumeration class and create special "NULL" instances of + the class for every enumeration. This option was not + implemented. + + kcm 28-Mar-1995 + */ + + + + /* EnumName (TYPEget_name (VARget_type (a)))*/ + switch( TYPEget_body( VARget_type( a ) ) -> type ) { + case enumeration_: + fprintf( f, " return (%s) 0;\n}\n\n", + EnumName( TYPEget_name( VARget_type( a ) ) ) ); + break; + + case boolean_: + fprintf( f, " return (Boolean) 0;\n}\n\n" ); + break; + + case logical_: + fprintf( f, " return (Logical) 0;\n}\n\n" ); + break; + + default: + fprintf( f, " return 0;\n}\n\n" ); + } + + /* put method */ + ATTRprint_access_methods_put_head( classnm, a, f ); + fprintf( f, "{\n" ); + LISTdo( items, t, Type ) + if( TYPEis_entity( t ) && + ( uattr = ENTITYget_named_attribute( + ( ent = ENT_TYPEget_entity( t ) ), + ( char * ) StrToLower( attrnm ) ) ) ) + + { + /* for the select items which have the current attribute */ + + /* if ( !multiple_inheritance ) { */ + if( !memberOfEntPrimary( ent, uattr ) ) { + /* See note for similar code segment in 1st part of fn. */ + continue; + } + /* } */ + + if( ! VARis_derived( uattr ) ) { + + if( !strcmp( utype, TYPEget_ctype( VARget_type( uattr ) ) ) ) { + /* check to make sure the underlying attribute\'s type is + the same as the current attribute. + */ + + /* if the underlying type is that item\'s type + call the underlying_item\'s member function */ + strncpy( uent, TYPEget_ctype( t ), BUFSIZ ); + fprintf( f, + " if( CurrentUnderlyingType () == %s ) \n\t// %s\n", + TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) ) ); + fprintf( f, "\t{ ((%s) _%s) ->%s( x );\n\t return;\n\t}\n", + uent, SEL_ITEMget_dmname( t ), funcnm ); + } else /* warning printed above */ + fprintf( f, " // for %s attribute access function" + " has a different argument type\n", + SEL_ITEMget_enumtype( t ) ); + } else /* derived attributes */ + fprintf( f, " // for %s attribute is derived\n", + SEL_ITEMget_enumtype( t ) ); + } + LISTod; + PRINT_SELECTBUG_WARNING( f ); + fprintf( f, "}\n" ); + } + LISTod; + LISTfree( attrs ); +} + +/******************* +TYPEselect_lib_print_part_four prints part 4 of the SDAI document of a select +class. +*******************/ +void +TYPEselect_lib_print_part_four( const Type type, FILE * f, Schema schema, + Linked_List dups, char * n ) { + char x[BUFSIZ]; + int firsttime = 1; + + fprintf( f, "\n\t// part 4\n" ); + + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if( ( TYPEis_entity( t ) ) + || ( !utype_member( dups, t, 1 ) ) ) { + fprintf( f, "%s& %s::operator =( const %s& o )\n{\n" + " nullify ();\n", + n, n, AccessType( t ) ); + + if( isAggregateType( t ) ) { + fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); + } else { + fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); + } + + fprintf( f, " SetUnderlyingType (%s);\n", TYPEtd_name( t ) ); + fprintf( f, " return *this;\n}\n\n" ); + } + LISTod; + LISTdo( dups, t, Type ) + if( ! TYPEis_entity( t ) ) { /* entities were done already */ + if( isAggregateType( t ) ) { + fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", + n, n, AccessType( t ) ); + fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); + } else { + fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", + n, n, TYPEget_utype( t ) ); + fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); + } + + fprintf( f, " underlying_type = 0; // MUST BE SET BY USER\n" ); + fprintf( f, " // discriminator = UNSET\n" ); + fprintf( f, " return *this;\n}\n" ); + } + LISTod; + + fprintf( f, "\n#ifdef COMPILER_DEFINES_OPERATOR_EQ\n#else\n\n" ); + fprintf( f, "%s& %s::operator =( const %s_ptr& o )\n{\n", n, n, n ); + + LISTdo( SEL_TYPEget_items( type ), t, Type ) + strncpy( x, TYPEget_name( t ), BUFSIZ ); + if( firsttime ) { + fprintf( f, " " ); + firsttime = 0; + } else { + fprintf( f, " else " ); + } + fprintf( f, "if ( o -> CurrentUnderlyingType () == %s )\n", + TYPEtd_name( t ) ); + if( TYPEis_select( t ) ) { + if( utype_member( dups, t, 1 ) ) + /** if in the dup list **/ + fprintf( f, " _%s = &(o -> _%s);\n", + SEL_ITEMget_dmname( t ), + StrToLower( TYPEget_utype( t ) ) ); + else + fprintf( f, "\t_%s = &(o -> _%s);\n", + SEL_ITEMget_dmname( t ), + SEL_ITEMget_dmname( t ) ); + } else { + if( utype_member( dups, t, 1 ) ) + /** if in the dup list **/ + fprintf( f, " _%s = o -> _%s;\n", + SEL_ITEMget_dmname( t ), + SEL_ITEMget_dmname( t ) ); + /* I changed this although I'm not sure how the if and else differ */ + /* StrToLower(TYPEget_utype(t)) ); */ + else + fprintf( f, "\t_%s = o -> _%s;\n", + SEL_ITEMget_dmname( t ), + SEL_ITEMget_dmname( t ) ); + } + LISTod; + fprintf( f, " underlying_type = o -> CurrentUnderlyingType ();\n" ); + fprintf( f, " return *this;\n}\n\n" ); + + /* fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", n,n,n );*/ + fprintf( f, "SCLP23(Select)& %s::operator =( const SCLP23(Select)& o )\n{\n", n ); + + firsttime = 1; + LISTdo( SEL_TYPEget_items( type ), t, Type ) + strncpy( x, TYPEget_name( t ), BUFSIZ ); + if( firsttime ) { + fprintf( f, " " ); + firsttime = 0; + } else { + fprintf( f, " else " ); + } + fprintf( f, "if ( o.CurrentUnderlyingType () == %s )\n", + TYPEtd_name( t ) ); + if( TYPEis_select( t ) ) { + if( utype_member( dups, t, 1 ) ) + /** if in the dup list **/ + /* fprintf( f, " _%s = o._%s;\n", */ + fprintf( f, "\t_%s = ((%s&) o)._%s;\n", + SEL_ITEMget_dmname( t ), + n, + SEL_ITEMget_dmname( t ) ); + /* StrToLower(TYPEget_utype(t)) ); */ + else + /* fprintf( f, "\t_%s = o._%s;\n", */ + fprintf( f, "\t_%s = &(((%s&) o)._%s);\n", + SEL_ITEMget_dmname( t ), + n, + SEL_ITEMget_dmname( t ) ); + } else { + if( utype_member( dups, t, 1 ) ) + /** if in the dup list **/ + /* fprintf( f, " _%s = o._%s;\n", */ + fprintf( f, "\t_%s = ((%s&) o)._%s;\n", + SEL_ITEMget_dmname( t ), + n, + SEL_ITEMget_dmname( t ) ); + /* StrToLower(TYPEget_utype(t)) ); */ + else + /* fprintf( f, "\t_%s = o._%s;\n", */ + fprintf( f, "\t_%s = ((%s&) o)._%s;\n", + SEL_ITEMget_dmname( t ), + n, + SEL_ITEMget_dmname( t ) ); + } + LISTod; + fprintf( f, " underlying_type = o.CurrentUnderlyingType ();\n" ); + fprintf( f, " return *this;\n}\n\n" ); + fprintf( f, "#endif\n" ); + +#ifdef JNK + /* define ShallowCopy because operator= does not always act virtual */ + fprintf( f, "SCLP23(Select)& %s::ShallowCopy ( const SCLP23(Select)& o )\n{\n", n ); + + LISTdo( SEL_TYPEget_items( type ), t, Type ) + strncpy( x, TYPEget_name( t ), BUFSIZ ); + fprintf( f, " if( o.CurrentUnderlyingType () == %s )\n", + TYPEtd_name( t ) ); + if( utype_member( dups, t, 1 ) ) + /** if in the dup list **/ + fprintf( f, " _%s = o._%s;\n", + SEL_ITEMget_dmname( t ), + StrToLower( TYPEget_utype( t ) ) ); + else + fprintf( f, "\t_%s = o._%s;\n", + SEL_ITEMget_dmname( t ), + SEL_ITEMget_dmname( t ) ); + LISTod; + fprintf( f, " underlying_type = o.CurrentUnderlyingType ();\n" ); + fprintf( f, " return *this;\n}\n" ); +#endif +} + + +/******************* +TYPEselect_init_print prints the types that belong to the select type +*******************/ + +void +TYPEselect_init_print( const Type type, FILE * f, Schema schema ) { +#define schema_name SCHEMAget_name(schema) + LISTdo( SEL_TYPEget_items( type ), t, Type ) + + fprintf( f, "\t%s -> Elements ().AddNode", + TYPEtd_name( type ) ); + fprintf( f, " (%s);\n", + TYPEtd_name( t ) ); + LISTod; +#undef schema_name +} + +void +TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) { + char n[BUFSIZ]; /* pointers to class name(s) */ + const char * dm; /* data member name */ + Linked_List data_members = SELgetnew_dmlist( type ); + + strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ ); + + fprintf( f, "\n\n// STEP Part 21\n" ); + /* write part 21 */ + fprintf( f, "\nvoid\n%s::STEPwrite_content (ostream& out, const char *" + " currSch) const\n{\n ", n ); + + /* go through the items */ + LISTdo( SEL_TYPEget_items( type ), t, Type ) + dm = SEL_ITEMget_dmname( t ); + + fprintf( f, "if (CurrentUnderlyingType () == %s)\n", + TYPEtd_name( t ) ); + + switch( TYPEget_body( t )->type ) { + + /* if it\'s a number, just print it */ + case integer_: + fprintf( f, "\tout << _%s;\n else ", dm ); + break; + + case number_: + case real_: + fprintf( f, "\tWriteReal(_%s,out);\n else ", dm ); + break; + + case entity_: + fprintf( f, "\t_%s -> STEPwrite_reference (out);\n else ", dm ); + break; + + case string_: + case enumeration_: + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + case logical_: + case boolean_: + case binary_: + /* for string\'s, enum\'s, select\'s, binary\'s, and aggregate\'s + it\'ll be embedded; + */ + fprintf( f, "\t_%s.STEPwrite (out);\n else ", dm ); + break; + + case select_: + fprintf( f, "\t_%s.STEPwrite (out, currSch);\n else ", dm ); + /* Select type needs currSch passed too. A Select writes the name of its + // current choice when it writes itself out (e.g. "DATA(33.5)"). Since + // the current choice name may depend on our current schema (it may be a + // schema which USEs "DATA" and renames it to "VAL"), we pass currSch. */ + break; + + default: + /* otherwise it\'s a pointer */ + fprintf( f, "\t_%s -> STEPwrite (out);\n else ", dm ); + break; + } + LISTod; + + fprintf( f, " {\n" ); + PRINT_BUG_REPORT + fprintf( f, " }\n" ); + fprintf( f, " return;\n}\n" ); + + /* ValueType() -- get type of value stored in select */ + + fprintf( f, "\nBASE_TYPE\n%s::ValueType() const\n{\n ", n ); + + LISTdo( SEL_TYPEget_items( type ), t, Type ) + dm = SEL_ITEMget_dmname( t ); + fprintf( f, "if (CurrentUnderlyingType() == %s)\n", + TYPEtd_name( t ) ); + + switch( TYPEget_body( t )->type ) { + case select_: + fprintf( f, " return _%s.ValueType();\n else ", dm ); + break; + default: + fprintf( f, " return %s;\n else ", FundamentalType( t, 0 ) ); + } + LISTod; + + fprintf( f, " {\n" ); + PRINT_BUG_REPORT + fprintf( f, " }\n" ); + fprintf( f, " return (BASE_TYPE)0;\n}\n" ); + + /* STEPwrite_verbose() -- print value with specified type */ + + fprintf( f, "\nvoid\n%s::STEPwrite_verbose (ostream& out," + " const char *currSch) const\n{\n", n ); + + /* Get name of typedescriptor, according to value of currSch: */ + fprintf( f, " const TypeDescriptor *td = CurrentUnderlyingType();\n" ); + fprintf( f, " std::string tmp;\n\n" ); + fprintf( f, " if ( td ) {\n" ); + fprintf( f, " // If we have a legal underlying type, get its name acc\n" ); + fprintf( f, " // to the current schema.\n" ); + fprintf( f, " StrToUpper( td->Name(currSch), tmp );\n" ); + fprintf( f, " }\n " ); + + /* Next loop through the possible items: */ + LISTdo( SEL_TYPEget_items( type ), t, Type ) + dm = SEL_ITEMget_dmname( t ); + fprintf( f, "if (td == %s)\n", + TYPEtd_name( t ) ); + + switch( TYPEget_body( t )->type ) { + case integer_: + /* fprintf(f, " out << \"%s(\" << _%s << \")\";\n else ", + StrToUpper(TYPEget_name(t)), dm);*/ + fprintf( f, " out << tmp.c_str() << \"(\" << _%s << \")\";\n else ", + dm ); + break; + + case real_: + case number_: + fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); + fprintf( f, " WriteReal(_%s,out);\n", dm ); + fprintf( f, " out << \")\";\n }\n else " ); + break; + + case entity_: + fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); + fprintf( f, " _%s -> STEPwrite_reference (out);\n", dm ); + fprintf( f, " out << \")\";\n }\n else " ); + break; + case string_: + case enumeration_: + case logical_: + case boolean_: + case binary_: + fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); + fprintf( f, " _%s.STEPwrite (out);\n", dm ); + fprintf( f, " out << \")\";\n }\n else " ); + break; + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + /* Aggregates need currSch passed since they may be aggrs of sels. */ + fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); + fprintf( f, " _%s.STEPwrite (out, currSch);\n", dm ); + fprintf( f, " out << \")\";\n }\n else " ); + break; + case select_: + fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); + fprintf( f, " _%s.STEPwrite_verbose (out, currSch);\n", dm ); + fprintf( f, " out << \")\";\n }\n else " ); + break; + default: + fprintf( f, " _%s -> STEPwrite (out); \n else ", dm ); + break; + } + LISTod; + + fprintf( f, " {\n" ); + PRINT_BUG_REPORT + fprintf( f, " }\n" ); + fprintf( f, " return;\n}\n" ); + + + /* Read part 21 */ + fprintf( f, "\nSeverity\n%s::STEPread_content " + "(istream& in, InstMgr * instances,\n\t\t\tconst char *utype, " + "int addFileId, const char *currSch)\n{\n", n ); + + /* go through the items */ + LISTdo( SEL_TYPEget_items( type ), t, Type ) + + fprintf( f, " if (CurrentUnderlyingType () == %s) ", + TYPEtd_name( t ) ); + + dm = SEL_ITEMget_dmname( t ); + + switch( TYPEget_body( t )->type ) { + /* if it\'s a number, just read it */ + case real_: + case number_: + /* since REAL and NUMBER are handled the same they both need + to be included in the case stmt */ + fprintf( f, " {\n\tReadReal (_%s, in, &_error, \"),\");\n" + "\treturn severity ();\n }\n", + dm ); + break; + + case integer_: + fprintf( f, " {\n\tReadInteger (_%s, in, &_error, \"),\");\n" + "\treturn severity ();\n }\n", + dm ); + break; + + case entity_: + /* if it\'s an entity, use Assign - done in Select class */ + fprintf( f, + " {\n\t// set Underlying Type in Select class\n" + "\t_%s = ReadEntityRef " + "(in, &_error, \",)\", instances, addFileId);\n", dm ); + fprintf( f, "\tif (_%s && (_%s != S_ENTITY_NULL)\n " + "\t && (CurrentUnderlyingType () -> CanBe (_%s -> eDesc )) )\n" + "\t return severity ();\n", + dm, dm, dm ); + fprintf( f, "\telse {\n " + "\t Error (\"Reference to instance that is not indicated type\\n\");\n" + "\t _%s = 0;\n" + "\t nullify ();\n" + "\t return severity (SEVERITY_USERMSG);\n\t}\n }\n", + dm + ); + break; + + case string_: + case enumeration_: + case logical_: + case boolean_: + case binary_: + fprintf( f, + " {\n\t_%s.STEPread (in, &_error);\n" + "\treturn severity ();\n }\n", + dm ); + break; + case select_: + fprintf( f, + " {\n\t_%s.STEPread (in, &_error, instances, utype, " + "addFileId, currSch);\n\treturn severity ();\n }\n", + dm ); + break; + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + fprintf( f, + " {\n\t_%s.STEPread (in, &_error,\n" + "\t\t\t %s -> AggrElemTypeDescriptor (),\n" + "\t\t\t instances, addFileId, currSch);\n" + "\treturn severity ();\n }\n", + dm, TYPEtd_name( t ) ); + break; + + default: + fprintf( f, + " {\n\t_%s -> STEPread (in, &_error, instances, addFileId);\n" + "\treturn severity ();\n }\n", + dm ); + break; + } + + LISTod; + + PRINT_SELECTBUG_WARNING( f ) ; + fprintf( f, "#ifdef __SUNCPLUSPLUS__\n" + "std::cerr << instances << \" \" << addFileId << std::endl;\n" + "#endif\n" ); + + LISTfree( data_members ); + fprintf( f, + /* "#ifdef __GNUG__\n"*/ + /* "\n return SEVERITY_NULL;\n"*/ + /* "#endif"*/ + "\n return severity ();" + "\n}\n" ); +} + + +void +TYPEselect_lib_StrToVal( const Type type, FILE * f, Schema schema ) { + char n[BUFSIZ]; /* pointers to class name */ + Linked_List data_members = SELgetnew_dmlist( type ); + int enum_cnt = 0; + + strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ ); + + /* read StrToVal_content */ + fprintf( f, "\nSeverity\n%s::StrToVal_content " + "(const char * str, InstMgr * instances)" + "\n{\n", n ); + + fprintf( f, " switch (base_type) {\n" ); + LISTdo( data_members, t, Type ) + /* fprintf (f, " case %s : \n", FundamentalType (t, 0));*/ + + switch( TYPEget_body( t )->type ) { + + case real_: + case integer_: + case number_: + case select_: + /* if it\'s a number, use STEPread_content - done in Select class */ + /* if it\'s a select, use STEPread_content - done in Select class */ + /* fprintf (f, "\t// done in Select class\n\treturn SEVERITY_NULL;\n");*/ + break; + + case entity_: + /* if it\'s an entity, use AssignEntity - done in Select class */ + /* fprintf (f, "\t// done in Select class\n\treturn SEVERITY_NULL;\n");*/ + + break; + case binary_: + case logical_: + case boolean_: + case enumeration_: + if( !enum_cnt ) { + /* if there\'s more than one enumeration they are done in Select class */ + fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); + fprintf( f, + "\treturn _%s.StrToVal (str, &_error);\n", + SEL_ITEMget_dmname( t ) ); + } else { + fprintf( f, " // case %s : done in Select class\n", FundamentalType( t, 0 ) ); + } + ++enum_cnt; + break; + + case string_: + fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); + fprintf( f, + "\treturn _%s.StrToVal (str);\n", + SEL_ITEMget_dmname( t ) ); + break; + + case aggregate_: + case array_: + case bag_: + case set_: + case list_: + fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); + fprintf( f, + "\treturn _%s.StrToVal (str, &_error, " + "%s -> AggrElemTypeDescriptor ());\n", + /* "instances, addFileId); "*/ + SEL_ITEMget_dmname( t ), + TYPEtd_name( t ) ); + break; + + default: + /* otherwise use StrToVal on the contents to check the format */ + fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); + fprintf( f, + "\treturn _%s -> StrToVal (str, instances);\n", + SEL_ITEMget_dmname( t ) ); + } + LISTod; + + fprintf( f, " default: // should never be here - done in Select class\n" ); + PRINT_SELECTBUG_WARNING( f ) ; + fprintf( f, "#ifdef __SUNCPLUSPLUS__\n" + "std::cerr << str << \" \" << instances << std::endl;\n" + "#endif\n" ); + fprintf( f, "\treturn SEVERITY_WARNING;\n }\n" ); + + LISTfree( data_members ); + fprintf( f, + "#ifdef __GNUG__\n" + "\n return SEVERITY_NULL;\n" + "#endif" + "\n}\n" ); +} + +void +TYPEselect_lib_virtual( const Type type, FILE * f, Schema schema ) { + TYPEselect_lib_part21( type, f, schema ); + TYPEselect_lib_StrToVal( type, f, schema ); +} + +void +SELlib_print_protected( const Type type, FILE * f, const Schema schema ) { + const char * snm; + + /* SELECT::AssignEntity */ + fprintf( f, "\nconst TypeDescriptor * \n%s::AssignEntity (SCLP23(Application_instance) * se)\n" + "{\n", + SelectName( TYPEget_name( type ) ) + ); + + + /* loop through the items in the SELECT */ + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if( TYPEis_entity( t ) ) { + fprintf( f, + " // %s\n" /* item name */ + " if (se -> IsA (%s))\n" /* td */ + " { \n" + "\t_%s = (%s_ptr) se;\n" /* underlying data member */ + /* underlying data member type */ + "\treturn SetUnderlyingType (%s);\n" /* td */ + " }\n", + StrToUpper( TYPEget_name( t ) ), + TYPEtd_name( t ), + SEL_ITEMget_dmname( t ), + ClassName( TYPEget_name( t ) ), + TYPEtd_name( t ) + ); + } + if( TYPEis_select( t ) ) { + fprintf( f, + " // %s\n" /* item name */ + " if (%s -> CanBe (se -> eDesc))\n" + " { \n" + "\t_%s.AssignEntity (se);\n" /* underlying data member */ + "\treturn SetUnderlyingType (%s);\n" /* td */ + " }\n", + StrToUpper( TYPEget_name( t ) ), + TYPEtd_name( t ), + SEL_ITEMget_dmname( t ), + TYPEtd_name( t ) + ); + } + + LISTod; + fprintf( f, " // should never be here - done in Select class\n" ); + PRINT_SELECTBUG_WARNING( f ) ; + fprintf( f, + "#ifdef __SUNCPLUSPLUS__\n" + " std::cerr << se -> EntityName () << std::endl;\n" + "#endif\n" + " return 0;\n}\n" ); + + /* SELECT::NewSelect */ + snm = SelectName( TYPEget_name( type ) ); + fprintf( f, "\nSCLP23(Select) * \n%s::NewSelect ()\n{\n", snm ); + + fprintf( f, " %s * tmp = new %s();\n", snm, snm ); + fprintf( f, " return tmp;\n}\n" ); +} + + +/******************* +TYPEselect_lib_print prints the member functions (definitions) of a select +class. +*******************/ +void +TYPEselect_lib_print( const Type type, FILE * f, Schema schema ) { + // first prevent to use python keywords + if (is_python_keyword(TYPEget_name(type))) { + fprintf( f, "# SELECT TYPE %s_\n", TYPEget_name(type) ); + fprintf( f, "%s_=SELECT([",TYPEget_name(type)); + } + else { + fprintf( f, "# SELECT TYPE %s\n", TYPEget_name(type) ); + fprintf( f, "%s=SELECT([",TYPEget_name(type)); + } + // first compute the number of types (necessary to insert commas) + int nbr_select = 0; + LISTdo( SEL_TYPEget_items( type ), t, Type ) + nbr_select++; + LISTod; + // then write types + int num = 0; + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if (is_python_keyword(TYPEget_name(t))) { + fprintf( f, "%s_",TYPEget_name(t)); + } + else { + fprintf( f, "%s",TYPEget_name(t)); + } + if (num < nbr_select -1 ) fprintf(f,","); + num++; + LISTod; + fprintf(f,"])\n"); +} + +void +TYPEselect_print( Type t, FILES * files, Schema schema ) { + SelectTag tag, tmp; + Type i, bt; /* type of elements in an aggregate */ + char nm[BUFSIZ], tdnm[BUFSIZ]; + FILE * inc = files->inc; + + /* if type is already marked, return */ + if( ( SelectTag )( tmp = TYPEget_clientData( t ) ) ) { + if( ( tmp ->started ) && ( ! tmp ->complete ) ) + fprintf( stderr, "WARNING: SELECT type %s causes circular references\n", + TYPEget_name( t ) ); + return; + } + + /* mark the type as being processed */ + tag = ( SelectTag ) malloc( sizeof( struct SelectTag_ ) ); + tag -> started = 1; + tag -> complete = 0; + TYPEput_clientData( t, tag ); + + + /* Check if we're a renamed type, e.g., TYPE B (sel) = A. If so, if A has + // been defined, we process B differently (with a couple of typedef's - + // some are printed in files->classes rather than here). If A has not been + // defined, we must recurse. */ + if( ( i = TYPEget_ancestor( t ) ) != NULL ) { + if( !TYPEget_clientData( i ) ) { + TYPEselect_print( i, files, schema ); + } + strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ ); + strncpy( tdnm, TYPEtd_name( t ), BUFSIZ ); + fprintf( inc, "typedef %s * \t%sH;\n", nm, nm ); + fprintf( inc, "typedef %s_ptr *\t%s_var;\n", nm, nm ); + /* Below are specialized create functions for the renamed sel type (both + // single and aggregate). The functions call the original sel's con- + // structor, passing the new sel's typedescriptor to create a hybrid + // entity - the original select pointing to a new typedesc. These fns + // give the user an easy way to create the renamed type properly. */ + fprintf( inc, "inline SCLP23(Select) *\ncreate_%s ()", nm ); + fprintf( inc, " { return new %s( %s ); }\n\n", nm, tdnm ); + fprintf( inc, "inline STEPaggregate *\ncreate_%ss ()", nm ); + fprintf( inc, " { return new %ss( %s ); }\n\n", nm, tdnm ); + return; + } + + LISTdo( SEL_TYPEget_items( t ), i, Type ) + + /* check the items for select types */ + /* and do the referenced select types first */ + + /* check aggregates too */ + /* set i to the bt and catch in next ifs */ + if( isAggregateType( i ) ) { + bt = TYPEget_base_type( i ); + /* DAR - corrected - prev'ly above line retrieved non-aggr base type. + // But unnec - we only need the item defined if it's a select or a 1D + // aggregate. If bt is also an aggr, we go on. */ + if( TYPEis_select( bt ) ) { + i = bt; + } else if( TYPEis_entity( bt ) ) { + i = bt; + } + } + + if( TYPEis_select( i ) && !TYPEget_clientData( i ) ) { + TYPEselect_print( i, files, schema ); + } + /* NOTE - there was a bug here because above if did not take into account + that i came from a different schema (and above loop would have printed + it here!). Taken care of by code in multpass.c which would not allow + us to get this far (wouldn't have called the type_print() fn's) if a + select has members in other schemas which haven't been processed. So, + now by definition i must have been processed already if it's in another + schema. So the above if will only reorder the printing of the sel's in + this schema, which is the intent. DAR */ + +#ifdef OBSOLETE + /* check the attributes to see if a select is referenced */ + if( TYPEis_entity( i ) ) { + LISTdo( ENTITYget_all_attributes( ENT_TYPEget_entity( i ) ), a, Variable ) + if( TYPEis_select( VARget_type( a ) ) ) { + TYPEselect_print( VARget_type( a ), files, schema ); + } + LISTod + } +#endif + LISTod + + //TYPEselect_inc_print( t, files -> inc ); + TYPEselect_lib_print( t, files -> lib, schema ); + /* TYPEselect_init_print (t, files -> init, schema); + DAR - moved to TYPEprint_init() - to keep init info together. */ + tag -> complete = 1; +} +#undef BASE_SELECT + + +/************************************************************************** +******** END of SELECT TYPE +**************************************************************************/ From bd9942dc3683f5ebf59886d07d85272d276dc5a7 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Tue, 10 Jan 2012 22:04:09 +0100 Subject: [PATCH 02/19] * Made ARRAY implementation strictly comply with ISO 10303-11:1994 * Updated SCL unittest. --- .../python/SCL/AggregationDataType.py | 58 ++++++++++++-- src/fedex_python/python/SCL_unittest.py | 75 +++++++++++++++++-- 2 files changed, 119 insertions(+), 14 deletions(-) diff --git a/src/fedex_python/python/SCL/AggregationDataType.py b/src/fedex_python/python/SCL/AggregationDataType.py index b36a95b54..a841313f8 100644 --- a/src/fedex_python/python/SCL/AggregationDataType.py +++ b/src/fedex_python/python/SCL/AggregationDataType.py @@ -30,13 +30,12 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from SimpleDataTypes import * +from TypeChecker import * class BaseAggregate(object): """ A class that define common properties to ARRAY, LIST, SET and BAG. """ def __init__( self , bound1 , bound2 , base_type ): - # init base list with an empty list - list.__init__(self,[]) # check that bound1bound2: @@ -44,8 +43,7 @@ def __init__( self , bound1 , bound2 , base_type ): self._bound1 = bound1 self._bound2 = bound2 self._base_type = base_type - print base_type - + def __getitem__(self, index): if indexself._bound_2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + else: + value = self._container[index-self._bound_1] + if not self._optional and value==None: + raise AssertionError("Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first."%index) + return value + def __setitem__(self, index, value): + if indexself._bound_2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + else: + # first check the type of the value + check_type(value,self._base_type) + # then check if the value is already in the array + if self._unique: + if value in self._container: + raise AssertionError("UNIQUE keyword prevent inserting this instance.") + self._container[index-self._bound_1] = value + class LIST(list, BaseAggregate): """A list data type has as its domain sequences of like elements. The optional lower and upper bounds, which are integer-valued expressions, dfine the minimum and maximum number of diff --git a/src/fedex_python/python/SCL_unittest.py b/src/fedex_python/python/SCL_unittest.py index e6f3f8a2c..b76894a62 100644 --- a/src/fedex_python/python/SCL_unittest.py +++ b/src/fedex_python/python/SCL_unittest.py @@ -29,11 +29,12 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import unittest + from SCL.SimpleDataTypes import * from SCL.TypeChecker import * from SCL.ConstructedDataTypes import * - -import unittest +from SCL.AggregationDataType import * # # Simple data types @@ -133,7 +134,70 @@ def test_create_from_bool(self): self.assertTrue(a) b = BOOLEAN(False) self.assertFalse(b) - + +# +# AggregationDataTypeSimple +# +class TestARRAY(unittest.TestCase): + ''' + ARRAY test + ''' + def test_create_array(self): + ARRAY(1,7,REAL) + #upper and lower bounds can be negative + ARRAY(-1,5,INTEGER) + ARRAY(-4,-3,INTEGER) + # they even can be both 0 + ARRAY(0,0,REAL) + ARRAY(1,1,BOOLEAN) + # lower bound should be less or equal than upper bound + try: + ARRAY(3,2,REAL) + except AssertionError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + + def test_array_unique(self): + # if UNIQUE is not set to True (False by default), + # the array may contain the same instance at different + # positions + a = ARRAY(1,4,REAL) + a[3] = REAL(4) + a[4] = REAL(4) + # however, if UNIQUE, then every instances in the + # array must be different + a = ARRAY(1,4,REAL,UNIQUE=True) + a[3] = REAL(4) + try: + a[3] = REAL(4) + except AssertionError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + + def test_array_optional(self): + # if OPTIONAL is not set explicitely to True + # then each value must be set + a = ARRAY(1,3,REAL) + try: + a[1] + except AssertionError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + # if OPTIONAL is set to True, then values + # can be indeterminated + b = ARRAY(1,3,REAL,OPTIONAL=True) + b[2] = REAL(5) + b[3] = REAL(5) + # # TypeChecker # @@ -153,14 +217,13 @@ class P: check_type(3,P) except TypeError: pass - except a: + except e: self.fail('Unexpected exception thrown:', e) else: self.fail('ExpectedException not thrown') def test_check_enum_type(self): enum = ENUMERATION(["my","string"]) - print check_type("my",enum) - + unittest.main() From 575c77dda91082b7f6db08db4b651908d51e6f16 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Wed, 11 Jan 2012 15:46:28 +0100 Subject: [PATCH 03/19] Bugfix: segfault when processing ap203 schema --- src/fedex_python/src/multpass_python.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/fedex_python/src/multpass_python.c b/src/fedex_python/src/multpass_python.c index e07141574..50f8e889a 100644 --- a/src/fedex_python/src/multpass_python.c +++ b/src/fedex_python/src/multpass_python.c @@ -642,16 +642,17 @@ static void addAggrTypedefs( Schema schema, FILE * classes ) // the only types which had to wait for their underlying type. // 2D aggr's and higher only need type GenericAggr defined // which is built-in. */ - if( firsttime ) { - fprintf( classes, "\n// Aggregate types (from all sche" ); - fprintf( classes, "mas) which depend on other types:\n" ); - firsttime = FALSE; - } - strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); - fprintf( classes, "typedef %s\t%s;\n", - TYPEget_ctype( t ), nm ); - fprintf( classes, "typedef %s *\t%sH;\n", nm, nm ); - fprintf( classes, "typedef %s *\t%s_ptr;\n", nm, nm ); + printf("in addAggrTypedefs. %s is enum or select.\n",TYPEget_name(t)); + //if( firsttime ) { + // fprintf( classes, "\n// Aggregate types (from all sche" ); + // fprintf( classes, "mas) which depend on other types:\n" ); + // firsttime = FALSE; + //} + //strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); + //fprintf( classes, "typedef %s\t%s;\n", + // TYPEget_ctype( t ), nm ); + //fprintf( classes, "typedef %s *\t%sH;\n", nm, nm ); + //fprintf( classes, "typedef %s *\t%s_ptr;\n", nm, nm ); } } SCOPEod From ee78ba9c52974c9c2f31977dbdf901805af34046 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Thu, 12 Jan 2012 06:42:40 +0100 Subject: [PATCH 04/19] Moved AggregationDataType module name to AggregationDataTypes --- ...ionDataType.py => AggregationDataTypes.py} | 0 src/fedex_python/python/SCL/Expr.py | 2 +- src/fedex_python/python/SCL/Part21.py | 121 ++++++++++++++---- .../python/SCL/SimpleDataTypes.pyc | Bin 0 -> 7205 bytes src/fedex_python/python/SCL/__init__.py | 1 + src/fedex_python/python/SCL/__init__.pyc | Bin 0 -> 258 bytes src/fedex_python/python/SCL/as1.stp | 35 +++++ src/fedex_python/python/SCL/essa_par.py | 54 ++++++++ src/fedex_python/python/SCL_unittest.py | 3 + .../src/classes_wrapper_python.cc | 2 +- 10 files changed, 190 insertions(+), 28 deletions(-) rename src/fedex_python/python/SCL/{AggregationDataType.py => AggregationDataTypes.py} (100%) create mode 100644 src/fedex_python/python/SCL/SimpleDataTypes.pyc create mode 100644 src/fedex_python/python/SCL/__init__.pyc create mode 100644 src/fedex_python/python/SCL/as1.stp create mode 100644 src/fedex_python/python/SCL/essa_par.py diff --git a/src/fedex_python/python/SCL/AggregationDataType.py b/src/fedex_python/python/SCL/AggregationDataTypes.py similarity index 100% rename from src/fedex_python/python/SCL/AggregationDataType.py rename to src/fedex_python/python/SCL/AggregationDataTypes.py diff --git a/src/fedex_python/python/SCL/Expr.py b/src/fedex_python/python/SCL/Expr.py index 685743af0..068242c0b 100644 --- a/src/fedex_python/python/SCL/Expr.py +++ b/src/fedex_python/python/SCL/Expr.py @@ -59,7 +59,7 @@ def EvalDerivedAttribute(class_instance, str_expr): for item in props: str_expr = str_expr.replace(item,"class_instance.%s"%item) # after that step, the expression should be: - # PI*class_instance.radiüs*class_instance.radius + # PI*class_instance.radius*class_instance.radius # this can be evaluated with the eval function # CAREFUL: eval is known to be unsafe. This should be changed in the future # (using a parser, or simpy for instance) diff --git a/src/fedex_python/python/SCL/Part21.py b/src/fedex_python/python/SCL/Part21.py index 75a5fdcb2..4d82d666d 100644 --- a/src/fedex_python/python/SCL/Part21.py +++ b/src/fedex_python/python/SCL/Part21.py @@ -67,8 +67,27 @@ def print_instances(self): "==========" print "Instance #%i"%(idx+1) print self._instances[idx] - -class Part21Loader: + +class Part21EntityInstance: + """ + A class to represent a Part21 instance as defined in one Part21 file + A Part21EntityInstance is defined by the following arguments: + entity_name: a string + entity_attributes: a list of strings to represent an attribute. + For instance, the following expression: + #4 = PRODUCT_DEFINITION_SHAPE('$','$',#5); + will result in : + entity : + entity_instance_attributes: ['$','$','#5'] + """ + def __init__(self,entity_name,attributes): + self._entity + self._attributes_definition = attributes + print self._entity_name + print self._attributes_definition + + +class Part21Parser: """ Loads all instances definition of a Part21 file into memory. Two dicts are created: @@ -79,7 +98,7 @@ class Part21Loader: def __init__(self, filename): self._filename = filename # the schema - self._schema = "" + self._schema_name = "" # the dict self._instances contain instance definition self._instances_definition = {} # this dict contains lists of 0 ancestors, 1 ancestor, etc. @@ -87,23 +106,57 @@ def __init__(self, filename): self._number_of_ancestors = {} for i in range(2000): self._number_of_ancestors[i]=[] - print "Parsing file %s..."%filename, self.parse_file() - print "done." # reduce number_of_ancestors dict for item in self._number_of_ancestors.keys(): if len(self._number_of_ancestors[item])==0: del self._number_of_ancestors[item] - def get_schema(self): - return self._schema + def get_schema_name(self): + return self._schema_name + print schema_name def get_number_of_instances(self): return len(self._instances_definition.keys()) - + + def parse_attributes(self, attr_str): + """ + This method takes a string an returns a list of attributes (but without any mapping). + For instance: + input = "'',(#11,#15,#19,#23,#27),#31" + output = ['',(#11,#15,#19,#23,#27),'#31'] + """ + aggr_scope_level = 0 + attrs = [] + current_attr = '' + previous_ch = '' + for ch in attr_str: + if ch == ',' and aggr_scope_level == 0: + attrs.append(current_attr) + current_attr = '' + else: + if ch == '(': + aggr_scope_level +=1 + elif ch == ')': + aggr_scope_level -= 1 + current_attr += ch + previous_ch = ch + # finally add the last attr when exiting loop + attrs.append(current_attr) + return attrs + def parse_file(self): + init_time = time.time() + print "Parsing file %s..."%self._filename, fp = open(self._filename) - for line in fp: + while True: + line = fp.readline() + if not line: + break + # there may be a multline definition. In this case, we read lines untill we found + # a ; + while (not line.endswith(";\r\n")): #its a multiline + line = line.replace("\r\n","") + fp.readline() # parse line match_instance_definition = INSTANCE_DEFINITION_RE.search(line) # id,name,attrs if match_instance_definition: @@ -113,13 +166,33 @@ def parse_file(self): number_of_ancestors = entity_attrs.count('#') # fill number of ancestors dict self._number_of_ancestors[number_of_ancestors].append(instance_int_id) - self._instances_definition[instance_int_id] = [entity_name,entity_attrs] + # parse attributes string + entity_attrs_list = self.parse_attributes(entity_attrs) + # then finally append this instance to the disct instance + self._instances_definition[instance_int_id] = (entity_name,entity_attrs_list) else: #does not match with entity instance definition, parse the header if line.startswith('FILE_SCHEMA'): #identify the schema name - self._schema = line.split("'")[1].split("'")[0].split(" ")[0].lower() + self._schema_name = line.split("'")[1].split("'")[0].split(" ")[0].lower() fp.close() - + print 'done in %fs.'%(time.time()-init_time) + print 'schema: - %s entities %i'%(self._schema_name,len(self._instances_definition.keys())) + +class EntityInstancesFactory(object): + ''' + This class creates entity instances from the str definition + For instance, the definition: + 20: ('CARTESIAN_POINT', ["''", '(5.,125.,20.)']) + will result in: + p = ARRAY(1,3,REAL) + p.[1]=REAL(5) + p.[2] = REAL(125) + p.[3] = REAL(20) + new_instance = cartesian_point(STRING(''),p) + ''' + def __init__(self, schema_name, instance_definition): + # First try to import the schema module + pass class Part21Population(object): def __init__(self, part21_loader): """ Take a part21_loader a tries to create entities @@ -185,19 +258,15 @@ def map_express_to_python(self,attr): if __name__ == "__main__": import time import sys - sys.path.append("..") - from config_control_design import * - t1 = time.time() - print "Loading file into memory" - #file = Part21Loader("as1-oc-214.stp") + #sys.path.append("..") + #from config_control_design import * + #p21loader = Part21Loader("as1-oc-214.stp") #file = Part21Loader("as1-tu-203.stp") #file = Part21Loader("HAYON.stp") - p21loader = Part21Loader("as1.stp") - t2 = time.time() - print "Loading schema took: %s s \n" % ((t2-t1)) - t1 = time.time() - print "Creating instances" - p21population = Part21Population(p21loader) - p21population.create_entity_instances() - t2 = time.time() - print "Creating instances took: %s s \n" % ((t2-t1)) \ No newline at end of file + p21loader = Part21Parser("as1.stp") + print p21loader._instances_definition + #print "Creating instances" + #p21population = Part21Population(p21loader) + #p21population.create_entity_instances() + #t2 = time.time() + #print "Creating instances took: %s s \n" % ((t2-t1)) \ No newline at end of file diff --git a/src/fedex_python/python/SCL/SimpleDataTypes.pyc b/src/fedex_python/python/SCL/SimpleDataTypes.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4e015cfe88ffe5293a9d36a987599226cf167f34 GIT binary patch literal 7205 zcmcgxTW=J}6|Np%u#F7{gCQF!DJ6?Mmb?zeTowdLY}SA!V$j%o^C}wkbk}$qdb)@1 z9viQCNWwnk4@An3$V2{0{z{(m5Gnb-Q{6o`Ft9`!smpz-s&oI&spEhAb8cqt-_uV# zmH)=@_qVvxs-u*z)ILT>`9D#9Mg5@EYo)&3$Mcvn71hMec=>ir`4h^F%iGEF?S%4A zDKjZ=r^>gdls~QfPn17XzM4{Iireo`D>I|^Pb>d)v2M1UG^@;<^5@jEii&?wj(z}Qy-C4VR`+9Y2c_y30s+})?x4Bg-Z2--yP40LJgMmt*XN(nE0yfwmQ?=b{ zg%iHQ)ESN6Ud!mH+isXd`)=my?6_le%LNmu4zg7HaoY_d?S>(znI!P^p&ND$zD7F3 z;?Ru_y6%Bl9o|Z|m+jIPmp6>=rpDJtErb1ZJBE~L$9O>#dlq{qrjwY|M46ifaioJ( zM{%Zub|+3UH_BFJQyHEfXD!TVyPXb{c1L?|#HpadSD=%{pwj3DVFpe+b~f3ujCyed zb$7iiPIMfF$J%Qd?|BN5+{|(g**b3GwoL}zbljA@yWk}XvcL_4?@JEdT!EH3kNV|B zW89~%$1%VRy9^AqQ^laf2pK=5CTwOCxDl<|kDQS%V%WX^_*c6SJ~UszHhW+`U4{>3E2-7E9E(jv<(7@H2 zurXDY#$i_ig0d4H%uCnHR`sr^p@<*^af->E&qNFxNBTtzM*I;>hY`VFK*h?BtX z*r$wi5N#YIRNLe;OS@(93L&6R4Q=&nV?(R~WSc0GsyK4`qicyIGwwkLUW&y)6I4p_G;PF#xUDRC`W=b}!bq<0(4HDy1*HB8I(^>>K#3)$bLTe{Z;a1|NnK=MP3W8bQ8_W7@!h96> zlPl1^L{2hnvq&ikIiv)AVNJz$BLKGL5xPJ|0+*sT8HRI#L@ZYIGQm`MZh87Z13!CJ$zF>ej6hG4U2@GJ%}7cR*&z>!^ONo z(1RO_en$Y0niLx4z9(odmw+noQywT<)qSMan7AI5TAP5@sP^5x+V;*v4|no=XBxQz zgOy6NHPeZSBsDL(CPK*3x4af|x(5_OvY^s?&pmjQ%{xH0AOqCV+naIHW;Kx6c+ZK7 z!%IZ_W)>dFlE~I-H?QBcN*>57x7UH5Eb)rWVkJjzISTx&WrMiLC+lmU_rJa;`A6nS z+WAgD*#2hgi!%MJuidiK^$A&LBd6b|uC{y3nkg3mMV|=}euKLBecjR={q?R4ul_M3n^cb*AoqwNAk4k1(Ezx zvcdavyWJ#o+xbwA01E_M5jEvneJ`c0V3VxH&1}I9uTx^=1)YrQ1s;0yyV@eLmu)<$dBR&VsI;<+GP?c&UU zlR%=w_{b#7jPuYS{83R+0$3LKD#1(JNVPM|V#n?y@(gF8H()7zatXUwFkRIf*wy#N zOCXb|+k!yv-~k$pPka8bYKu|BM1F`gjO{E6geE$GntM8ynIDPP(}3frxNMHQl;^m| zPabaH|B$Nx6#!k>VF-lr0a2k3fJV=n6f0{b2D5Fs2)9nUW<@vM5T;^9)QzML%e|z( zcE7$}&?rDQXE-ms$wV^_VPzr@PzFa@+_d7*2Ry<4q%OcN>4HxqJm1MVxm)m|?^?@% zOPf_jme6UuxZOeN(}3k9D7becj!`8>J$5MWyW!PR z#TT0aTLKqkta?7u3wVTlR(ioyp0hW%cQ$I@mN|P26E-=C$If1ag~w1HtH^G zx2|Ck=@s5$1^a)d62}uT%M_*E=E+ieJcLSFbuVGiDti1mx`I!0K zCS*FO5E&8TEvb1AK0lC^`zwNxO-54;Ej(cTJR?h_^m1X5u!b^n!MAmUVO|Ec`eT@} z36qJ~;sJ2_}}45!UJ0wGZE1Om`gT%8L6<<;gexx_S8TrZxv%c{sp*)_I(_diFn{qsGyJ5D1dMi3;iQQQCBBSk~ z^CLD%|A4s+*CkOR`fz1qmL6bxvyE=1mqfKoQle!6>Ub#`R`pXPS-3Vj8tAd0sKBX& zG>YkU9xOI=f%75xSfthH zw;$SKK8-bhBvo!bxiIOR9m~7f{1-&Mp8gE)@1vc8hW>%=$~Kd@t);bNYqkT-!0%tb zu^Rq4?%%K=M*>^rQP#E9YXSeJ0}G1!U5N19Vi(YF%S{L7^zWN7_;1MgdEWEK3sqgf zAk8M}s9QK-YpTYWs9oT|E=g^c11sdJ2fg#%poLQ z85=TsG8!41J^Rbu3D6^|zia<>@N3GPu40(1EX*!mUYuI|WMO9d^kijmdCr+|W}WH2 Jv3Qzw{tM;-<4yno literal 0 HcmV?d00001 diff --git a/src/fedex_python/python/SCL/__init__.py b/src/fedex_python/python/SCL/__init__.py index e69de29bb..96522a17f 100644 --- a/src/fedex_python/python/SCL/__init__.py +++ b/src/fedex_python/python/SCL/__init__.py @@ -0,0 +1 @@ +__all__ = ['SCLBase','SimpleDataTypes','AggregationDataType','TypeChecker','ConstructedDataTypes','Expr','Part21'] diff --git a/src/fedex_python/python/SCL/__init__.pyc b/src/fedex_python/python/SCL/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..44f764573e6c5d20fa9c9b93a8eb959c7b6d04c2 GIT binary patch literal 258 zcmYLD%?<%E5FUTKLU7>jx+lU}1mz}3IJq>(mVB-J&1fb6Ys+@Xp#n<6$#W?S`M&Hyi>4?3a`rGfO?jt7R^0GB}<*fIt@0D+@MF`APi0? ryP!h2Sk1YJW6lHW;h$`A3EPf2*QrL%NBI-oxw9mb_gKxH-#X71pbR>1 literal 0 HcmV?d00001 diff --git a/src/fedex_python/python/SCL/as1.stp b/src/fedex_python/python/SCL/as1.stp new file mode 100644 index 000000000..c2f1c219d --- /dev/null +++ b/src/fedex_python/python/SCL/as1.stp @@ -0,0 +1,35 @@ +ISO-10303-21; +HEADER; +FILE_DESCRIPTION(('Open CASCADE Model'),'2;1'); +FILE_NAME('Open CASCADE Shape Model','2008-07-24T15:00:20',( + '--- Datakit Converter ---'),('--- Datakit www.datakit.com---'), + ' Release Version Jun 30 2008','Open CASCADE 6.1',' '); +FILE_SCHEMA(('AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }')); +ENDSEC; +DATA; +#1 = APPLICATION_PROTOCOL_DEFINITION('international standard', + 'automotive_design',2000,#2); +#2 = APPLICATION_CONTEXT( + 'core data for automotive mechanical design processes'); +#3 = SHAPE_DEFINITION_REPRESENTATION(#4,#10); +#4 = PRODUCT_DEFINITION_SHAPE('$','$',#5); +#5 = PRODUCT_DEFINITION('design','',#6,#9); +#6 = PRODUCT_DEFINITION_FORMATION('','',#7); +#7 = PRODUCT('as1','as1','',(#8)); +#8 = PRODUCT_CONTEXT('',#2,'mechanical'); +#9 = PRODUCT_DEFINITION_CONTEXT('part definition',#2,'design'); +#10 = SHAPE_REPRESENTATION('',(#11,#15,#19,#23,#27),#31); +#11 = AXIS2_PLACEMENT_3D('',#12,#13,#14); +#12 = CARTESIAN_POINT('',(0.E+000,0.E+000,0.E+000)); +#13 = DIRECTION('',(0.E+000,0.E+000,1.)); +#14 = DIRECTION('',(1.,0.E+000,0.E+000)); +#15 = AXIS2_PLACEMENT_3D('',#16,#17,#18); +#16 = CARTESIAN_POINT('',(-10.,75.,60.)); +#17 = DIRECTION('',(1.,0.E+000,0.E+000)); +#18 = DIRECTION('',(0.E+000,0.E+000,-1.)); +#19 = AXIS2_PLACEMENT_3D('',#20,#21,#22); +#20 = CARTESIAN_POINT('',(5.,125.,20.)); +#21 = DIRECTION('',(0.E+000,0.E+000,1.)); +#22 = DIRECTION('',(1.,0.E+000,0.E+000)); +ENDSEC; +END-ISO-10303-21; diff --git a/src/fedex_python/python/SCL/essa_par.py b/src/fedex_python/python/SCL/essa_par.py new file mode 100644 index 000000000..376aa8875 --- /dev/null +++ b/src/fedex_python/python/SCL/essa_par.py @@ -0,0 +1,54 @@ +def process_nested_parent_str(attr_str): + ''' + The first letter should be a parenthesis + input string: "(1,4,(5,6),7)" + output: tuple (1,4,(4,6),7) + ''' + params = [] + agg_scope_level = 0 + current_param = '' + for i,ch in enumerate(attr_str): + if ch==',': + params.append(current_param) + current_param = '' + elif ch=='(': + agg_scope_level +=1 + elif ch==')': + agg_scope_level = 0 + elif agg_scope_level == 0: + current_param += ch + return params + +idx = 0 +def process_nested_parent_str2(attr_str): + ''' + The first letter should be a parenthesis + input string: "(1,4,(5,6),7)" + output: ['1','4',['5','6'],'7'] + ''' + global idx + acc=0 + print 'Entering function with string %s and index %i'%(attr_str,idx) + params = [] + current_param = '' + for i,ch in enumerate(attr_str): + idx += 1 + acc +=1 + if ch==',': + params.append(current_param) + current_param = '' + elif ch=='(': + nv = attr_str[idx:] + print "params",params + print "Str passed to the function:%s (idx=%i)"%(nv,idx) + current_param = process_nested_parent_str2(nv) + elif ch==')': + params.append(current_param) + idx -= acc+1 + return params + else: + current_param += ch + params.append(current_param) + return params +#print process_nested_parent_str2('1,2,3,4,5,6') +print process_nested_parent_str2("'A','B',('C','D'),'E'") \ No newline at end of file diff --git a/src/fedex_python/python/SCL_unittest.py b/src/fedex_python/python/SCL_unittest.py index b76894a62..b32f737ab 100644 --- a/src/fedex_python/python/SCL_unittest.py +++ b/src/fedex_python/python/SCL_unittest.py @@ -160,6 +160,9 @@ def test_create_array(self): else: self.fail('ExpectedException not thrown') + def test_array_bounds(self): + a = ARRAY() + def test_array_unique(self): # if UNIQUE is not set to True (False by default), # the array may contain the same instance at different diff --git a/src/fedex_python/src/classes_wrapper_python.cc b/src/fedex_python/src/classes_wrapper_python.cc index f0b8c9f6e..bb2a4e769 100644 --- a/src/fedex_python/src/classes_wrapper_python.cc +++ b/src/fedex_python/src/classes_wrapper_python.cc @@ -350,7 +350,7 @@ SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol, fprintf(libfile,"from SCL.SCLBase import *\n"); fprintf(libfile,"from SCL.SimpleDataTypes import *\n"); fprintf(libfile,"from SCL.ConstructedDataTypes import *\n"); - fprintf(libfile,"from SCL.AggregationDataType import *\n"); + fprintf(libfile,"from SCL.AggregationDataTypes import *\n"); fprintf(libfile,"from SCL.TypeChecker import check_type\n"); fprintf(libfile,"from SCL.Expr import *\n"); From 8595a291cb40431899b8cbd8902ec1cec3a7892c Mon Sep 17 00:00:00 2001 From: tpaviot Date: Fri, 17 Feb 2012 14:04:41 +0100 Subject: [PATCH 05/19] Code cleanup --- src/fedex_python/src/classes_misc_python.c | 194 -- src/fedex_python/src/classes_python.c | 2379 +------------------- src/fedex_python/src/multpass_python.c | 29 - src/fedex_python/src/selects_python.c | 1129 +--------- 4 files changed, 120 insertions(+), 3611 deletions(-) diff --git a/src/fedex_python/src/classes_misc_python.c b/src/fedex_python/src/classes_misc_python.c index 5c8ea4ca8..28fe661b8 100644 --- a/src/fedex_python/src/classes_misc_python.c +++ b/src/fedex_python/src/classes_misc_python.c @@ -226,147 +226,6 @@ isAggregateType( const Type t ) { } -/****************************************************************** - ** Procedure: TYPEget_ctype - ** Parameters: const Type t -- type for attribute - ** Returns: a string which is the type of the data member in the c++ class - ** Description: supplies the type of a data member for the c++ class - ** Side Effects: - ** Status: complete 1/15/90 - ** Changes: Modified by CD to return the appropriate types as outlined in - ** "SDAI C++ Binding for PDES, Inc. Prototyping" by Stephen Clark - ** Change Date: 5/22/91 CD - ** Change Date: 28-Sep-1993 made entities use their real type instead of base - ** class STEPentityH - ******************************************************************/ - -const char * -TYPEget_ctype( const Type t ) { - Class_Of_Type class; - Type bt; - static char retval [BUFSIZ]; - - - /* aggregates are based on their base type - case TYPE_ARRAY: - case TYPE_BAG: - case TYPE_LIST: - case TYPE_SET: - */ - if( isAggregateType( t ) ) { - bt = TYPEget_body( t )->base; - - if( isAggregateType( bt ) ) { - return( "GenericAggregate" ); - } - - class = TYPEget_type( bt ); - - /* case TYPE_INTEGER: */ - if( class == Class_Integer_Type ) { - return ( "IntAggregate" ); - } - - /* case TYPE_REAL: - case TYPE_NUMBER: */ - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - return ( "RealAggregate" ); - } - - /* case TYPE_ENTITY: */ - if( class == Class_Entity_Type ) { - return( "EntityAggregate" ); - } - - /* case TYPE_ENUM: */ - /* case TYPE_SELECT: */ - if( ( class == Class_Enumeration_Type ) - || ( class == Class_Select_Type ) ) { - /* - strcpy (retval, ClassName (TYPEget_name (bt))); - */ - strcpy( retval, TYPEget_ctype( bt ) ); - strcat( retval, "s" ); - return ( retval ); - } - - /* case TYPE_LOGICAL: */ - if( class == Class_Logical_Type ) { - return ( "LOGICALS" ); - } - - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - return ( "BOOLEANS" ); - } - - /* case TYPE_STRING: */ - if( class == Class_String_Type ) { - return( "StringAggregate" ); - } - - /* case TYPE_BINARY: */ - if( class == Class_Binary_Type ) { - return( "BinaryAggregate" ); - } - } - - /* the rest is for things that are not aggregates */ - - class = TYPEget_type( t ); - - /* case TYPE_LOGICAL: */ - if( class == Class_Logical_Type ) { - return ( "SCLP23(LOGICAL)" ); - } - - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - return ( "SCLP23(BOOLEAN)" ); - } - - /* case TYPE_INTEGER: */ - if( class == Class_Integer_Type ) { - return ( "SCLP23(Integer)" ); - } - - /* case TYPE_REAL: - case TYPE_NUMBER: */ - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - return ( "SCLP23(Real)" ) ; - } - - /* case TYPE_STRING: */ - if( class == Class_String_Type ) { - return ( "SCLP23(String)" ); - } - - /* case TYPE_BINARY: */ - if( class == Class_Binary_Type ) { - return ( "SCLP23(Binary)" ); - } - - /* case TYPE_ENTITY: */ - if( class == Class_Entity_Type ) { - strncpy( retval, TypeName( t ), BUFSIZ - 2 ); - strcat( retval, "_ptr" ); - return retval; - /* return ("STEPentityH"); */ - } - /* case TYPE_ENUM: */ - /* case TYPE_SELECT: */ - if( class == Class_Enumeration_Type ) { - strncpy( retval, TypeName( t ), BUFSIZ - 2 ); - strcat( retval, "_var" ); - return retval; - } - if( class == Class_Select_Type ) { - return ( TypeName( t ) ); - } - - /* default returns undefined */ - return ( "SCLundefined" ); -} /****************************************************************** ** Procedure: TypeName @@ -376,59 +235,6 @@ TYPEget_ctype( const Type t ) { ******************************************************************/ const char * TypeName( Type t ) { - static char name [BUFSIZ]; - strcpy( name, TYPE_PREFIX ); - if( TYPEget_name( t ) ) { - strncat( name, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - strlen( TYPE_PREFIX ) - 1 ); - } else { - return TYPEget_ctype( t ); - } - return name; -} - -/****************************************************************** - ** Procedure: AccessType - ** Parameters: const Type t -- type for attribute - ** Returns: a string which is the type used by the access functions to - the data member in the c++ class - ** Description: supplies the type for access functions in a c++ class - ** Side Effects: - ** Status: 3-Nov-1993 -kcm -******************************************************************/ - -const char * -AccessType( Type t ) { - Class_Of_Type class; - static char nm [BUFSIZ]; - strncpy( nm, TypeName( t ), BUFSIZ - 4 ); - if( TYPEis_entity( t ) ) { - /* if(corba_binding) - { - if (TYPEget_name (t)) - strncpy (nm, FirstToUpper (TYPEget_name (t)), BUFSIZ-1); - } - */ - strcat( nm, "_ptr" ); - return nm; - } else if( TYPEis_select( t ) || TYPEis_aggregate( t ) ) { - strcat( nm, "_ptr" ); - return nm; - } - class = TYPEget_type( t ); - if( class == Class_Enumeration_Type ) { - strncpy( nm, TypeName( t ), BUFSIZ - 2 ); - strcat( nm, "_var" ); - return nm; - } - if( class == Class_Logical_Type ) { - strncpy( nm, "Logical", BUFSIZ - 2 ); - } - - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - strncpy( nm, "Boolean", BUFSIZ - 2 ); - } - return nm; } /****************************************************************** diff --git a/src/fedex_python/src/classes_python.c b/src/fedex_python/src/classes_python.c index 3a256794a..ad0fa7fac 100644 --- a/src/fedex_python/src/classes_python.c +++ b/src/fedex_python/src/classes_python.c @@ -214,185 +214,8 @@ USEREFout( Schema schema, Dictionary refdict, Linked_List reflist, char * type, const char * IdlEntityTypeName( Type t ) { - static char name [BUFSIZ]; - strcpy( name, TYPE_PREFIX ); - if( TYPEget_name( t ) ) { - strcpy( name, FirstToUpper( TYPEget_name( t ) ) ); - } else { - return TYPEget_ctype( t ); - } - return name; -} - -const char * -GetAggrElemType( const Type type ) { - Class_Of_Type class; - Type bt; - static char retval [BUFSIZ]; - - if( isAggregateType( type ) ) { - bt = TYPEget_nonaggregate_base_type( type ); - /* - bt = TYPEget_body(t)->base; - */ - if( isAggregateType( bt ) ) { - strcpy( retval, "ERROR_aggr_of_aggr" ); - } - - class = TYPEget_type( bt ); - - /* case TYPE_INTEGER: */ - if( class == Class_Integer_Type ) { /* return ( "IntAggregate" );*/ - strcpy( retval, "long" ); - } - - /* case TYPE_REAL: - case TYPE_NUMBER: */ - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) - /* return ( "RealAggregate" );*/ - { - strcpy( retval, "double" ); - } - - /* case TYPE_ENTITY: */ - if( class == Class_Entity_Type ) { - strcpy( retval, IdlEntityTypeName( bt ) ); - } - - - /* case TYPE_ENUM: */ - /* case TYPE_SELECT: */ - if( ( class == Class_Enumeration_Type ) - || ( class == Class_Select_Type ) ) { - /* - strcpy (retval, ClassName (TYPEget_name (bt))); - */ - strcpy( retval, TYPEget_ctype( bt ) ); - } - - /* case TYPE_LOGICAL: */ - if( class == Class_Logical_Type ) { - strcpy( retval, "Logical" ); - } - - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - strcpy( retval, "Bool" ); - } - - /* case TYPE_STRING: */ - if( class == Class_String_Type ) { /* return("StringAggregate");*/ - strcpy( retval, "string" ); - } - - /* case TYPE_BINARY: */ - if( class == Class_Binary_Type ) { /* return("BinaryAggregate");*/ - strcpy( retval, "binary" ); - } - } - return retval; } -const char * -TYPEget_idl_type( const Type t ) { - Class_Of_Type class; - static char retval [BUFSIZ]; - - /* aggregates are based on their base type - case TYPE_ARRAY: - case TYPE_BAG: - case TYPE_LIST: - case TYPE_SET: - */ - - if( isAggregateType( t ) ) { - strcpy( retval, GetAggrElemType( t ) ); - - /* ///////////////////////// */ - /* case TYPE_ARRAY: */ - if( TYPEget_type( t ) == Class_Array_Type ) { - strcat( retval, "__array" ); - } - /* case TYPE_LIST: */ - if( TYPEget_type( t ) == Class_List_Type ) { - strcat( retval, "__list" ); - } - /* case TYPE_SET: */ - if( TYPEget_type( t ) == Class_Set_Type ) { - strcat( retval, "__set" ); - } - /* case TYPE_BAG: */ - if( TYPEget_type( t ) == Class_Bag_Type ) { - strcat( retval, "__bag" ); - } - return retval; - - /* //////////////////////// */ - } - - /* the rest is for things that are not aggregates */ - - class = TYPEget_type( t ); - - /* case TYPE_LOGICAL: */ - if( class == Class_Logical_Type ) { - return ( "Logical" ); - } - - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - return ( "Boolean" ); - } - - /* case TYPE_INTEGER: */ - if( class == Class_Integer_Type ) { - return ( "SCLP23(Integer)" ); - } - /* return ("CORBA::Long");*/ - - /* case TYPE_REAL: - case TYPE_NUMBER: */ - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - return ( "SCLP23(Real)" ); - } - /* return ("CORBA::Double"); */ - - /* case TYPE_STRING: */ - if( class == Class_String_Type ) { - return ( "char *" ); - } - - /* case TYPE_BINARY: */ - if( class == Class_Binary_Type ) { - return ( AccessType( t ) ); - } - - /* case TYPE_ENTITY: */ - if( class == Class_Entity_Type ) { - /* better do this because the return type might go away */ - strcpy( retval, IdlEntityTypeName( t ) ); - strcat( retval, "_ptr" ); - return retval; - /* return ("SCLP23(Application_instance_ptr)"); */ - } - /* case TYPE_ENUM: */ - /* case TYPE_SELECT: */ - if( class == Class_Enumeration_Type ) { - strncpy( retval, EnumName( TYPEget_name( t ) ), BUFSIZ - 2 ); - - strcat( retval, " /*" ); - strcat( retval, IdlEntityTypeName( t ) ); - strcat( retval, "*/ " ); - /* strcat (retval, "_var");*/ - return retval; - } - if( class == Class_Select_Type ) { - return ( IdlEntityTypeName( t ) ); - } - - /* default returns undefined */ - return ( "SCLundefined" ); -} int Handle_FedPlus_Args( int i, char * arg ) { if( ( ( char )i == 's' ) || ( ( char )i == 'S' ) ) { @@ -514,1639 +337,150 @@ generate_dict_attr_name( Variable a, char * out ) { } /****************************************************************** - ** Procedure: TYPEget_express_type (const Type t) - ** Parameters: const Type t -- type for attribute - ** Returns: a string which is the type as it would appear in Express - ** Description: supplies the type for error messages - and to register the entity - - calls itself recursively to create a description of - aggregate types - ** Side Effects: - ** Status: new 1/24/91 - ******************************************************************/ - -String -TYPEget_express_type( const Type t ) { - Class_Of_Type class; - Type bt; - char retval [BUFSIZ]; - char * n, * permval, * aggr_type; - - - /* 1. "DEFINED" types */ - /* case TYPE_ENUM: */ - /* case TYPE_ENTITY: */ - /* case TYPE_SELECT: */ - - if( ( n = TYPEget_name( t ) ) ) { - PrettyTmpName( n ); - } - - /* 2. "BASE" types */ - class = TYPEget_type( t ); - - /* case TYPE_LOGICAL: */ - if( ( class == Class_Boolean_Type ) || ( class == Class_Logical_Type ) ) { - return ( "Logical" ); - } - - /* case TYPE_INTEGER: */ - if( class == Class_Integer_Type ) { - return ( "Integer " ); - } - - /* case TYPE_REAL: - case TYPE_NUMBER: */ - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - return ( "Real " ); - } - - /* case TYPE_STRING: */ - if( class == Class_String_Type ) { - return ( "String " ) ; - } - - /* case TYPE_BINARY: */ - if( class == Class_Binary_Type ) { - return ( "Binary " ) ; - } - - /* AGGREGATES - case TYPE_ARRAY: - case TYPE_BAG: - case TYPE_LIST: - case TYPE_SET: - */ - if( isAggregateType( t ) ) { - bt = TYPEget_nonaggregate_base_type( t ); - class = TYPEget_type( bt ); - - /* case TYPE_ARRAY: */ - if( TYPEget_type( t ) == Class_Array_Type ) { - aggr_type = "Array"; - } - /* case TYPE_LIST: */ - if( TYPEget_type( t ) == Class_List_Type ) { - aggr_type = "List"; - } - /* case TYPE_SET: */ - if( TYPEget_type( t ) == Class_Set_Type ) { - aggr_type = "Set"; - } - /* case TYPE_BAG: */ - if( TYPEget_type( t ) == Class_Bag_Type ) { - aggr_type = "Bag"; - } - - sprintf( retval, "%s of %s", - aggr_type, TYPEget_express_type( bt ) ); - - /* this will declare extra memory when aggregate is > 1D */ - - permval = ( char * )malloc( strlen( retval ) * sizeof( char ) + 1 ); - strcpy( permval, retval ); - return permval; - - } - - /* default returns undefined */ - - printf( "WARNING2: type %s is undefined\n", TYPEget_name( t ) ); - return ( "SCLundefined" ); - -} +** Entity Generation */ /****************************************************************** - ** Procedure: ATTRsign_access_method - ** Parameters: const Variable a -- attribute to print - access method signature for - ** FILE* file -- file being written to - ** Returns: nothing - ** Description: prints the signature for an access method - ** based on the attribute type - ** DAS i.e. prints the header for the attr. access functions - ** (get and put attr value) in the entity class def in .h file - ** Side Effects: - ** Status: complete 17-Feb-1992 + ** Procedure: ENTITYhead_print + ** Parameters: const Entity entity + ** FILE* file -- file being written to + ** Returns: + ** Description: prints the beginning of the entity class definition for the + ** c++ code and the declaration of extern attr descriptors for + ** the registry. In the .h file + ** Side Effects: generates c++ code + ** Status: good 1/15/91 + ** added registry things 12-Apr-1993 ******************************************************************/ void -ATTRsign_access_methods( Variable a, FILE * file ) { - - Type t = VARget_type( a ); - Class_Of_Type class; - char ctype [BUFSIZ]; +ENTITYhead_print( Entity entity, FILE * file, Schema schema ) { + char entnm [BUFSIZ]; char attrnm [BUFSIZ]; + Linked_List list; + int attr_count_tmp = attr_count; + Entity super = 0; - generate_attribute_func_name( a, attrnm ); - - /* - generate_attribute_name( a, attrnm ); - strncpy (attrnm, CheckWord (StrToLower (attrnm)), BUFSIZ); - if(old_accessors) - { - attrnm[0] = toupper(attrnm[0]); - } - else - { - attrnm[strlen(attrnm)] = '_'; - } - */ - - class = TYPEget_type( t ); - - if( corba_binding ) { - strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); - } else { - strncpy( ctype, AccessType( t ), BUFSIZ ); - } - if( corba_binding ) { - /* string, entity, and aggregate = no const */ - if( isAggregateType( t ) ) { - fprintf( file, "\t%s * %s(", ctype, attrnm ); - } else { - fprintf( file, "\t%s %s(", ctype, attrnm ); - } - fprintf( file, - "CORBA::Environment &IT_env=CORBA::default_environment) " ); - fprintf( file, - " /* const */ throw (CORBA::SystemException);\n" ); - if( ( class == Class_Enumeration_Type ) || - ( class == Class_Entity_Type ) || - ( class == Class_Boolean_Type ) || - ( class == Class_Logical_Type ) ) { - fprintf( file, "\tvoid %s (%s x", attrnm, ctype ); - } else if( isAggregateType( t ) ) { - fprintf( file, "\tvoid %s (const %s& x", attrnm, ctype ); - } else { - fprintf( file, "\tvoid %s (const %s x", attrnm, ctype ); - } - fprintf( file, - ", CORBA::Environment &IT_env=CORBA::default_environment)" ); - fprintf( file, - " throw (CORBA::SystemException);\n\n" ); - } else { - fprintf( file, "\tconst %s %s() const;\n", ctype, attrnm ); - fprintf( file, "\tvoid %s (const %s x);\n\n", attrnm, ctype ); - } - return; -} + strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); -/****************************************************************** - ** Procedure: ATTRprint_access_methods_get_head - ** Parameters: const Variable a -- attribute to find the type for - ** FILE* file -- file being written - ** Type t - type of the attribute - ** Class_Of_Type class -- type name of the class - ** const char *attrnm -- name of the attribute - ** char *ctype -- (possibly returned) name of the attribute c++ type - ** Returns: name to be used for the type of the c++ access functions - ** Description: prints the access method get head based on the attribute type - ** DAS which being translated is it prints the function header - ** for the get attr value access function defined for an - ** entity class. This is the .cc file version. - ** Side Effects: - ** Status: complete 7/15/93 by DDH - ******************************************************************/ -void -ATTRprint_access_methods_get_head( const char * classnm, Variable a, - FILE * file ) { - Type t = VARget_type( a ); - char ctype [BUFSIZ]; /* return type of the get function */ - char funcnm [BUFSIZ]; /* name of member function */ + /* DAS print all the attr descriptors and inverse attr descriptors for an + entity as extern defs in the .h file. */ + LISTdo( ENTITYget_attributes( entity ), v, Variable ) + generate_attribute_name( v, attrnm ); + fprintf( file, "extern %s *%s%d%s%s;\n", + ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), + ATTR_PREFIX, attr_count_tmp++, + ( VARis_derived( v ) ? "D" : ( VARis_type_shifter( v ) ? "R" : ( VARget_inverse( v ) ? "I" : "" ) ) ), + attrnm ); - generate_attribute_func_name( a, funcnm ); + /* **** testing the functions **** */ /* - generate_attribute_name( a, funcnm ); - funcnm[0] = toupper(funcnm[0]); - */ - - /* ///////////////////////////////////////////////// */ - - if( corba_binding ) { - strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); - } else { - strncpy( ctype, AccessType( t ), BUFSIZ ); - } - if( corba_binding ) { - /* string, entity, and aggregate = no const */ - if( isAggregateType( t ) ) { - fprintf( file, "\n%s * \n%s::%s(", ctype, classnm, funcnm ); - } else { - fprintf( file, "\n%s \n%s::%s(", ctype, classnm, funcnm ); - } - fprintf( file, - "CORBA::Environment &IT_env) " ); - fprintf( file, - " /* const */ throw (CORBA::SystemException)\n" ); - } else { - fprintf( file, "\nconst %s \n%s::%s() const\n", ctype, classnm, funcnm ); - } - return; - /* ///////////////////////////////////////////////// */ -#if 0 - /* case STRING: */ - /* case TYPE_BINARY: */ - /* string can\'t be const because it causes problems with SELECTs */ - if( ( class == Class_String_Type ) || ( class == Class_Binary_Type ) ) { - if( corba_binding ) { - fprintf( file, "\nchar * \n%s::%s(", classnm, funcnm ); - fprintf( file, - "CORBA::Environment &IT_env) const " ); - fprintf( file, - "throw (CORBA::SystemException)\n" ); - } else { - fprintf( file, - "\nconst %s\n%s::%s() const\n", ctype, classnm, funcnm ); - } - return; - } - /* case ENTITY: */ - /* return value isn\'t const */ - if( class == Class_Entity_Type ) { - if( corba_binding ) { - fprintf( file, "\n%s\n%s::%s(", ctype, classnm, funcnm ); - fprintf( file, - "CORBA::Environment &IT_env) /* const */ " ); - fprintf( file, - "throw (CORBA::SystemException)\n" ); - } else { - fprintf( file, "\n%s\n%s::%s() const \n", ctype, classnm, funcnm ); - } - return; - } - - /* case TYPE_LOGICAL: */ - if( class == Class_Logical_Type ) { - if( corba_binding ) { - fprintf( file, "\nconst Logical\n%s::%s(", classnm, funcnm ); - fprintf( file, - "CORBA::Environment &IT_env) const throw (CORBA::SystemException)\n" ); - } else - fprintf( file, - "\nconst Logical \n%s::%s() const\n", classnm, funcnm ); - return; - } - - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - if( corba_binding ) { - fprintf( file, "\nconst Boolean\n%s::%s(", classnm, funcnm ); - fprintf( file, - "CORBA::Environment &IT_env) const throw (CORBA::SystemException)\n" ); - } else - fprintf( file, - "\nconst Boolean\n%s::%s() const\n", classnm, funcnm ); - return; - } - - /* case TYPE_ENUM: */ - if( class == Class_Enumeration_Type ) { - sprintf( ctype, "%s ", EnumName( TYPEget_name( t ) ) ); - } - - - /* default: INTEGER and NUMBER */ - /* case TYPE_AGGRETATES: */ - /* case TYPE_SELECT: */ - /* case TYPE_ENTITY: */ - /* is the same type as the data member */ - fprintf( file, "\nconst %s\n%s::%s(", ctype, classnm, funcnm ); - if( corba_binding ) - fprintf( file, - "CORBA::Environment &IT_env) const throw (CORBA::SystemException)\n" ); - else { - fprintf( file, ") const\n" ); - } -#endif -} - -/****************************************************************** - ** Procedure: ATTRprint_access_methods_put_head - ** Parameters: const Variable a -- attribute to find the type for - ** FILE* file -- file being written to - ** Type t - type of the attribute - ** Class_Of_Type class -- type name of the class - ** const char *attrnm -- name of the attribute - ** char *ctype -- name of the attribute c++ type - ** Returns: name to be used for the type of the c++ access functions - ** Description: prints the access method put head based on the attribute type - ** DAS which being translated is it prints the function header - ** for the put attr value access function defined for an - ** entity class. This is the .cc file version. - ** Side Effects: - ** Status: complete 7/15/93 by DDH - ******************************************************************/ -void -ATTRprint_access_methods_put_head( CONST char * entnm, Variable a, FILE * file ) { - - Type t = VARget_type( a ); - char ctype [BUFSIZ]; - char funcnm [BUFSIZ]; - Class_Of_Type class = TYPEget_type( t ); + if( !(VARis_derived(v) && + VARget_initializer(v) && + VARis_type_shifter(v) && + VARis_overrider(entity, v)) ) + fprintf(file,"// %s Attr is not derived, a type shifter, overrider, no initializer.\n",attrnm); - generate_attribute_func_name( a, funcnm ); - /* - generate_attribute_name( a, funcnm ); - funcnm[0] = toupper(funcnm[0]); + if(VARis_derived (v)) + fprintf(file,"// %s Attr is derived\n",attrnm); + if (VARget_initializer (v)) + fprintf(file,"// %s Attr has an initializer\n",attrnm); + if(VARis_type_shifter (v)) + fprintf(file,"// %s Attr is a type shifter\n",attrnm); + if(VARis_overrider (entity, v)) + fprintf(file,"// %s Attr is an overrider\n",attrnm); */ + /* ****** */ - /* ///////////////////////////////////////////////// */ - - if( corba_binding ) { - strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); - } else { - strncpy( ctype, AccessType( t ), BUFSIZ ); - } - if( corba_binding ) { - /* string, entity, and aggregate = no const */ - if( ( class == Class_Enumeration_Type ) || - ( class == Class_Entity_Type ) || - ( class == Class_Boolean_Type ) || - ( class == Class_Logical_Type ) ) { - fprintf( file, "\nvoid \n%s::%s (%s x", entnm, funcnm, ctype ); - } else if( isAggregateType( t ) ) { - fprintf( file, "\nvoid \n%s::%s (const %s& x", entnm, funcnm, ctype ); - } else { - fprintf( file, "\nvoid \n%s::%s (const %s x", entnm, funcnm, ctype ); - } - fprintf( file, - ", CORBA::Environment &IT_env)" ); - fprintf( file, - " throw (CORBA::SystemException)\n\n" ); - } else { - fprintf( file, "\nvoid \n%s::%s (const %s x)\n\n", entnm, funcnm, ctype ); - } - return; - /* ///////////////////////////////////////////////// */ -#if 0 + LISTod - /* case TYPE_LOGICAL: */ - if( class == Class_Logical_Type ) { - strcpy( ctype, "Logical" ); - } + fprintf( file, "\nclass %s : ", entnm ); - /* case TYPE_BOOLEAN: */ - if( class == Class_Boolean_Type ) { - strcpy( ctype, "Boolean" ); - } + /* inherit from either supertype entity class or root class of + all - i.e. SCLP23(Application_instance) */ - /* case TYPE_ENUM: */ - if( class == Class_Enumeration_Type ) { - strncpy( ctype, EnumName( TYPEget_name( t ) ), BUFSIZ ); + if( multiple_inheritance ) { + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + super = ( Entity )LISTpeek_first( list ); + } + } else { /* the old way */ + super = ENTITYput_superclass( entity ); } - - /* case STRING:*/ - if( class == Class_String_Type ) { - strcpy( ctype, "const char *" ); + if( super ) { + fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); + } else { + fprintf( file, " public SCLP23(Application_instance) {\n" ); } - /* case TYPE_BINARY: */ - if( class == Class_Binary_Type ) { - sprintf( ctype, "const %s&", AccessType( t ) ); - } +#if 0 + /* this code is old non-working multiple inheritance code */ - /* default: INTEGER and NUMBER */ - /* case TYPE_AGGRETATES: */ - /* case TYPE_ENTITY: */ - /* case TYPE_SELECT: */ - /* is the same type as the data member */ - fprintf( file, "\nvoid \n%s::%s (%s x", entnm, funcnm, ctype ); - if( corba_binding ) { - fprintf( file, ", CORBA::Environment &IT_env) \nthrow (CORBA::SystemException" ); - } - fprintf( file, ")\n" ); - -#endif - -} - -void -AGGRprint_access_methods( CONST char * entnm, Variable a, FILE * file, Type t, - char * ctype, char * attrnm ) { - char aggrnode_name [BUFSIZ]; - Type bt; - Class_Of_Type class = TYPEget_type( t ); - char nm [BUFSIZ]; - - ATTRprint_access_methods_get_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( !corba_binding ) { - fprintf( file, " return (%s) &_%s; \n}\n", ctype, attrnm ); - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "\t{ _%s.ShallowCopy (*x); }\n", attrnm ); - return; - } else { - bt = TYPEget_nonaggregate_base_type( t ); - if( isAggregateType( bt ) ) { - strcpy( aggrnode_name, "/* ERROR aggr_of_aggr */" ); - } - - fprintf( file, " %s * seq = new %s;\n\n", ctype, ctype ); - /* Part_version__set * seq = new Part_version__set;*/ - - fprintf( file, " int count = _%s.EntryCount();\n", attrnm ); - fprintf( file, " seq->length(count);\n\n" ); - - fprintf( file, " int i = 0;\n" ); - fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n\n", attrnm ); - - - class = TYPEget_type( bt ); - - if( class == Class_Integer_Type ) { - /* strcpy(aggrnode_name,"IntNode"); */ - fprintf( file, " while(n)\n" ); - fprintf( file, " {\n" ); - - fprintf( file, "\t(*seq)[i] = ((IntNode*)n)->value;\n" ); - fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr integer element: \" << ((IntNode*)n)->value << std::endl;\n", entnm, attrnm ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr integer element: \" << ((IntNode*)n)->value << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, " return seq;\n" ); - fprintf( file, "}\n" ); - } - - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - /* strcpy(aggrnode_name,"RealNode"); */ - fprintf( file, " while(n)\n" ); - fprintf( file, " {\n" ); - - fprintf( file, "\t(*seq)[i] = ((RealNode*)n)->value;\n" ); - fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr real element: \" << ((RealNode*)n)->value << std::endl;\n", entnm, attrnm ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - - fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr real element: \" << ((RealNode*)n)->value << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, " return seq;\n" ); - fprintf( file, "}\n" ); - } - - if( class == Class_Entity_Type ) { - /* strcpy(aggrnode_name,"EntityNode");*/ - fprintf( file, " int file_id = 0;\n" ); - fprintf( file, " char markerServer[BUFSIZ];\n" ); - fprintf( file, " while(n)\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tfile_id = ((EntityNode*)n)->node->STEPfile_id;\n" ); - fprintf( file, "\tstd::cout << \"StepFileId: \" << file_id;\n" ); - - fprintf( file, "\t// the marker:server is used\n" ); - fprintf( file, "\tsprintf(markerServer, \"%%d:%%s\", file_id, serverName);\n" ); - fprintf( file, "\tstd::cout << \" markerServer: \" << markerServer << std::endl;\n" ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr entity element w/file_id: \" << file_id << \" markerServer: \" << markerServer << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - if( TYPEget_name( bt ) ) { - strncpy( nm, FirstToUpper( TYPEget_name( bt ) ), BUFSIZ - 1 ); - } - fprintf( file, "\t(*seq)[i] = %s::_bind(markerServer, sclHostName);\n", nm ); - fprintf( file, - "/*\n\t%s_var x = %s::_bind((const char *)markerServer," - "sclHostName);\n", nm, nm ); - fprintf( file, - "\t%s::_duplicate(x);\n\n", nm ); - fprintf( file, "\t(*seq)[i] = x;\n*/\n" ); - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, " return seq;\n" ); - fprintf( file, "}\n" ); - /* ////////////////////////////////////////////////// */ - } - - if( ( class == Class_Enumeration_Type ) || - ( class == Class_Logical_Type ) || - ( class == Class_Boolean_Type ) ) { - /* strcpy(aggrnode_name,"EnumNode"); */ - fprintf( file, " while(n)\n" ); - fprintf( file, " {\n" ); - - fprintf( file, "\t(*seq)[i] = ((EnumNode*)n)->node->asInt();\n" ); - fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr enumeration/Boolean/Logical element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() ) << std::endl;\n", entnm, attrnm ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr enumeration/Boolean/Logical element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() ) << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, " return seq;\n" ); - fprintf( file, "}\n" ); - } - - if( class == Class_Select_Type ) { - strcpy( aggrnode_name, "SelectNode" ); - fprintf( file, " std::cout << \"ERROR function not implemented: entity %s, attr _%s: aggr select element: \" << std::endl;\n", entnm, attrnm ); - fprintf( file, " return 0;\n" ); - fprintf( file, "}\n" ); - } - - if( class == Class_String_Type ) { /* return("StringAggregate");*/ - /* strcpy(aggrnode_name,"StringNode");*/ - fprintf( file, " while(n)\n" ); - fprintf( file, " {\n" ); - - fprintf( file, "\t(*seq)[i] = CORBA::string_dupl( ((StringNode*)n)->value.c_str() );\n" ); - fprintf( file, "\tstd::cout << \"returning entity %s, attr _%s: aggr string element: \" << ((StringNode*)n)->value.c_str() << std::endl;\n", entnm, attrnm ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI returning entity: %s, attr: _%s, aggr string element: \" << ((StringNode*)n)->value.c_str() << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, " return seq;\n" ); - fprintf( file, "}\n" ); - } - if( class == Class_Binary_Type ) { /* return("BinaryAggregate");*/ - strcpy( aggrnode_name, "BinaryNode" ); - fprintf( file, " std::cout << \"ERROR function not implemented: entity %s, attr _%s: aggr binary element: \" << std::endl;\n", entnm, attrnm ); - fprintf( file, " return 0;\n" ); - fprintf( file, "}\n" ); - } - /* ////////////////////////////////////// */ - ATTRprint_access_methods_put_head( entnm, a, file ); - - bt = TYPEget_nonaggregate_base_type( t ); - if( isAggregateType( bt ) ) { - strcpy( aggrnode_name, "/* ERROR aggr_of_aggr */" ); - } - - class = TYPEget_type( bt ); - - if( class == Class_Integer_Type ) { - /* ************************************** */ - if( TYPEget_name( bt ) ) { - strcpy( nm, "Sdai" ); - strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); - } - - fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); - fprintf( file, "{\n" ); - fprintf( file, " int countx = x.length();\n" ); - fprintf( file, " SingleLinkNode *trailn = 0;\n" ); - fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); - fprintf( file, " if( countx == 0 )\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\t_%s.Empty();\n", attrnm ); - fprintf( file, "\treturn;\n" ); - fprintf( file, " }\n\n" ); - fprintf( file, " int i = 0;\n" ); - fprintf( file, " while(i < countx)\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tif(n == 0)\n" ); - fprintf( file, "\t{\n" ); - fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); - fprintf( file, "\t _%s.AppendNode( (IntNode*)n );\n", attrnm ); - fprintf( file, "\t}\n" ); - fprintf( file, "\t((IntNode*)n)->value = x[i];\n"); - fprintf( file, "\tstd::cout << \"Assigning aggr int element: \" << ((IntNode*)n)->value;\n" ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr integer element: \" << ((IntNode*)n)->value << std::endl;\n", entnm, attrnm ); - - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\ttrailn = n;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "/*\n" ); - fprintf( file, " if(n)\n" ); - fprintf( file, "\t_%s.DeleteFollowingNodes((IntNode*)trailn);\n", attrnm ); - fprintf( file, "*/\n" ); - fprintf( file, "}\n" ); - /* ************************************** */ - } - - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - /* ************************************** */ - if( TYPEget_name( bt ) ) { - strcpy( nm, "Sdai" ); - strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); - } - - fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); - fprintf( file, "{\n" ); - fprintf( file, " int countx = x.length();\n" ); - fprintf( file, " SingleLinkNode *trailn = 0;\n" ); - fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); - fprintf( file, " if( countx == 0 )\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\t_%s.Empty();\n", attrnm ); - fprintf( file, "\treturn;\n" ); - fprintf( file, " }\n\n" ); - fprintf( file, " int i = 0;\n" ); - fprintf( file, " while(i < countx)\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tif(n == 0)\n" ); - fprintf( file, "\t{\n" ); - fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); - fprintf( file, "\t _%s.AppendNode( (RealNode*)n );\n", attrnm ); - fprintf( file, "\t}\n" ); - fprintf( file, "\t((RealNode*)n)->value = x[i];\n"); - fprintf( file, "\tstd::cout << \"Assigning aggr real element: \" << ((RealNode*)n)->value;\n" ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr real element: \" << ((RealNode*)n)->value << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - fprintf( file, "\ti++;\n" ); - fprintf( file, "\ttrailn = n;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "/*\n" ); - fprintf( file, " if(n)\n" ); - fprintf( file, "\t_%s.DeleteFollowingNodes((RealNode*)trailn);\n", attrnm ); - fprintf( file, "*/\n" ); - fprintf( file, "}\n" ); - /* ************************************** */ - } - - if( class == Class_Entity_Type ) { - /* strcpy(nm, TYPEget_name(bt)); - strcpy(nm, TYPEget_name - (TYPEget_nonaggregate_base_type (VARget_type (a)))); - */ - /* ************************************** */ - if( TYPEget_name( bt ) ) { - strcpy( nm, "Sdai" ); - strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); - } - - fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); - fprintf( file, "{\n" ); - fprintf( file, " int countx = x.length();\n" ); - fprintf( file, " SingleLinkNode *trailn = 0;\n" ); - fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); - fprintf( file, " if( countx > 0 )\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tif( n == 0 )\n" ); - fprintf( file, "\t{\n" ); - fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); - fprintf( file, "\t _%s.AppendNode( (EntityNode*)n );\n", attrnm ); - fprintf( file, "\t}\n" ); - fprintf( file, " }\n" ); - fprintf( file, " else\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\t_%s.Empty();\n", attrnm ); - fprintf( file, "\treturn;\n" ); - fprintf( file, " }\n\n" ); - fprintf( file, " int i = 0;\n" ); - fprintf( file, " while(i < countx)\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tif(n == 0)\n" ); - fprintf( file, "\t{\n" ); - fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); - fprintf( file, "\t _%s.AppendNode( (EntityNode*)n );\n", attrnm ); - fprintf( file, "\t}\n" ); - fprintf( file, "\t((EntityNode*)n)->node = (%s*)DEREF( x[i] );\n", nm ); - fprintf( file, "\tstd::cout << \"Assigning entity w/StepFileId: \" << ((EntityNode*)n)->node->STEPfile_id;\n" ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr entity element w/file_id: \" << ((EntityNode*)n)->node->STEPfile_id << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - - fprintf( file, "\ti++;\n" ); - fprintf( file, "\ttrailn = n;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "/*\n" ); - fprintf( file, " if(n)\n" ); - fprintf( file, "\t_%s.DeleteFollowingNodes((EntityNode*)trailn);\n", attrnm ); - fprintf( file, "*/\n" ); - fprintf( file, "}\n" ); - /* ************************************** */ - - } - - if( ( class == Class_Enumeration_Type ) || - ( class == Class_Logical_Type ) || - ( class == Class_Boolean_Type ) ) { - /* ************************************** */ - if( TYPEget_name( bt ) ) { - strcpy( nm, "Sdai" ); - strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); - } - - fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); - fprintf( file, "{\n" ); - fprintf( file, " int countx = x.length();\n" ); - fprintf( file, " SingleLinkNode *trailn = 0;\n" ); - fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); - fprintf( file, " if( countx == 0 )\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\t_%s.Empty();\n", attrnm ); - fprintf( file, "\treturn;\n" ); - fprintf( file, " }\n\n" ); - fprintf( file, " int i = 0;\n" ); - fprintf( file, " while(i < countx)\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tif(n == 0)\n" ); - fprintf( file, "\t{\n" ); - fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); - fprintf( file, "\t _%s.AppendNode( (EnumNode*)n );\n", attrnm ); - fprintf( file, "\t}\n" ); - fprintf( file, "\t((EnumNode*)n)->node->put( (int)x[i] );\n"); - fprintf( file, "\tstd::cout << \"Assigning aggr enum element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() );\n" ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr enumeration/Boolean/Logical element: \" << ((EnumNode*)n)->node->element_at( ((EnumNode*)n)->node->asInt() ) << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - fprintf( file, "\ti++;\n" ); - fprintf( file, "\ttrailn = n;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "/*\n" ); - fprintf( file, " if(n)\n" ); - fprintf( file, "\t_%s.DeleteFollowingNodes((EnumNode*)trailn);\n", attrnm ); - fprintf( file, "*/\n" ); - fprintf( file, "}\n" ); - /* ************************************** */ - } - - if( class == Class_Select_Type ) { - fprintf( file, "\t{ /*_%s.ShallowCopy (*x); */ }\n", attrnm ); - strcpy( aggrnode_name, "SelectNode" ); - } - - if( class == Class_String_Type ) { /* return("StringAggregate");*/ - /* ************************************** */ - if( TYPEget_name( bt ) ) { - strcpy( nm, "Sdai" ); - strcat( nm, FirstToUpper( TYPEget_name( bt ) ) ); - } - - fprintf( file, "\t/* { _%s.ShallowCopy (*x); } */\n", attrnm ); - fprintf( file, "{\n" ); - fprintf( file, " int countx = x.length();\n" ); - fprintf( file, " SingleLinkNode *trailn = 0;\n" ); - fprintf( file, " SingleLinkNode *n = _%s.GetHead();\n", attrnm ); - fprintf( file, " if( countx == 0 )\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\t_%s.Empty();\n", attrnm ); - fprintf( file, "\treturn;\n" ); - fprintf( file, " }\n\n" ); - fprintf( file, " int i = 0;\n" ); - fprintf( file, " while(i < countx)\n" ); - fprintf( file, " {\n" ); - fprintf( file, "\tif(n == 0)\n" ); - fprintf( file, "\t{\n" ); - fprintf( file, "\t n = _%s.NewNode();\n", attrnm ); - fprintf( file, "\t _%s.AppendNode( (StringNode*)n );\n", attrnm ); - fprintf( file, "\t}\n" ); - fprintf( file, "\t((StringNode*)n)->value = x[i];\n"); - fprintf( file, "\tstd::cout << \"Assigning aggr string element: \" << ((StringNode*)n)->value.c_str();\n" ); - /* /////////////////////////////////////////// */ - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, "\tif(*logStream)\n\t{\n" ); - fprintf( file, - "\t logStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI assigning entity: %s, attr: _%s, aggr string element: \" << ((StringNode*)n)->value.c_str() << std::endl;\n", entnm, attrnm ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, "\t}\n" ); - fprintf( file, "#endif\n" ); - } - /* /////////////////////////////////////////// */ - fprintf( file, "\ti++;\n" ); - fprintf( file, "\ttrailn = n;\n" ); - fprintf( file, "\tn = n->NextNode();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "/*\n" ); - fprintf( file, " if(n)\n" ); - fprintf( file, "\t_%s.DeleteFollowingNodes((EnumNode*)trailn);\n", attrnm ); - fprintf( file, "*/\n" ); - fprintf( file, "}\n" ); - /* ************************************** */ - } - if( class == Class_Binary_Type ) { /* return("BinaryAggregate");*/ - fprintf( file, "\t{ /*_%s.ShallowCopy (*x); */ }\n", attrnm ); - strcpy( aggrnode_name, "BinaryNode" ); - } - /* x-> x-> */ - /* ////////////////////////// */ - } - return; -} - -/****************************************************************** - ** Procedure: ATTRprint_access_method - ** Parameters: const Variable a -- attribute to find the type for - ** FILE* file -- file being written to - ** Returns: name to be used for the type of the c++ access functions - ** Description: prints the access method based on the attribute type - ** i.e. get and put value access functions defined in a class - ** generated for an entity. - ** Side Effects: - ** Status: complete 1/15/91 - ** updated 17-Feb-1992 to print to library file instead of header - ** updated 15-July-1993 to call the get/put head functions by DDH - ******************************************************************/ -void -ATTRprint_access_methods( CONST char * entnm, Variable a, FILE * file ) { - Type t = VARget_type( a ); - Class_Of_Type class; - char ctype [BUFSIZ]; /* type of data member */ - char attrnm [BUFSIZ]; - char membernm[BUFSIZ]; - char funcnm [BUFSIZ]; /* name of member function */ - - char nm [BUFSIZ]; - /* I believe nm has the name of the underlying type without Sdai in - front of it */ - if( TYPEget_name( t ) ) { - strncpy( nm, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - 1 ); - } - - generate_attribute_func_name( a, funcnm ); - /* - generate_attribute_name( a, funcnm ); - funcnm[0] = toupper(funcnm[0]); - */ - - generate_attribute_name( a, attrnm ); - strcpy( membernm, attrnm ); - membernm[0] = toupper( membernm[0] ); - class = TYPEget_type( t ); - /* strncpy (ctype, TYPEget_ctype (t), BUFSIZ);*/ - if( corba_binding ) { - strncpy( ctype, TYPEget_idl_type( t ), BUFSIZ ); - } else { - strncpy( ctype, AccessType( t ), BUFSIZ ); - } - - if( isAggregate( a ) ) { - AGGRprint_access_methods( entnm, a, file, t, ctype, attrnm ); - return; - } - ATTRprint_access_methods_get_head( entnm, a, file ); - - /* case TYPE_ENTITY: */ - if( class == Class_Entity_Type ) { - - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tlogStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\tif(! (_%s == S_ENTITY_NULL) )\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"reference to Sdai%s entity #\" << _%s->STEPfile_id << std::endl;\n", - nm, attrnm ); - /* funcnm, attrnm);*/ - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"null entity\" << std::endl;\n\t}\n" ); - fprintf( file, "\tlogStream->close();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "#endif\n" ); - /* fprintf (file, " return (%s) _%s;\n}\n", ctype, attrnm); */ - } - if( corba_binding ) { - if( TYPEget_name( t ) ) { - strncpy( nm, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - 1 ); - } - - /* fprintf (file, "{\n if(_%s != 0)\n {\n", attrnm); */ - fprintf( file, " if(_%s != 0)\n {\n", attrnm ); - fprintf( file, "\ttry\n\t{\n" ); - fprintf( file, - "\t const char *hostName = CORBA::Orbix.myHost();\n" ); - fprintf( file, - "\t char markerServer[64];\n" ); - fprintf( file, - "\t sprintf(markerServer, \"%%d:%%s\", _%s->" - "STEPfile_id, serverName);\n\n", attrnm ); - fprintf( file, - "\t std::cout << \"*****\" << markerServer << std::endl;\n\n" ); - fprintf( file, - "\t %s_var x = %s::_bind((const char *)markerServer," - "hostName);\n", nm, nm ); - fprintf( file, - "\t %s::_duplicate(x);\n\n", nm ); - fprintf( file, - "\t std::cout << std::endl << \"x->_refCount(): \" << x->" - "_refCount();\n" ); - fprintf( file, - "\t std::cout << std::endl << \"STEPfile id inside _%s's get " - "function is: \" \n", attrnm ); - fprintf( file, - "\t\t << _%s->STEPfile_id << std::endl;\n", attrnm ); - fprintf( file, - "\t std::cout << \"x's marker name in server's " - "implementation object's attr _%s's get function is: " - "'\" \n", attrnm ); - fprintf( file, - "\t\t << x->_marker() << \"'\" << std::endl << std::endl;\n" ); - fprintf( file, "\t return x;\n\t}\n" ); - fprintf( file, - "\tcatch (CORBA::SystemException &se) {\n" ); - fprintf( file, - "\t std::cerr << \"Unexpected system exception in _%s's " - "get funct: \" << &se;\n", attrnm ); - fprintf( file, - "\t throw;\n" ); - fprintf( file, - "\t}\n\tcatch(...) {\n" ); - fprintf( file, - "\t std::cerr << \"Caught Unknown Exception in _%s's get " - "funct!\" << std::endl;\n", attrnm ); - fprintf( file, - "\t throw;\n\t}\n" ); - - /* - fprintf (file, "\t%s_ptr x = new TIE_%s(Sdai%s) ((Sdai%s*)_%s);\n", - nm, nm, nm, nm, attrnm); - fprintf (file, "\t%s::_duplicate(x);\n", nm); - fprintf (file, "\tstd::cout << \"STEPfile id is: \" << _%s->STEPfile_id << std::endl;\n", attrnm); - */ - fprintf( file, " }\n" ); - fprintf( file, " else\n" ); - fprintf( file, "\tstd::cout << \"nil object ref in attr _%s's put " - "funct\" << std::endl;\n", attrnm ); - fprintf( file, " return %s::_nil();\n}\n", nm ); - } else - /* fprintf (file, "\t{ return (%s) _%s; }\n", ctype, attrnm);*/ - { - fprintf( file, " return (%s) _%s; \n}\n", ctype, attrnm ); - } - - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "\n" ); - /* fprintf (file, "{\n"); */ - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tlogStream->open(SCLLOGFILE,ios::app);\n" ); - - if( corba_binding ) { - fprintf( file, "\tif(x && !((Sdai%s*)(DEREF(x)) == S_ENTITY_NULL) )\n\t{\n", nm ); - } else { - fprintf( file, "\tif(! (x == S_ENTITY_NULL) )\n\t{\n" ); - } - - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", - entnm, funcnm ); - - if( corba_binding ) - fprintf( file, - "\t *logStream << \"reference to Sdai%s entity #\" << ((Sdai%s*)(DEREF(x)))->STEPfile_id << std::endl;\n", - nm, nm ); - else - fprintf( file, - "\t *logStream << \"reference to Sdai%s entity #\" << x->STEPfile_id << std::endl;\n", - nm ); - - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"null entity\" << std::endl;\n\t}\n" ); - fprintf( file, "\tlogStream->close();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "#endif\n" ); - /* fprintf (file, " _%s = x; \n}\n", attrnm ); */ - } - if( corba_binding ) { - fprintf( file, "\n" ); - fprintf( file, " _%s = (Sdai%s*)(DEREF(x)); \n", attrnm, nm ); - fprintf( file, " if(_%s)\n {\n", attrnm ); - fprintf( file, "\tstd::cout << \"STEPfile id inside _%s's put function is: \"\n", attrnm ); - fprintf( file, "\t << _%s->STEPfile_id << std::endl;\n", attrnm ); - fprintf( file, " }\n else\n" ); - fprintf( file, "\tstd::cout << \"nil object ref in _%s's put funct\" << std::endl;\n", attrnm ); - fprintf( file, "}\n" ); - } else { - fprintf( file, " _%s = x; \n}\n", attrnm ); - } - /* fprintf (file, "\t{ _%s = x; }\n", attrnm ); */ - - return; - } - /* case TYPE_LOGICAL: */ - if( ( class == Class_Boolean_Type ) || ( class == Class_Logical_Type ) ) { - - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tlogStream->open(SCLLOGFILE,ios::app);\n" ); - fprintf( file, "\tif(!_%s.is_null())\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << _%s.element_at(_%s.asInt()) << std::endl;\n", - attrnm, attrnm ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n" ); - fprintf( file, "\t logStream->close();\n" ); - fprintf( file, " }\n" ); - fprintf( file, "#endif\n" ); - /* fprintf (file, "\t{ return (const PSDAI::LOGICAL&) _%s; }\n", attrnm);*/ - } - if( corba_binding ) { - if( class == Class_Boolean_Type ) { - fprintf( file, " return (Boolean) _%s;\n}\n", attrnm ); - } else if( class == Class_Logical_Type ) { - fprintf( file, " return (Logical) _%s;\n}\n", attrnm ); - } - } else { - fprintf( file, " return (%s) _%s;\n}\n", ctype, attrnm ); - } - - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\t*logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t*logStream << _%s.element_at(x) << std::endl;\n", attrnm ); - fprintf( file, " }\n" ); - fprintf( file, "#endif\n" ); - - /* fprintf (file, "\t{ return (const PSDAI::LOGICAL&) _%s; }\n", attrnm);*/ - /* fprintf (file, " _%s.put (x); \n}\n", attrnm ); */ - } - fprintf( file, " _%s.put (x); \n}\n", attrnm ); - return; - } - /* case TYPE_ENUM: */ - if( class == Class_Enumeration_Type ) { - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!_%s.is_null())\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << _%s.element_at(_%s.asInt()) << std::endl;\n", - attrnm, attrnm ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - /* fprintf (file, "\t{ return (const %s&) _%s; }\n", ctype, attrnm);*/ - /* fprintf (file, " return (%s) _%s; \n}\n", */ - /* EnumName (TYPEget_name (t)), attrnm); */ - } - fprintf( file, " return (%s) _%s; \n}\n", - EnumName( TYPEget_name( t ) ), attrnm ); - - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\t*logStream << time(NULL) << \" SDAI %s::%s() assigned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t*logStream << _%s.element_at(x) << std::endl;\n", attrnm ); - fprintf( file, " }\n" ); - fprintf( file, "#endif\n" ); - - /* fprintf (file, "\t{ return (const PSDAI::LOGICAL&) _%s; }\n", attrnm);*/ - /* fprintf (file, " _%s.put (x); \n}\n", attrnm ); */ - } - fprintf( file, " _%s.put (x); \n}\n", attrnm ); - return; - } - /* case TYPE_SELECT: */ - if( class == Class_Select_Type ) { - fprintf( file, "\t{ return (const %s) &_%s; }\n", ctype, attrnm ); - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "\t{ _%s = x; }\n", attrnm ); - return; - } - /* case TYPE_AGGRETATES: */ - /* handled in AGGRprint_access_methods(entnm, a, file, t, ctype, attrnm) */ - - - /* case STRING:*/ - /* case TYPE_BINARY: */ - if( ( class == Class_String_Type ) || ( class == Class_Binary_Type ) ) { - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!_%s.is_null())\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << _%s.c_str() << std::endl;\n", attrnm ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - - /* fprintf (file, "\t{ return (%s) _%s; }\n", ctype, attrnm);*/ - /* fprintf (file, " return (const %s) _%s; \n}\n", ctype, attrnm); */ - /*DASSTR fprintf (file, "\t{ return (const %s&) _%s; }\n", ctype, attrnm);*/ - } - if( corba_binding ) { - fprintf( file, " return CORBA::string_dupl(_%s); \n}\n", attrnm ); - } else { - fprintf( file, " return (const %s) _%s; \n}\n", ctype, attrnm ); - } - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!x)\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << x << std::endl;\n" ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - - /* fprintf (file, " _%s = x; \n}\n", attrnm ); */ - } - fprintf( file, " _%s = x; \n}\n", attrnm ); - return; - } - /* case TYPE_INTEGER: */ - if( class == Class_Integer_Type ) { - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!(_%s == S_INT_NULL) )\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << _%s << std::endl;\n", attrnm ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - } - /* default: INTEGER */ - /* is the same type as the data member */ - fprintf( file, " return (const %s) _%s; \n}\n", ctype, attrnm ); - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!(x == S_INT_NULL) )\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << x << std::endl;\n" ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - /* default: INTEGER */ - /* is the same type as the data member */ - } - fprintf( file, " _%s = x; \n}\n", attrnm ); - } - - /* case TYPE_REAL: - case TYPE_NUMBER: */ - if( ( class == Class_Number_Type ) || ( class == Class_Real_Type ) ) { - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!(_%s == S_REAL_NULL) )\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << _%s << std::endl;\n", attrnm ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - } - fprintf( file, " return (const %s) _%s; \n}\n", ctype, attrnm ); - ATTRprint_access_methods_put_head( entnm, a, file ); - fprintf( file, "{\n" ); - if( print_logging ) { - fprintf( file, "#ifdef SCL_LOGGING\n" ); - fprintf( file, " if(*logStream)\n {\n" ); - fprintf( file, "\tif(!(_%s == S_REAL_NULL) )\n\t{\n", attrnm ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << _%s << std::endl;\n", attrnm ); - fprintf( file, "\t}\n\telse\n\t{\n" ); - fprintf( file, "\t *logStream << time(NULL) << \" SDAI %s::%s() returned: \";\n", - entnm, funcnm ); - fprintf( file, - "\t *logStream << \"unset\" << std::endl;\n\t}\n }\n" ); - fprintf( file, "#endif\n" ); - } - fprintf( file, " _%s = x; \n}\n", attrnm ); - } -} - -/****************************************************************** -** Entity Generation */ - -/****************************************************************** - ** Procedure: ENTITYhead_print - ** Parameters: const Entity entity - ** FILE* file -- file being written to - ** Returns: - ** Description: prints the beginning of the entity class definition for the - ** c++ code and the declaration of extern attr descriptors for - ** the registry. In the .h file - ** Side Effects: generates c++ code - ** Status: good 1/15/91 - ** added registry things 12-Apr-1993 - ******************************************************************/ - -void -ENTITYhead_print( Entity entity, FILE * file, Schema schema ) { - char entnm [BUFSIZ]; - char attrnm [BUFSIZ]; - Linked_List list; - int attr_count_tmp = attr_count; - Entity super = 0; - - strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); - - /* DAS print all the attr descriptors and inverse attr descriptors for an - entity as extern defs in the .h file. */ - LISTdo( ENTITYget_attributes( entity ), v, Variable ) - generate_attribute_name( v, attrnm ); - fprintf( file, "extern %s *%s%d%s%s;\n", - ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), - ATTR_PREFIX, attr_count_tmp++, - ( VARis_derived( v ) ? "D" : ( VARis_type_shifter( v ) ? "R" : ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm ); - - /* **** testing the functions **** */ - /* - if( !(VARis_derived(v) && - VARget_initializer(v) && - VARis_type_shifter(v) && - VARis_overrider(entity, v)) ) - fprintf(file,"// %s Attr is not derived, a type shifter, overrider, no initializer.\n",attrnm); - - if(VARis_derived (v)) - fprintf(file,"// %s Attr is derived\n",attrnm); - if (VARget_initializer (v)) - fprintf(file,"// %s Attr has an initializer\n",attrnm); - if(VARis_type_shifter (v)) - fprintf(file,"// %s Attr is a type shifter\n",attrnm); - if(VARis_overrider (entity, v)) - fprintf(file,"// %s Attr is an overrider\n",attrnm); - */ - /* ****** */ - - LISTod - - fprintf( file, "\nclass %s : ", entnm ); - - /* inherit from either supertype entity class or root class of - all - i.e. SCLP23(Application_instance) */ - - if( multiple_inheritance ) { - list = ENTITYget_supertypes( entity ); - if( ! LISTempty( list ) ) { - super = ( Entity )LISTpeek_first( list ); - } - } else { /* the old way */ - super = ENTITYput_superclass( entity ); - } - - if( super ) { - fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); - } else { - fprintf( file, " public SCLP23(Application_instance) {\n" ); - } - -#if 0 - /* this code is old non-working multiple inheritance code */ - - list = ENTITYget_supertypes( entity ); - if( ! LISTempty( list ) ) { - LISTdo( list, e, Entity ) - /* if there\'s no super class yet, - or the super class doesn\'t have any attributes - */ - if( ( ! super ) || ( ! ENTITYhas_explicit_attributes( super ) ) ) { - super = e; - ++ super_cnt; - } else { - printf( "WARNING: multiple inheritance not implemented.\n" ); - printf( "\tin ENTITY %s\n\tSUPERTYPE %s IGNORED.\n\n", - ENTITYget_name( entity ), ENTITYget_name( e ) ); - } - LISTod; - fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); + list = ENTITYget_supertypes( entity ); + if( ! LISTempty( list ) ) { + LISTdo( list, e, Entity ) + /* if there\'s no super class yet, + or the super class doesn\'t have any attributes + */ + if( ( ! super ) || ( ! ENTITYhas_explicit_attributes( super ) ) ) { + super = e; + ++ super_cnt; + } else { + printf( "WARNING: multiple inheritance not implemented.\n" ); + printf( "\tin ENTITY %s\n\tSUPERTYPE %s IGNORED.\n\n", + ENTITYget_name( entity ), ENTITYget_name( e ) ); + } + LISTod; + fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); /* for multiple inheritance LISTdo (list, e, Entity) - sprintf (buf, " public %s, ", ENTITYget_classname (e)); - move (buf); - LISTod; - sprintf (buf - 2, " {\n"); - move (buf); - fprintf(file,buffer); - */ - } else { /* if entity has no supertypes, it's at top of hierarchy */ - fprintf( file, " public SCLP23(Application_instance) {\n" ); - } -#endif - -} - -/****************************************************************** - ** Procedure: DataMemberPrint - ** Parameters: const Entity entity -- entity being processed - ** FILE* file -- file being written to - ** Returns: - ** Description: prints out the data members for an entity's c++ class - ** definition - ** Side Effects: generates c++ code - ** Status: ok 1/15/91 - ******************************************************************/ - -void -DataMemberPrint( Entity entity, FILE * file, Schema schema ) { - Linked_List attr_list; - char entnm [BUFSIZ]; - char attrnm [BUFSIZ]; - - const char * ctype, * etype; - - strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm */ - - /* print list of attributes in the protected access area */ - - fprintf( file, " protected:\n" ); - - attr_list = ENTITYget_attributes( entity ); - LISTdo( attr_list, a, Variable ) - if( VARget_initializer( a ) == EXPRESSION_NULL ) { - ctype = TYPEget_ctype( VARget_type( a ) ); - generate_attribute_name( a, attrnm ); - if( !strcmp( ctype, "SCLundefined" ) ) { - printf( "WARNING: in entity %s:\n", ENTITYget_name( entity ) ); - printf( "\tthe type for attribute %s is not fully implemented\n", attrnm ); - } - if( TYPEis_entity( VARget_type( a ) ) ) { - fprintf( file, "\tSCLP23(Application_instance_ptr) _%s ;", attrnm ); - } else { - fprintf( file, "\t%s _%s ;", ctype, attrnm ); - } - if( VARget_optional( a ) ) { - fprintf( file, " // OPTIONAL" ); - } - if( isAggregate( a ) ) { - /* if it's a named type, comment the type */ - if( ( etype = TYPEget_name - ( TYPEget_nonaggregate_base_type( VARget_type( a ) ) ) ) ) { - fprintf( file, "\t // of %s\n", etype ); - } - } - - fprintf( file, "\n" ); - } - - LISTod; -} - -/****************************************************************** - ** Procedure: MemberFunctionSign - ** Parameters: Entity *entity -- entity being processed - ** FILE* file -- file being written to - ** Returns: - ** Description: prints the signature for member functions - of an entity's class definition - ** DAS prints the end of the entity class def and the creation - ** function that the EntityTypeDescriptor uses. - ** Side Effects: prints c++ code to a file - ** Status: ok 1/1/5/91 - ** updated 17-Feb-1992 to print only the signature - and not the function definitions - ******************************************************************/ - -void -MemberFunctionSign( Entity entity, FILE * file ) { - - Linked_List attr_list; - static int entcode = 0; - char entnm [BUFSIZ]; - - /* added for calling multiple_inheritance */ - Linked_List parent_attr_list; - Linked_List parent_list; - int super_cnt = 0; - - strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm */ - - fprintf( file, " public: \n" ); - - /* put in member functions which belong to all entities */ - /* constructor: */ - fprintf( file, "\n %s ( ); \n", entnm ); - - fprintf( file, "\t%s (SCLP23(Application_instance) *se, int *addAttrs = 0); \n", entnm ); - /* copy constructor*/ - fprintf( file, " %s (%s& e ); \n", entnm, entnm ); - /* destructor: */ - fprintf( file, " ~%s ();\n", entnm ); - - /* fprintf (file, " char *Name () { return \"%s\"; }\n", */ - /* PrettyTmpName (ENTITYget_name (entity)));*/ - fprintf( file, " int opcode () { return %d ; } \n", - entcode++ ); - - /* print signature of access functions for attributes */ - attr_list = ENTITYget_attributes( entity ); - LISTdo( attr_list, a, Variable ) - if( VARget_initializer( a ) == EXPRESSION_NULL ) { - - /* retrieval and assignment */ - ATTRsign_access_methods( a, file ); - } - - LISTod; - - /* //////////////// */ - if( multiple_inheritance ) { - /* could print out access functions for parent attributes not - inherited through C++ inheritance. */ - parent_list = ENTITYget_supertypes( entity ); - if( ! LISTempty( parent_list ) ) { - - LISTdo( parent_list, e, Entity ) - /* if there\'s no super class yet, - or the super class doesn\'t have any attributes - */ - - __attribute__( ( unused ) ) Entity super = e; - super_cnt++; - if( super_cnt == 1 ) { - /* ignore the 1st parent */ - fprintf( file, - "\t/* The first parent's access functions are */\n%s\n", - "\t/* above or covered by inherited functions. */" ); - } else { - fprintf( file, "\n#if 0\n" ); - /* printf("\tin ENTITY %s\n\tadding SUPERTYPE %s\'s member functions. 1\n\n", - ENTITYget_name (entity), ENTITYget_name (e));*/ - - parent_attr_list = ENTITYget_attributes( e ); - LISTdo( parent_attr_list, a2, Variable ) - /* do for EXPLICIT, REDEFINED, and INVERSE attributes - but not DERIVED */ - if( ! VARis_derived( a2 ) ) { - - /* retrieval and assignment */ - ATTRsign_access_methods( a2, file ); - } - LISTod; - fprintf( file, "\n#endif\n" ); - } - LISTod; - } - } - /* //////////////// */ - if( corba_binding ) { - fprintf( file, "\n//\t%s_ptr create_TIE();\n\tIDL_Application_instance_ptr create_TIE();\n", - ENTITYget_CORBAname( entity ) ); - /* - fprintf(file, "\n//\t%s_ptr create_TIE();\n\tP26::Application_instance_ptr create_TIE();\n", - ENTITYget_CORBAname(entity)); + sprintf (buf, " public %s, ", ENTITYget_classname (e)); + move (buf); + LISTod; + sprintf (buf - 2, " {\n"); + move (buf); + fprintf(file,buffer); */ + } else { /* if entity has no supertypes, it's at top of hierarchy */ + fprintf( file, " public SCLP23(Application_instance) {\n" ); } - fprintf( file, "};\n" ); - if( corba_binding ) { - fprintf( file, "\n// Associate IDL interface generated code with implementation object\nDEF_TIE_%s(%s)\n", ENTITYget_CORBAname( entity ), entnm ); - } +#endif + +} + +/****************************************************************** + ** Procedure: DataMemberPrint + ** Parameters: const Entity entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: prints out the data members for an entity's c++ class + ** definition + ** Side Effects: generates c++ code + ** Status: ok 1/15/91 + ******************************************************************/ + +void +DataMemberPrint( Entity entity, FILE * file, Schema schema ) { +} + +/****************************************************************** + ** Procedure: MemberFunctionSign + ** Parameters: Entity *entity -- entity being processed + ** FILE* file -- file being written to + ** Returns: + ** Description: prints the signature for member functions + of an entity's class definition + ** DAS prints the end of the entity class def and the creation + ** function that the EntityTypeDescriptor uses. + ** Side Effects: prints c++ code to a file + ** Status: ok 1/1/5/91 + ** updated 17-Feb-1992 to print only the signature + and not the function definitions + ******************************************************************/ - /* print creation function for class */ - fprintf( file, "\n#if defined(__O3DB__)\n" ); - fprintf( file, "inline SCLP23(Application_instance_ptr) \ncreate_%s () { return (SCLP23(Application_instance_ptr)) new %s ; }\n", - entnm, entnm ); - fprintf( file, "#else\n" ); - fprintf( file, "inline %s *\ncreate_%s () { return new %s ; }\n", - entnm, entnm, entnm ); - fprintf( file, "#endif\n" ); +void +MemberFunctionSign( Entity entity, FILE * file ) { } @@ -2445,110 +779,6 @@ ENTITYinc_print( Entity entity, FILE * file, Schema schema ) { MemberFunctionSign( entity, file ); } */ -/****************************************************************** - ** Procedure: LIBcopy_constructor - ** Parameters: - ** Returns: - ** Description: - ** Side Effects: - ** Status: not used 17-Feb-1992 - ******************************************************************/ -void -LIBcopy_constructor( Entity ent, FILE * file ) { - Linked_List attr_list; - Class_Of_Type class; - Type t; - char buffer [BUFSIZ], - attrnm[BUFSIZ], - *b = buffer; - int count = attr_count; - - String entnm = ENTITYget_classname( ent ); - __attribute__( ( unused ) ) bool opt; - const char * StrToLower( const char * word ); - - /*mjm7/10/91 copy constructor definition */ - fprintf( file, "\t%s::%s(%s& e ) \n", entnm, entnm, entnm ); - fprintf( file, " {" ); - - /* attributes */ - attr_list = ENTITYget_attributes( ent ); - LISTdo( attr_list, a, Variable ) - if( VARget_initializer( a ) == EXPRESSION_NULL ) { - /* include attribute if it is not derived */ - generate_attribute_name( a, attrnm ); - t = VARget_type( a ); - class = TYPEget_type( t ); - opt = VARget_optional( a ); - - /* 1. initialize everything to NULL (even if not optional) */ - - /* default: to intialize attribute to NULL */ - sprintf( b, "\t_%s = e.%s();\n", attrnm, attrnm ); - - /*mjm7/11/91 case TYPE_STRING */ - if( ( class == Class_String_Type ) || ( class == Class_Binary_Type ) ) { - sprintf( b, "\t_%s = strdup(e.%s());\n", attrnm, attrnm ); - } - - - /* case TYPE_ENTITY: */ - if( class == Class_Entity_Type ) { - sprintf( b, "\t_%s = e.%s();\n", attrnm, attrnm ); - } - /* previous line modified to conform with SDAI C++ Binding for PDES, Inc. Prototyping 5/22/91 CD */ - - /* case TYPE_ENUM: */ - if( class == Class_Enumeration_Type ) { - sprintf( b, "\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); - } - /* case TYPE_SELECT: */ - if( class == Class_Select_Type ) { - sprintf( b, "DDDDDDD\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); - } - /* case TYPE_BOOLEAN */ - if( class == Class_Boolean_Type ) { - sprintf( b, "\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); - } - /* previous line modified to conform with SDAI C++ Binding for PDES, Inc. Prototyping 5/22/91 CD */ - - /* case TYPE_LOGICAL */ - if( class == Class_Logical_Type ) { - sprintf( b, "\t_%s.put(e.%s().asInt());\n", attrnm, attrnm ); - } - /* previous line modified to conform with SDAI C++ Binding for PDES, Inc. Prototyping 5/22/91 CD */ - - /* case TYPE_ARRAY: - case TYPE_LIST: - case TYPE_SET: - case TYPE_BAG: */ - if( isAggregateType( t ) ) { - *b = '\0'; - } - - fprintf( file, "%s", b ) ; - - fprintf( file, "\t attributes.push " ); - - /* 2. put attribute on attributes list */ - - /* default: */ - - fprintf( file, "\n\t(new STEPattribute(*%s%d%s, %s &_%s));\n", - ATTR_PREFIX, count, - /* (VARis_derived (t) ? "D" : (VARis_type_shifter (t) ? "R" : (VARget_inverse (t) ? "I" : ""))),*/ - /* (VARis_derived (t) ? "D" : (VARget_inverse (t) ? "I" : "")),*/ - attrnm, - ( TYPEis_entity( t ) ? "(SCLP23(Application_instance_ptr) *)" : "" ), - attrnm ); - ++count; - - } - LISTod; - fprintf( file, " }\n" ); - - -} int get_local_attribute_number( Entity entity ) { @@ -3090,76 +1320,6 @@ TYPEis_builtin( const Type t ) { */ void print_typechain( FILE * f, const Type t, char * buf, Schema schema ) { - /* if we've been called, current type has no name */ - /* nor is it a built-in type */ - /* the type_count variable is there for debugging purposes */ - - const char * ctype = TYPEget_ctype( t ); - Type base = 0; - int count = type_count++; - char typename_buf[MAX_LEN]; - - switch( TYPEget_body( t )->type ) { - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - /* create a new TypeDescriptor variable, e.g. t1, and new space for it */ - fprintf( f, "\t%s * %s%d = new %s;\n", - GetTypeDescriptorName( t ), TD_PREFIX, count, - GetTypeDescriptorName( t ) ); - - fprintf( f, - "\t%s%d->AssignAggrCreator((AggregateCreator) create_%s);%s", - TD_PREFIX, count, ctype, "\t// Creator function \n" ); - if( !TYPEget_head( t ) ) { - if( TYPEget_body( t )->lower ) - fprintf( f, "\t%s%d->Bound1(%d);\n", TD_PREFIX, count, - TYPEget_body( t )->lower->u.integer ); - if( TYPEget_body( t )->upper ) - fprintf( f, "\t%s%d->Bound2(%d);\n", TD_PREFIX, count, - TYPEget_body( t )->upper->u.integer ); - if( TYPEget_body( t )->flags.unique ) - fprintf( f, "\t%s%d->UniqueElements(LTrue);\n", - TD_PREFIX, count ); - if( TYPEget_body( t )->flags.optional ) - fprintf( f, "\t%s%d->OptionalElements(LTrue);\n", - TD_PREFIX, count ); - } - break; - - default: /* this should not happen since only aggregates are allowed to - not have a name. This funct should only be called for aggrs - without names. */ - fprintf( f, "\tTypeDescriptor * %s%d = new TypeDescriptor;\n", - TD_PREFIX, count ); - } - - /* there is no name so name doesn't need to be initialized */ - - fprintf( f, "\t%s%d->FundamentalType(%s);\n", TD_PREFIX, count, - FundamentalType( t, 1 ) ); - fprintf( f, "\t%s%d->Description(\"%s\");\n", TD_PREFIX, count, - TypeDescription( t ) ); - - /* DAS ORIG SCHEMA FIX */ - fprintf( f, "\t%s%d->OriginatingSchema(%s%s);\n", TD_PREFIX, count, - SCHEMA_PREFIX, SCHEMAget_name( schema ) ); - - if( TYPEget_RefTypeVarNm( t, typename_buf, schema ) ) { - fprintf( f, "\t%s%d->ReferentType(%s);\n", TD_PREFIX, count, typename_buf ); - } else { - /* no name, recurse */ - char callee_buffer[MAX_LEN]; - if( TYPEget_body( t ) ) { - base = TYPEget_body( t )->base; - } - print_typechain( f, base, callee_buffer, schema ); - fprintf( f, "\t%s%d->ReferentType(%s);\n", TD_PREFIX, count, callee_buffer ); - } - sprintf( buf, "%s%d", TD_PREFIX, count ); - } /****************************************************************** @@ -4050,64 +2210,6 @@ Type_Description( const Type t, char * buf ) { **************************************************************************/ void TYPEprint_typedefs( Type t, FILE * classes ) { - char nm [BUFSIZ]; - Type i; - - /* Print the typedef statement (poss also a forward class def: */ - if( TYPEis_enumeration( t ) ) { - /* For enums and sels (else clause below), we need forward decl's so - // that if we later come across a type which is an aggregate of one of - // them, we'll be able to process it. For selects, we also need a decl - // of the class itself, while for enum's we don't. Objects which con- - // tain an enum can't be generated until the enum is generated. (The - // same is basically true for the select, but a sel containing an ent - // containing a sel needs the forward decl (trust me ;-) ). */ - if( !TYPEget_head( t ) ) { - /* Only print this enum if it is an actual type and not a redefi- - // nition of another enum. (Those are printed at the end of the - // classes file - after all the actual enum's. They must be - // printed last since they depend on the others.) */ - strncpy( nm, TYPEget_ctype( t ), BUFSIZ ); - fprintf( classes, "class %ss;\n", nm ); - } - } else if( TYPEis_select( t ) ) { - if( !TYPEget_head( t ) ) { - /* Same comment as above. */ - strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ ); - fprintf( classes, "class %s;\n", nm ); - fprintf( classes, "typedef %s * %s_ptr;\n", nm, nm ); - fprintf( classes, "class %ss;\n", nm ); - fprintf( classes, "typedef %ss * %ss_ptr;\n", nm, nm ); - } - } else { - if( TYPEis_aggregate( t ) ) { - i = TYPEget_base_type( t ); - if( TYPEis_enumeration( i ) || TYPEis_select( i ) ) { - /* One exceptional case - a 1d aggregate of an enum or select. - // We must wait till the enum/sel itself has been processed. - // To ensure this, we process all such 1d aggrs in a special - // loop at the end (in multpass.c). 2d aggrs (or higher), how- - // ever, can be processed now - they only require GenericAggr - // for their definition here. */ - goto externln; - } - } - /* At this point, we'll print typedefs for types which are redefined - // fundamental types and their aggregates, and for 2D aggregates(aggre- - // gates of aggregates) of enum's and selects. */ - strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); - fprintf( classes, "typedef %s \t%s;\n", TYPEget_ctype( t ), nm ); - if( TYPEis_aggregate( t ) ) { - fprintf( classes, "typedef %s * \t%sH;\n", nm, nm ); - fprintf( classes, "typedef %s * \t%s_ptr;\n", nm, nm ); - fprintf( classes, "typedef %s_ptr \t%s_var;\n", nm, nm ); - } - } - -externln: - /* Print the extern statement: */ - strncpy( nm, TYPEtd_name( t ), BUFSIZ ); - fprintf( classes, "extern %s \t*%s;\n", GetTypeDescriptorName( t ), nm ); } /* return 1 if it is a multidimensional aggregate at the level passed in @@ -4309,9 +2411,7 @@ printEnumCreateHdr( FILE * inc, const Type type ) * of it (when "TYPE enum2 = enum1"), I placed this code in a separate fn. */ { - const char * nm = TYPEget_ctype( type ); - fprintf( inc, " SCLP23(Enum) * create_%s ();\n", nm ); } static void @@ -4320,13 +2420,6 @@ printEnumCreateBody( FILE * lib, const Type type ) * See header comment above by printEnumCreateHdr. */ { - const char * nm = TYPEget_ctype( type ); - char tdnm[BUFSIZ]; - - strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - - fprintf( lib, "\nSCLP23(Enum) * \ncreate_%s () \n{\n", nm ); - fprintf( lib, " return new %s( \"\", %s );\n}\n\n", nm, tdnm ); } static void @@ -4335,21 +2428,10 @@ printEnumAggrCrHdr( FILE * inc, const Type type ) * Similar to printEnumCreateHdr above for the enum aggregate. */ { - const char * n = TYPEget_ctype( type ); - /* const char *n = ClassName( TYPEget_name(type) ));*/ - - fprintf( inc, " STEPaggregate * create_%ss ();\n", n ); } static void printEnumAggrCrBody( FILE * lib, const Type type ) { - const char * n = TYPEget_ctype( type ); - char tdnm[BUFSIZ]; - - strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - - fprintf( lib, "\nSTEPaggregate * \ncreate_%ss ()\n{\n", n ); - fprintf( lib, " return new %ss( %s );\n}\n", n, tdnm ); } void @@ -4444,231 +2526,4 @@ TYPEprint_nm_ft_desc( Schema schema, const Type type, FILE * f, char * endChars void TYPEprint_new( const Type type, FILE * create, Schema schema ) { - Linked_List wheres; - char * whereRule, *whereRule_formatted = ""; - int whereRule_formatted_size = 0; - char * ptr, *ptr2; - - Type tmpType = TYPEget_head( type ); - Type bodyType = tmpType; - - /* define type definition */ - /* in source - the real definition of the TypeDescriptor */ - - if( TYPEis_select( type ) ) { - fprintf( create, - "\t%s = new SelectTypeDescriptor (\n\t\t ~%s,\t//unique elements,\n", - TYPEtd_name( type ), - /* ! any_duplicates_in_select (SEL_TYPEget_items(type)) );*/ - /* unique_types (SEL_TYPEget_items (type) ) );*/ - non_unique_types_string( type ) ); - /* DAS ORIG SCHEMA FIX */ - TYPEprint_nm_ft_desc( schema, type, create, "," ); - - fprintf( create, - "\t\t (SelectCreator) create_%s);\t// Creator function\n", - SelectName( TYPEget_name( type ) ) ); - } else - /*DASSSS if (TYPEget_name(t)) { - strcat(buf," "); - strcat(buf,PrettyTmpName (TYPEget_name(t))); - */ - switch( TYPEget_body( type )->type ) { - - - case boolean_: - - fprintf( create, "\t%s = new EnumTypeDescriptor (\n", - TYPEtd_name( type ) ); - - /* fill in it's values */ - TYPEprint_nm_ft_desc( schema, type, create, "," ); - fprintf( create, - "\t\t (EnumCreator) create_BOOLEAN);\t// Creator function\n" ); - break; - - case logical_: - - fprintf( create, "\t%s = new EnumTypeDescriptor (\n", - TYPEtd_name( type ) ); - - /* fill in it's values */ - TYPEprint_nm_ft_desc( schema, type, create, "," ); - fprintf( create, - "\t\t (EnumCreator) create_LOGICAL);\t// Creator function\n" ); - break; - - case enumeration_: - - fprintf( create, "\t%s = new EnumTypeDescriptor (\n", - TYPEtd_name( type ) ); - - /* fill in it's values */ - TYPEprint_nm_ft_desc( schema, type, create, "," ); - /* - fprintf(create, - "\t\t (EnumCreator) create_%s);\t// Creator function\n", - TYPEget_ctype(type) ); - */ - /* DASCUR */ - - /* get the type name of the underlying type - it is the type that - needs to get created */ - - tmpType = TYPEget_head( type ); - if( tmpType ) { - - bodyType = tmpType; - - while( tmpType ) { - bodyType = tmpType; - tmpType = TYPEget_head( tmpType ); - } - - fprintf( create, - "\t\t (EnumCreator) create_%s);\t// Creator function\n", - TYPEget_ctype( bodyType ) ); - } else - fprintf( create, - "\t\t (EnumCreator) create_%s);\t// Creator function\n", - TYPEget_ctype( type ) ); - break; - - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - - fprintf( create, "\n\t%s = new %s (\n", - TYPEtd_name( type ), GetTypeDescriptorName( type ) ); - - /* fill in it's values */ - TYPEprint_nm_ft_desc( schema, type, create, "," ); - - fprintf( create, - "\t\t (AggregateCreator) create_%s);\t// Creator function\n\n", - ClassName( TYPEget_name( type ) ) ); - break; - - default: - fprintf( create, "\t%s = new TypeDescriptor (\n", - TYPEtd_name( type ) ); - - /* fill in it's values */ - TYPEprint_nm_ft_desc( schema, type, create, ");" ); - - break; - } - /* add the type to the Schema dictionary entry */ - fprintf( create, "\t%s%s->AddType(%s);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ), TYPEtd_name( type ) ); - - - wheres = type->where; - - if( wheres ) { - fprintf( create, "\t%s->_where_rules = new Where_rule__list;\n", - TYPEtd_name( type ) ); - - LISTdo( wheres, w, Where ) - whereRule = EXPRto_string( w->expr ); - ptr2 = whereRule; - - if( whereRule_formatted_size == 0 ) { - whereRule_formatted_size = 3 * BUFSIZ; - whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); - } else if( ( strlen( whereRule ) + 300 ) > whereRule_formatted_size ) { - free( whereRule_formatted ); - whereRule_formatted_size = strlen( whereRule ) + BUFSIZ; - whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); - } - whereRule_formatted[0] = '\0'; - if( w->label ) { - strcpy( whereRule_formatted, w->label->name ); - strcat( whereRule_formatted, ": (" ); - ptr = whereRule_formatted + strlen( whereRule_formatted ); - while( *ptr2 ) { - if( *ptr2 == '\n' ) { - ; - } else if( *ptr2 == '\\' ) { - *ptr = '\\'; - ptr++; - *ptr = '\\'; - ptr++; - - } else if( *ptr2 == '(' ) { - /* *ptr = '\\'; ptr++; - *ptr = 'n'; ptr++; - *ptr = '\\'; ptr++; - *ptr = 't'; ptr++; */ - *ptr = *ptr2; - ptr++; - } else { - *ptr = *ptr2; - ptr++; - } - ptr2++; - } - *ptr = '\0'; - - strcat( ptr, ");\\n" ); - } else { - /* no label */ - strcpy( whereRule_formatted, "(" ); - ptr = whereRule_formatted + strlen( whereRule_formatted ); - - while( *ptr2 ) { - if( *ptr2 == '\n' ) { - ; - } else if( *ptr2 == '\\' ) { - *ptr = '\\'; - ptr++; - *ptr = '\\'; - ptr++; - - } else if( *ptr2 == '(' ) { - /* *ptr = '\\'; ptr++; - *ptr = 'n'; ptr++; - *ptr = '\\'; ptr++; - *ptr = 't'; ptr++; */ - *ptr = *ptr2; - ptr++; - } else { - *ptr = *ptr2; - ptr++; - } - ptr2++; - } - *ptr = '\0'; - strcat( ptr, ");\\n" ); - } - fprintf( create, "\twr = new Where_rule(\"%s\");\n", whereRule_formatted ); - fprintf( create, "\t%s->_where_rules->Append(wr);\n", - TYPEtd_name( type ) ); - - free( whereRule ); - ptr2 = whereRule = 0; - LISTod - free( whereRule_formatted ); - } } - -/* - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - case select_: - case enumeration_: - case boolean_: - case logical_: - case integer_: - case real_: - case number_: - case string_: - case binary_: - case number_: - case generic_: - case entity_: -*/ diff --git a/src/fedex_python/src/multpass_python.c b/src/fedex_python/src/multpass_python.c index 50f8e889a..d1b5b5fca 100644 --- a/src/fedex_python/src/multpass_python.c +++ b/src/fedex_python/src/multpass_python.c @@ -589,35 +589,6 @@ static void addRenameTypedefs( Schema schema, FILE * classes ) * Sdaiclasses.h (needs to have forward declarations here).) */ { - DictionaryEntry de; - Type i; - char nm[BUFSIZ], basenm[BUFSIZ]; - static int firsttime = TRUE; - - SCOPEdo_types( schema, t, de ) - if( ( TYPEis_enumeration( t ) || TYPEis_select( t ) ) - && ( ( i = TYPEget_ancestor( t ) ) != NULL ) ) { - /* I.e., t is a renamed enum/sel type. i is set to the orig enum/ - // sel t is based on (in case it's a rename of a rename etc). */ - if( firsttime ) { - printf( "\n// Renamed enum and select\n" ); - //printf( " types (from all schemas):\n" ); - firsttime = FALSE; - } - if( TYPEis_enumeration( t ) ) { - strncpy( nm, TYPEget_ctype( t ), BUFSIZ - 1 ); - strncpy( basenm, TYPEget_ctype( i ), BUFSIZ - 1 ); - //fprintf( classes, "typedef %ss\t%ss;\n", basenm, nm ); - } else { - strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ - 1 ); - strncpy( basenm, SelectName( TYPEget_name( i ) ), BUFSIZ - 1 ); - printf( "typedef %s %s;\n", basenm, nm ); - //fprintf( "typedef %s * %s_ptr;\n", nm, nm ); - //fprintf( classes, "typedef %ss %ss;\n", basenm, nm ); - //fprintf( classes, "typedef %ss * %ss_ptr;\n", nm, nm ); - } - } - SCOPEod } static void addAggrTypedefs( Schema schema, FILE * classes ) diff --git a/src/fedex_python/src/selects_python.c b/src/fedex_python/src/selects_python.c index 78dcc8e22..db3393852 100644 --- a/src/fedex_python/src/selects_python.c +++ b/src/fedex_python/src/selects_python.c @@ -79,12 +79,6 @@ SEL_ITEMget_enumtype( Type t ) { const char * TYPEget_utype( Type t ) { - /* - static char b [BUFSIZ]; - strncpy (b, TYPEget_ctype (t), BUFSIZ-2); - if (TYPEis_select (t)) strcat (b, "H"); - */ - return ( TYPEis_entity( t ) ? "SCLP23(Application_instance_ptr)" : TYPEget_ctype( t ) ); } /******************* @@ -208,45 +202,6 @@ SEL_ITEMget_dmtype( Type t, const Linked_List l ) { } -/** -*** SEL_ITEMget_dmname (Type t) -*** Returns the name of the data member in the select class for the item of -*** the select having the type t. -*** Logical and boolean are handled as exceptions because TYPEget_utype() -*** returns "PSDAI::..." for them which is not a legal variable name. -***/ - -const char * -SEL_ITEMget_dmname( Type t ) { - Class_Of_Type class = TYPEget_type( t ); - - if( class == Class_Integer_Type ) { - return "integer"; - } - if( class == Class_Real_Type ) { - return "real"; - } - if( class == Class_Number_Type ) { - return "real"; - } - if( class == Class_String_Type ) { - return "string"; - } - if( class == Class_Binary_Type ) { - return "binary"; - } - if( class == Class_Logical_Type ) { - return "logical"; - } - if( class == Class_Boolean_Type ) { - return "boolean"; - } - if( class == Class_Entity_Type ) { - return "app_inst"; - } - return ( StrToLower( TYPEget_utype( t ) ) ); -} - /******************* duplicate_in_express_list @@ -578,96 +533,7 @@ TYPEselect_inc_print_vars prints the class 'definition', that is, the objects ********************/ void TYPEselect_inc_print_vars( const Type type, FILE * f, Linked_List dups ) { - int size, j; - Linked_List data_members = SELgetnew_dmlist( type ); - char dmname [BUFSIZ], - classnm [BUFSIZ], - tdnm [BUFSIZ]; - - strncpy( classnm, SelectName( TYPEget_name( type ) ), BUFSIZ ); - strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - size = strlen( classnm ) + 2; /* for formatting output */ - - fprintf( f, "\n////////// SELECT TYPE %s\n", - SelectName( TYPEget_name( type ) ) ); - /* fprintf( f, "class %s;\n"*/ - /* "typedef %s * %sH;\n\n",*/ - /* classnm, classnm, classnm);*/ - fprintf( f, "class %s : public " BASE_SELECT " {\n", classnm ); - fprintf( f, " protected:\n" ); - /* fprintf( f, " \tunion { \n" ); */ - fprintf( f, "/* \tunion { */\n" ); - fprintf( f, "\t// types in SELECT \n" ); - LISTdo( SEL_TYPEget_items( type ), t, Type ) - fprintf( f, "\t// %s\t-- %s\n", - SEL_ITEMget_enumtype( t ), FundamentalType( t, 0 ) ); - LISTod; - - LISTdo( data_members, t, Type ) - strncpy( dmname, SEL_ITEMget_dmname( t ), BUFSIZ ); - fprintf( f, "\t %s _%s;\n", TYPEget_utype( t ), dmname ); - LISTod; - - /* fprintf( f, " \t} ;" );*/ - fprintf( f, "/* \t} ; */" ); - fprintf( f, " /* unnamed union of select items */\n" ); - - fprintf( f, "\n public:\n" ); - fprintf( f, - "\tvirtual const TypeDescriptor * AssignEntity (SCLP23(Application_instance) * se);\n" - "\tvirtual SCLP23(Select) * NewSelect ();\n" - ); - - fprintf( f, "\n\tvirtual BASE_TYPE ValueType() const;\n" ); - - fprintf( f, "\n\n// STEP Part 21\n" ); - fprintf( f, "\tvirtual void STEPwrite_content (ostream& out =std::cout,\n" - "\t\t\t\t\tconst char *currSch =0) const;\n" ); - fprintf( f, "\tvirtual void STEPwrite_verbose (ostream& out =std::cout,\n" - "\t\t\t\t\tconst char *currSch =0) const;\n" ); - fprintf( f, "\tvirtual Severity STEPread_content (istream& in =cin,\n" - "\t\tInstMgr * instances =0, const char *utype =0,\n" - "\t\tint addFileId =0, const char *currSch =0);\n" ); - - /* read StrToVal_content */ - fprintf( f, "\tvirtual Severity StrToVal_content " - "(const char *,\n\t\tInstMgr * instances =0);\n" ); - - /* constructor(s) */ - fprintf( f, "\n// STEP Part 22: SDAI\n" ); - fprintf( f, "\n// constructors\n" ); - fprintf( f, "\t%s( const SelectTypeDescriptor * =%s );\n", - classnm, tdnm ); - - fprintf( f, "\t// part 1\n" ); - - LISTdo( SEL_TYPEget_items( type ), t, Type ) - if( ( TYPEis_entity( t ) ) - || ( !utype_member( dups, t, 1 ) ) ) { - /** if an entity or not in the dup list **/ - fprintf( f, "\t%s( const %s&,\n\t", - SelectName( TYPEget_name( type ) ), AccessType( t ) ); - for( j = 0; j < size; j++ ) { - fprintf( f, " " ); - } - fprintf( f, "const SelectTypeDescriptor * =%s );\n", tdnm ); - } - LISTod; - LISTdo( dups, t, Type ) - if( ! TYPEis_entity( t ) ) { /* entities were done already */ - fprintf( f, "\t%s( const %s&,\n\t", - SelectName( TYPEget_name( type ) ), - isAggregateType( t ) ? AccessType( t ) : TYPEget_utype( t ) ); - for( j = 0; j < size; j++ ) { - fprintf( f, " " ); - } - fprintf( f, "const SelectTypeDescriptor * =%s );\n", tdnm ); - } - LISTod; - - /* destructor */ - fprintf( f, "\tvirtual ~%s();\n", classnm ); - LISTfree( data_members ); + } /******************* @@ -676,125 +542,7 @@ class. *******************/ void TYPEselect_inc_print( const Type type, FILE * f ) { - char n[BUFSIZ]; /* class name */ - char tdnm [BUFSIZ]; /* TypeDescriptor name */ - Linked_List dups; - int dup_result; - Linked_List attrs; - - dup_result = find_duplicate_list( type, &dups ); - strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ ); - strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - TYPEselect_inc_print_vars( type, f, dups ); - - fprintf( f, "\n\t// part 2\n" ); - - LISTdo( SEL_TYPEget_items( type ), t, Type ) - if( ( TYPEis_entity( t ) ) - || ( !utype_member( dups, t, 1 ) ) ) { - /** if an entity or not in the dup list **/ - fprintf( f, "\toperator %s();\n", AccessType( t ) ); - } - LISTod; - LISTdo( dups, t, Type ) - /* do the dups once only */ - if( ! TYPEis_entity( t ) ) /* entities were done already */ - fprintf( f, "\toperator %s ();\n", - ( TYPEis_aggregate( t ) || TYPEis_select( t ) ) ? - AccessType( t ) : TYPEget_utype( t ) ); - LISTod; - - fprintf( f, "\n\t// part 3\n" ); - attrs = SEL_TYPEgetnew_attribute_list( type ); - /* get the list of unique attributes from the entity items */ - LISTdo( attrs, a, Variable ) - if( VARget_initializer( a ) == EXPRESSION_NULL ) { - ATTRsign_access_methods( a, f ); - } - LISTod; - LISTfree( attrs ); - - fprintf( f, "\n\t// part 4\n" ); - LISTdo( SEL_TYPEget_items( type ), t, Type ) - if( ( TYPEis_entity( t ) ) - || ( !utype_member( dups, t, 1 ) ) ) { - /** if an entity or not in the dup list **/ - fprintf( f, "\t%s& operator =( const %s& );\n", - SelectName( TYPEget_name( type ) ), AccessType( t ) ); - } - LISTod; - LISTdo( dups, t, Type ) - if( ! TYPEis_entity( t ) ) { /* entities were done already */ - fprintf( f, "\t%s& operator =( const %s& );\n", - SelectName( TYPEget_name( type ) ), - isAggregateType( t ) ? AccessType( t ) : TYPEget_utype( t ) ); - } - LISTod; - - fprintf( f, "\t// not in SDAI\n" - "\t%s& ShallowCopy ( const %s& );\n", - n, n ); - - fprintf( f, "\n#ifdef COMPILER_DEFINES_OPERATOR_EQ\n#else\n" ); - fprintf( f, "\t%s& operator =( %s * const & );\n", n, n ); - fprintf( f, "\tSCLP23(Select)& operator =( const SCLP23(Select)& );\n" ); - /* fprintf( f, "\t%s& operator =( const %s& );\n", n, n );*/ - fprintf( f, "#endif\n" ); - - fprintf( f, "\n\t// part 5\n" ); - LISTdo( SEL_TYPEget_items( type ), t, Type ) - fprintf( f, "\tLogical Is%s() const;\n", - FirstToUpper( TYPEget_name( t ) ) ); - LISTod; - - fprintf( f, "\n\t// part 6 ... UnderlyingTypeName () implemented in" - " SCLP23(Select) class ...\n" ); - /* fprintf( f, "\tSCLP23(String) UnderlyingTypeName() const;\n" );*/ - /* fprintf( f, "\tconst EntityDescriptor * CurrentUnderlyingType();\n" );*/ - - if( dup_result ) { - /** if there are duplicate underlying types **/ - fprintf( f, "\n\t// part 7\n" ); - fprintf( f, "\tconst TypeDescriptor *" - "SetUnderlyingType ( const TypeDescriptor * td );\n"); - } else { - fprintf( f, "\n\t// part 7 ... NONE\tonly for complex selects...\n" ); - } - -#ifdef PART8 - fprintf( f, "\n\t// part 8\n" ); - fprintf( f, "\t%s* operator->();\n", n ); -#endif - - fprintf( f, "};\n" ); - - fprintf( f, "\ninline SCLP23(Select) * create_%s () { return new %s; }\n", n, n ); - - /* DAR - moved from SCOPEPrint() */ - fprintf( f, "typedef %s * %sH;\n", n, n ); - fprintf( f, "typedef %s_ptr %s_var;\n\n", n, n ); - - /* print things for aggregate class */ - fprintf( f, "\nclass %ss : public SelectAggregate {\n", n ); - fprintf( f, " protected:\n" ); - fprintf( f, " SelectTypeDescriptor *sel_type;\n\n" ); - fprintf( f, " public:\n" ); - fprintf( f, " %ss( SelectTypeDescriptor * =%s );\n", n, tdnm ); - fprintf( f, " ~%ss();\n", n ); - fprintf( f, " virtual SingleLinkNode * NewNode()\n" ); - fprintf( f, "\t { return new SelectNode (new %s( sel_type )); }\n", n ); - fprintf( f, "};\n" ); - - /* DAS creation function for select aggregate class */ - fprintf( f, "inline STEPaggregate * create_%ss () { return new %ss; }\n", - n, n ); - - fprintf( f, "typedef %ss_ptr %ss_var;\n", n, n ); - - fprintf( f, "\n///// END SELECT TYPE %s\n\n", TYPEget_name( type ) ); - - LISTfree( dups ); -} + } /******************* @@ -804,129 +552,6 @@ class. void TYPEselect_lib_print_part_one( const Type type, FILE * f, Schema schema, Linked_List dups, char * n ) { -#define schema_name SCHEMAget_name(schema) - char tdnm[BUFSIZ], - nm[BUFSIZ]; - int size = strlen( n ) * 2 + 4, j; /* size - for formatting output */ - - strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - strncpy( nm, SelectName( TYPEget_name( type ) ), BUFSIZ ); - - /* constructor(s) */ - /* null constructor */ - fprintf( f, "\n// STEP Part 22: SDAI\n" ); - fprintf( f, "\n\t// part 0\n" ); - fprintf( f, "%s::%s( const SelectTypeDescriptor *typedescript )\n", n, n ); - fprintf( f, " : " BASE_SELECT " (typedescript)" ); - /* Initialize the select members with their correct typedescriptors: */ - initSelItems( type, f ); - fprintf( f, "\n{\n" ); - fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); - fprintf( f, "\t*logStream << \"DAVE ERR entering %s constructor.\" << std::endl;\n", n ); - fprintf( f, " }\n#endif\n" ); - /* fprintf( f, "#ifdef WE_WANT_TO_HAVE_THIS_CONSTRUCTOR\n" );*/ - fprintf( f, " nullify();\n" ); - /* fprintf( f, "#endif\n" );*/ - fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); - fprintf( f, "//\t*logStream << \"DAVE ERR exiting %s constructor.\" << std::endl;\n", n ); - fprintf( f, " }\n#endif\n" ); - fprintf( f, "}\n" ); - - /* constructors with underlying types */ - fprintf( f, "\n\t// part 1\n" ); - LISTdo( SEL_TYPEget_items( type ), t, Type ) - if( ( TYPEis_entity( t ) ) - || ( !utype_member( dups, t, 1 ) ) ) { - /* if there is not more than one underlying type that maps to the same - * base type print out the constructor using the type from the TYPE - * statement as the underlying type. Also skip enums/sels which are - * renames of other items. That would create redundant constructors - * since renames are typedef'ed to the original type. - */ - fprintf( f, "%s::%s( const %s& o,\n", n, n, AccessType( t ) ); - for( j = 0; j < size; j++ ) { - fprintf( f, " " ); - } - /* Did this for the heck of it, and to show how easy it would have - been to make it all pretty - DAR. ;-) */ - fprintf( f, "const SelectTypeDescriptor *typedescript )\n" ); - - fprintf( f, " : " BASE_SELECT " (typedescript, %s)", - TYPEtd_name( t ) ); - initSelItems( type, f ); - fprintf( f, "\n{\n" ); - fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); - fprintf( f, - "\t*logStream << \"DAVE ERR entering %s constructor.\"" - " << std::endl;\n", n ); - fprintf( f, " }\n#endif\n" ); - - if( isAggregateType( t ) ) { - fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); - } else { - fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); - } - fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); - fprintf( f, - "//\t*logStream << \"DAVE ERR exiting %s constructor.\"" - " << std::endl;\n", n ); - fprintf( f, " }\n#endif\n" ); - - fprintf( f, "}\n\n" ); - } - LISTod; - LISTdo( dups, t, Type ) - /* if there is more than one underlying type that maps to the - * same base type, print a constructor using the base type. - */ - if( ! TYPEis_entity( t ) ) { /* entities were done already */ - if( isAggregateType( t ) ) { - fprintf( f, "%s::%s( const %s& o,\n", n, n, AccessType( t ) ); - for( j = 0; j < size; j++ ) { - fprintf( f, " " ); - } - fprintf( f, "const SelectTypeDescriptor *typedescript )\n" ); - fprintf( f, " : " BASE_SELECT " ( typedescript, %s )", - TYPEtd_name( t ) ); - initSelItems( type, f ); - fprintf( f, "\n{\n" ); - fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); - fprintf( f, - "\t*logStream << \"DAVE ERR entering %s constructor.\"" - " << std::endl;\n", n ); - fprintf( f, " }\n#endif\n" ); - fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); - } else { - fprintf( f, "%s::%s( const %s& o,\n", n, n, TYPEget_utype( t ) ); - for( j = 0; j < size; j++ ) { - fprintf( f, " " ); - } - fprintf( f, "const SelectTypeDescriptor *typedescript )\n" ); - fprintf( f, " : " BASE_SELECT " ( typedescript, %s )", - TYPEtd_name( t ) ); - initSelItems( type, f ); - fprintf( f, "\n{\n" ); - fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); - } - fprintf( f, - "// NOTE: Underlying type defaults to %s instead of NULL\n", - TYPEtd_name( t ) ); - fprintf( f, "#ifdef SCL_LOGGING\n if( *logStream )\n {\n" ); - fprintf( f, - "//\t*logStream << \"DAVE ERR exiting %s constructor.\"" - " << std::endl;\n", n ); - fprintf( f, " }\n#endif\n" ); - fprintf( f, "}\n\n" ); - } - LISTod; - - fprintf( f, "%s::~%s()\n{\n", n, n ); - fprintf( f, "}\n\n" ); - - fprintf( f, "%ss::%ss( SelectTypeDescriptor *s)\n" - " : SelectAggregate(), sel_type(s)\n{\n}\n\n", n, n ); - fprintf( f, "%ss::~%ss() { }\n\n", n, n ); -#undef schema_name } static void @@ -938,14 +563,6 @@ initSelItems( const Type type, FILE * f ) * selA's, so it must be set specifically. */ { - Linked_List data_members = SELgetnew_dmlist( type ); - - LISTdo( data_members, t, Type ) - if( TYPEis_select( t ) ) { - fprintf( f, ",\n _%s (%s)", SEL_ITEMget_dmname( t ), - TYPEtd_name( t ) ); - } - LISTod; } Linked_List @@ -1019,179 +636,6 @@ types. void TYPEselect_lib_print_part_three( const Type type, FILE * f, Schema schema, char * classnm ) { -#define ENTITYget_type(e) ((e)->u.entity->type) - - char uent[BUFSIZ], /* name of underlying entity type */ - utype[BUFSIZ], /* underlying type name */ - attrnm [BUFSIZ], /* attribute name -> data member = _attrnm */ - funcnm[BUFSIZ]; /* access function name = Attrnm */ - Linked_List items = SEL_TYPEget_items( type ); - /* all the items in the select type */ - Linked_List attrs = SEL_TYPEgetnew_attribute_list( type ); - /* list of attributes with unique names */ - Entity ent; - Variable uattr; /* attribute in underlying type */ - - fprintf( f, "\n\t// part 3\n" ); - - LISTdo( attrs, a, Variable ) - /* go through all the unique attributes */ - if( VARget_initializer( a ) == EXPRESSION_NULL ) { - /* only do for explicit attributes */ - generate_attribute_func_name( a, funcnm ); - generate_attribute_name( a, attrnm ); - /* - strncpy (funcnm, attrnm, BUFSIZ); - funcnm [0] = toupper (funcnm[0]); - */ - /* use the ctype since utype will be the same for all entities */ - strncpy( utype, TYPEget_ctype( VARget_type( a ) ), BUFSIZ ); - - /* get method */ - ATTRprint_access_methods_get_head( classnm, a, f ); - fprintf( f, "{\n" ); - - LISTdo( items, t, Type ) - if( TYPEis_entity( t ) && - ( uattr = ENTITYget_named_attribute - ( ( ent = ENT_TYPEget_entity( t ) ), - ( char * ) StrToLower( attrnm ) ) ) ) - - { - /* for the select items which have the current attribute */ - - /* if ( !multiple_inheritance ) { */ - if( !memberOfEntPrimary( ent, uattr ) ) { - /* If multiple inheritance is not supported, we must addi- - tionally check that uattr is a member of the entity's - primary inheritance path (i.e., the entity, its first - supertype, the super's first super, etc). The above - `if' is commented out, because currently mult inher is - not supported to the extent of handling accessor func- - tions for non-primary supertypes. */ - continue; - } - /* } */ - - if( ! VARis_derived( uattr ) ) { - - if( !strcmp( utype, TYPEget_ctype( VARget_type( uattr ) ) ) ) { - /* check to make sure the underlying attribute\'s type is - the same as the current attribute. - */ - - strncpy( uent, TYPEget_ctype( t ), BUFSIZ ); - - /* if the underlying type is that item\'s type - call the underlying_item\'s member function */ - fprintf( f, - " if( CurrentUnderlyingType () == %s ) \n\t// %s\n", - TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) ) ); - fprintf( f, "\treturn ((%s) _%s) ->%s();\n", - uent, SEL_ITEMget_dmname( t ), funcnm ); - - } else { - /* types are not the same issue a warning */ - fprintf( stderr, - "WARNING: in SELECT TYPE %s: \n\tambiguous " - "attribute \"%s\" from underlying type \"%s\".\n\n", - TYPEget_name( type ), attrnm, TYPEget_name( t ) ); - fprintf( f, " // %s\n\t// attribute access function" - " has a different return type\n", - StrToUpper( TYPEget_name( t ) ) ); - } - - } else /* derived attributes */ - fprintf( f, " // for %s attribute is derived\n", - StrToUpper( TYPEget_name( t ) ) ); - } - LISTod; - PRINT_BUG_REPORT - - /* If the return type is an enumeration class then you can\'t - return NULL. Instead I made the return type the - enumeration value. This causes a WARNING about going from - int (NULL) to the enumeration type. To get rid of the - WARNING you could add an explicit cast (using the code - commented out below. - - Another option is to have the return type be the - enumeration class and create special "NULL" instances of - the class for every enumeration. This option was not - implemented. - - kcm 28-Mar-1995 - */ - - - - /* EnumName (TYPEget_name (VARget_type (a)))*/ - switch( TYPEget_body( VARget_type( a ) ) -> type ) { - case enumeration_: - fprintf( f, " return (%s) 0;\n}\n\n", - EnumName( TYPEget_name( VARget_type( a ) ) ) ); - break; - - case boolean_: - fprintf( f, " return (Boolean) 0;\n}\n\n" ); - break; - - case logical_: - fprintf( f, " return (Logical) 0;\n}\n\n" ); - break; - - default: - fprintf( f, " return 0;\n}\n\n" ); - } - - /* put method */ - ATTRprint_access_methods_put_head( classnm, a, f ); - fprintf( f, "{\n" ); - LISTdo( items, t, Type ) - if( TYPEis_entity( t ) && - ( uattr = ENTITYget_named_attribute( - ( ent = ENT_TYPEget_entity( t ) ), - ( char * ) StrToLower( attrnm ) ) ) ) - - { - /* for the select items which have the current attribute */ - - /* if ( !multiple_inheritance ) { */ - if( !memberOfEntPrimary( ent, uattr ) ) { - /* See note for similar code segment in 1st part of fn. */ - continue; - } - /* } */ - - if( ! VARis_derived( uattr ) ) { - - if( !strcmp( utype, TYPEget_ctype( VARget_type( uattr ) ) ) ) { - /* check to make sure the underlying attribute\'s type is - the same as the current attribute. - */ - - /* if the underlying type is that item\'s type - call the underlying_item\'s member function */ - strncpy( uent, TYPEget_ctype( t ), BUFSIZ ); - fprintf( f, - " if( CurrentUnderlyingType () == %s ) \n\t// %s\n", - TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) ) ); - fprintf( f, "\t{ ((%s) _%s) ->%s( x );\n\t return;\n\t}\n", - uent, SEL_ITEMget_dmname( t ), funcnm ); - } else /* warning printed above */ - fprintf( f, " // for %s attribute access function" - " has a different argument type\n", - SEL_ITEMget_enumtype( t ) ); - } else /* derived attributes */ - fprintf( f, " // for %s attribute is derived\n", - SEL_ITEMget_enumtype( t ) ); - } - LISTod; - PRINT_SELECTBUG_WARNING( f ); - fprintf( f, "}\n" ); - } - LISTod; - LISTfree( attrs ); } /******************* @@ -1201,158 +645,7 @@ class. void TYPEselect_lib_print_part_four( const Type type, FILE * f, Schema schema, Linked_List dups, char * n ) { - char x[BUFSIZ]; - int firsttime = 1; - - fprintf( f, "\n\t// part 4\n" ); - - LISTdo( SEL_TYPEget_items( type ), t, Type ) - if( ( TYPEis_entity( t ) ) - || ( !utype_member( dups, t, 1 ) ) ) { - fprintf( f, "%s& %s::operator =( const %s& o )\n{\n" - " nullify ();\n", - n, n, AccessType( t ) ); - - if( isAggregateType( t ) ) { - fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); - } else { - fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); - } - - fprintf( f, " SetUnderlyingType (%s);\n", TYPEtd_name( t ) ); - fprintf( f, " return *this;\n}\n\n" ); - } - LISTod; - LISTdo( dups, t, Type ) - if( ! TYPEis_entity( t ) ) { /* entities were done already */ - if( isAggregateType( t ) ) { - fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", - n, n, AccessType( t ) ); - fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) ); - } else { - fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", - n, n, TYPEget_utype( t ) ); - fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) ); - } - - fprintf( f, " underlying_type = 0; // MUST BE SET BY USER\n" ); - fprintf( f, " // discriminator = UNSET\n" ); - fprintf( f, " return *this;\n}\n" ); - } - LISTod; - - fprintf( f, "\n#ifdef COMPILER_DEFINES_OPERATOR_EQ\n#else\n\n" ); - fprintf( f, "%s& %s::operator =( const %s_ptr& o )\n{\n", n, n, n ); - - LISTdo( SEL_TYPEget_items( type ), t, Type ) - strncpy( x, TYPEget_name( t ), BUFSIZ ); - if( firsttime ) { - fprintf( f, " " ); - firsttime = 0; - } else { - fprintf( f, " else " ); - } - fprintf( f, "if ( o -> CurrentUnderlyingType () == %s )\n", - TYPEtd_name( t ) ); - if( TYPEis_select( t ) ) { - if( utype_member( dups, t, 1 ) ) - /** if in the dup list **/ - fprintf( f, " _%s = &(o -> _%s);\n", - SEL_ITEMget_dmname( t ), - StrToLower( TYPEget_utype( t ) ) ); - else - fprintf( f, "\t_%s = &(o -> _%s);\n", - SEL_ITEMget_dmname( t ), - SEL_ITEMget_dmname( t ) ); - } else { - if( utype_member( dups, t, 1 ) ) - /** if in the dup list **/ - fprintf( f, " _%s = o -> _%s;\n", - SEL_ITEMget_dmname( t ), - SEL_ITEMget_dmname( t ) ); - /* I changed this although I'm not sure how the if and else differ */ - /* StrToLower(TYPEget_utype(t)) ); */ - else - fprintf( f, "\t_%s = o -> _%s;\n", - SEL_ITEMget_dmname( t ), - SEL_ITEMget_dmname( t ) ); - } - LISTod; - fprintf( f, " underlying_type = o -> CurrentUnderlyingType ();\n" ); - fprintf( f, " return *this;\n}\n\n" ); - - /* fprintf( f, "%s& %s::operator =( const %s& o )\n{\n", n,n,n );*/ - fprintf( f, "SCLP23(Select)& %s::operator =( const SCLP23(Select)& o )\n{\n", n ); - - firsttime = 1; - LISTdo( SEL_TYPEget_items( type ), t, Type ) - strncpy( x, TYPEget_name( t ), BUFSIZ ); - if( firsttime ) { - fprintf( f, " " ); - firsttime = 0; - } else { - fprintf( f, " else " ); - } - fprintf( f, "if ( o.CurrentUnderlyingType () == %s )\n", - TYPEtd_name( t ) ); - if( TYPEis_select( t ) ) { - if( utype_member( dups, t, 1 ) ) - /** if in the dup list **/ - /* fprintf( f, " _%s = o._%s;\n", */ - fprintf( f, "\t_%s = ((%s&) o)._%s;\n", - SEL_ITEMget_dmname( t ), - n, - SEL_ITEMget_dmname( t ) ); - /* StrToLower(TYPEget_utype(t)) ); */ - else - /* fprintf( f, "\t_%s = o._%s;\n", */ - fprintf( f, "\t_%s = &(((%s&) o)._%s);\n", - SEL_ITEMget_dmname( t ), - n, - SEL_ITEMget_dmname( t ) ); - } else { - if( utype_member( dups, t, 1 ) ) - /** if in the dup list **/ - /* fprintf( f, " _%s = o._%s;\n", */ - fprintf( f, "\t_%s = ((%s&) o)._%s;\n", - SEL_ITEMget_dmname( t ), - n, - SEL_ITEMget_dmname( t ) ); - /* StrToLower(TYPEget_utype(t)) ); */ - else - /* fprintf( f, "\t_%s = o._%s;\n", */ - fprintf( f, "\t_%s = ((%s&) o)._%s;\n", - SEL_ITEMget_dmname( t ), - n, - SEL_ITEMget_dmname( t ) ); - } - LISTod; - fprintf( f, " underlying_type = o.CurrentUnderlyingType ();\n" ); - fprintf( f, " return *this;\n}\n\n" ); - fprintf( f, "#endif\n" ); - -#ifdef JNK - /* define ShallowCopy because operator= does not always act virtual */ - fprintf( f, "SCLP23(Select)& %s::ShallowCopy ( const SCLP23(Select)& o )\n{\n", n ); - - LISTdo( SEL_TYPEget_items( type ), t, Type ) - strncpy( x, TYPEget_name( t ), BUFSIZ ); - fprintf( f, " if( o.CurrentUnderlyingType () == %s )\n", - TYPEtd_name( t ) ); - if( utype_member( dups, t, 1 ) ) - /** if in the dup list **/ - fprintf( f, " _%s = o._%s;\n", - SEL_ITEMget_dmname( t ), - StrToLower( TYPEget_utype( t ) ) ); - else - fprintf( f, "\t_%s = o._%s;\n", - SEL_ITEMget_dmname( t ), - SEL_ITEMget_dmname( t ) ); - LISTod; - fprintf( f, " underlying_type = o.CurrentUnderlyingType ();\n" ); - fprintf( f, " return *this;\n}\n" ); -#endif -} + } /******************* @@ -1374,370 +667,11 @@ TYPEselect_init_print( const Type type, FILE * f, Schema schema ) { void TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) { - char n[BUFSIZ]; /* pointers to class name(s) */ - const char * dm; /* data member name */ - Linked_List data_members = SELgetnew_dmlist( type ); - - strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ ); - - fprintf( f, "\n\n// STEP Part 21\n" ); - /* write part 21 */ - fprintf( f, "\nvoid\n%s::STEPwrite_content (ostream& out, const char *" - " currSch) const\n{\n ", n ); - - /* go through the items */ - LISTdo( SEL_TYPEget_items( type ), t, Type ) - dm = SEL_ITEMget_dmname( t ); - - fprintf( f, "if (CurrentUnderlyingType () == %s)\n", - TYPEtd_name( t ) ); - - switch( TYPEget_body( t )->type ) { - - /* if it\'s a number, just print it */ - case integer_: - fprintf( f, "\tout << _%s;\n else ", dm ); - break; - - case number_: - case real_: - fprintf( f, "\tWriteReal(_%s,out);\n else ", dm ); - break; - - case entity_: - fprintf( f, "\t_%s -> STEPwrite_reference (out);\n else ", dm ); - break; - - case string_: - case enumeration_: - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - case logical_: - case boolean_: - case binary_: - /* for string\'s, enum\'s, select\'s, binary\'s, and aggregate\'s - it\'ll be embedded; - */ - fprintf( f, "\t_%s.STEPwrite (out);\n else ", dm ); - break; - - case select_: - fprintf( f, "\t_%s.STEPwrite (out, currSch);\n else ", dm ); - /* Select type needs currSch passed too. A Select writes the name of its - // current choice when it writes itself out (e.g. "DATA(33.5)"). Since - // the current choice name may depend on our current schema (it may be a - // schema which USEs "DATA" and renames it to "VAL"), we pass currSch. */ - break; - - default: - /* otherwise it\'s a pointer */ - fprintf( f, "\t_%s -> STEPwrite (out);\n else ", dm ); - break; - } - LISTod; - - fprintf( f, " {\n" ); - PRINT_BUG_REPORT - fprintf( f, " }\n" ); - fprintf( f, " return;\n}\n" ); - - /* ValueType() -- get type of value stored in select */ - - fprintf( f, "\nBASE_TYPE\n%s::ValueType() const\n{\n ", n ); - - LISTdo( SEL_TYPEget_items( type ), t, Type ) - dm = SEL_ITEMget_dmname( t ); - fprintf( f, "if (CurrentUnderlyingType() == %s)\n", - TYPEtd_name( t ) ); - - switch( TYPEget_body( t )->type ) { - case select_: - fprintf( f, " return _%s.ValueType();\n else ", dm ); - break; - default: - fprintf( f, " return %s;\n else ", FundamentalType( t, 0 ) ); - } - LISTod; - - fprintf( f, " {\n" ); - PRINT_BUG_REPORT - fprintf( f, " }\n" ); - fprintf( f, " return (BASE_TYPE)0;\n}\n" ); - - /* STEPwrite_verbose() -- print value with specified type */ - - fprintf( f, "\nvoid\n%s::STEPwrite_verbose (ostream& out," - " const char *currSch) const\n{\n", n ); - - /* Get name of typedescriptor, according to value of currSch: */ - fprintf( f, " const TypeDescriptor *td = CurrentUnderlyingType();\n" ); - fprintf( f, " std::string tmp;\n\n" ); - fprintf( f, " if ( td ) {\n" ); - fprintf( f, " // If we have a legal underlying type, get its name acc\n" ); - fprintf( f, " // to the current schema.\n" ); - fprintf( f, " StrToUpper( td->Name(currSch), tmp );\n" ); - fprintf( f, " }\n " ); - - /* Next loop through the possible items: */ - LISTdo( SEL_TYPEget_items( type ), t, Type ) - dm = SEL_ITEMget_dmname( t ); - fprintf( f, "if (td == %s)\n", - TYPEtd_name( t ) ); - - switch( TYPEget_body( t )->type ) { - case integer_: - /* fprintf(f, " out << \"%s(\" << _%s << \")\";\n else ", - StrToUpper(TYPEget_name(t)), dm);*/ - fprintf( f, " out << tmp.c_str() << \"(\" << _%s << \")\";\n else ", - dm ); - break; - - case real_: - case number_: - fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); - fprintf( f, " WriteReal(_%s,out);\n", dm ); - fprintf( f, " out << \")\";\n }\n else " ); - break; - - case entity_: - fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); - fprintf( f, " _%s -> STEPwrite_reference (out);\n", dm ); - fprintf( f, " out << \")\";\n }\n else " ); - break; - case string_: - case enumeration_: - case logical_: - case boolean_: - case binary_: - fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); - fprintf( f, " _%s.STEPwrite (out);\n", dm ); - fprintf( f, " out << \")\";\n }\n else " ); - break; - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - /* Aggregates need currSch passed since they may be aggrs of sels. */ - fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); - fprintf( f, " _%s.STEPwrite (out, currSch);\n", dm ); - fprintf( f, " out << \")\";\n }\n else " ); - break; - case select_: - fprintf( f, " {\n out << tmp.c_str() << \"(\";\n" ); - fprintf( f, " _%s.STEPwrite_verbose (out, currSch);\n", dm ); - fprintf( f, " out << \")\";\n }\n else " ); - break; - default: - fprintf( f, " _%s -> STEPwrite (out); \n else ", dm ); - break; - } - LISTod; - - fprintf( f, " {\n" ); - PRINT_BUG_REPORT - fprintf( f, " }\n" ); - fprintf( f, " return;\n}\n" ); - - - /* Read part 21 */ - fprintf( f, "\nSeverity\n%s::STEPread_content " - "(istream& in, InstMgr * instances,\n\t\t\tconst char *utype, " - "int addFileId, const char *currSch)\n{\n", n ); - - /* go through the items */ - LISTdo( SEL_TYPEget_items( type ), t, Type ) - - fprintf( f, " if (CurrentUnderlyingType () == %s) ", - TYPEtd_name( t ) ); - - dm = SEL_ITEMget_dmname( t ); - - switch( TYPEget_body( t )->type ) { - /* if it\'s a number, just read it */ - case real_: - case number_: - /* since REAL and NUMBER are handled the same they both need - to be included in the case stmt */ - fprintf( f, " {\n\tReadReal (_%s, in, &_error, \"),\");\n" - "\treturn severity ();\n }\n", - dm ); - break; - - case integer_: - fprintf( f, " {\n\tReadInteger (_%s, in, &_error, \"),\");\n" - "\treturn severity ();\n }\n", - dm ); - break; - - case entity_: - /* if it\'s an entity, use Assign - done in Select class */ - fprintf( f, - " {\n\t// set Underlying Type in Select class\n" - "\t_%s = ReadEntityRef " - "(in, &_error, \",)\", instances, addFileId);\n", dm ); - fprintf( f, "\tif (_%s && (_%s != S_ENTITY_NULL)\n " - "\t && (CurrentUnderlyingType () -> CanBe (_%s -> eDesc )) )\n" - "\t return severity ();\n", - dm, dm, dm ); - fprintf( f, "\telse {\n " - "\t Error (\"Reference to instance that is not indicated type\\n\");\n" - "\t _%s = 0;\n" - "\t nullify ();\n" - "\t return severity (SEVERITY_USERMSG);\n\t}\n }\n", - dm - ); - break; - - case string_: - case enumeration_: - case logical_: - case boolean_: - case binary_: - fprintf( f, - " {\n\t_%s.STEPread (in, &_error);\n" - "\treturn severity ();\n }\n", - dm ); - break; - case select_: - fprintf( f, - " {\n\t_%s.STEPread (in, &_error, instances, utype, " - "addFileId, currSch);\n\treturn severity ();\n }\n", - dm ); - break; - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - fprintf( f, - " {\n\t_%s.STEPread (in, &_error,\n" - "\t\t\t %s -> AggrElemTypeDescriptor (),\n" - "\t\t\t instances, addFileId, currSch);\n" - "\treturn severity ();\n }\n", - dm, TYPEtd_name( t ) ); - break; - - default: - fprintf( f, - " {\n\t_%s -> STEPread (in, &_error, instances, addFileId);\n" - "\treturn severity ();\n }\n", - dm ); - break; - } - - LISTod; - - PRINT_SELECTBUG_WARNING( f ) ; - fprintf( f, "#ifdef __SUNCPLUSPLUS__\n" - "std::cerr << instances << \" \" << addFileId << std::endl;\n" - "#endif\n" ); - - LISTfree( data_members ); - fprintf( f, - /* "#ifdef __GNUG__\n"*/ - /* "\n return SEVERITY_NULL;\n"*/ - /* "#endif"*/ - "\n return severity ();" - "\n}\n" ); } void TYPEselect_lib_StrToVal( const Type type, FILE * f, Schema schema ) { - char n[BUFSIZ]; /* pointers to class name */ - Linked_List data_members = SELgetnew_dmlist( type ); - int enum_cnt = 0; - - strncpy( n, SelectName( TYPEget_name( type ) ), BUFSIZ ); - - /* read StrToVal_content */ - fprintf( f, "\nSeverity\n%s::StrToVal_content " - "(const char * str, InstMgr * instances)" - "\n{\n", n ); - - fprintf( f, " switch (base_type) {\n" ); - LISTdo( data_members, t, Type ) - /* fprintf (f, " case %s : \n", FundamentalType (t, 0));*/ - - switch( TYPEget_body( t )->type ) { - - case real_: - case integer_: - case number_: - case select_: - /* if it\'s a number, use STEPread_content - done in Select class */ - /* if it\'s a select, use STEPread_content - done in Select class */ - /* fprintf (f, "\t// done in Select class\n\treturn SEVERITY_NULL;\n");*/ - break; - - case entity_: - /* if it\'s an entity, use AssignEntity - done in Select class */ - /* fprintf (f, "\t// done in Select class\n\treturn SEVERITY_NULL;\n");*/ - - break; - case binary_: - case logical_: - case boolean_: - case enumeration_: - if( !enum_cnt ) { - /* if there\'s more than one enumeration they are done in Select class */ - fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); - fprintf( f, - "\treturn _%s.StrToVal (str, &_error);\n", - SEL_ITEMget_dmname( t ) ); - } else { - fprintf( f, " // case %s : done in Select class\n", FundamentalType( t, 0 ) ); - } - ++enum_cnt; - break; - - case string_: - fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); - fprintf( f, - "\treturn _%s.StrToVal (str);\n", - SEL_ITEMget_dmname( t ) ); - break; - - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); - fprintf( f, - "\treturn _%s.StrToVal (str, &_error, " - "%s -> AggrElemTypeDescriptor ());\n", - /* "instances, addFileId); "*/ - SEL_ITEMget_dmname( t ), - TYPEtd_name( t ) ); - break; - - default: - /* otherwise use StrToVal on the contents to check the format */ - fprintf( f, " case %s : \n", FundamentalType( t, 0 ) ); - fprintf( f, - "\treturn _%s -> StrToVal (str, instances);\n", - SEL_ITEMget_dmname( t ) ); - } - LISTod; - - fprintf( f, " default: // should never be here - done in Select class\n" ); - PRINT_SELECTBUG_WARNING( f ) ; - fprintf( f, "#ifdef __SUNCPLUSPLUS__\n" - "std::cerr << str << \" \" << instances << std::endl;\n" - "#endif\n" ); - fprintf( f, "\treturn SEVERITY_WARNING;\n }\n" ); - - LISTfree( data_members ); - fprintf( f, - "#ifdef __GNUG__\n" - "\n return SEVERITY_NULL;\n" - "#endif" - "\n}\n" ); } void @@ -1748,63 +682,6 @@ TYPEselect_lib_virtual( const Type type, FILE * f, Schema schema ) { void SELlib_print_protected( const Type type, FILE * f, const Schema schema ) { - const char * snm; - - /* SELECT::AssignEntity */ - fprintf( f, "\nconst TypeDescriptor * \n%s::AssignEntity (SCLP23(Application_instance) * se)\n" - "{\n", - SelectName( TYPEget_name( type ) ) - ); - - - /* loop through the items in the SELECT */ - LISTdo( SEL_TYPEget_items( type ), t, Type ) - if( TYPEis_entity( t ) ) { - fprintf( f, - " // %s\n" /* item name */ - " if (se -> IsA (%s))\n" /* td */ - " { \n" - "\t_%s = (%s_ptr) se;\n" /* underlying data member */ - /* underlying data member type */ - "\treturn SetUnderlyingType (%s);\n" /* td */ - " }\n", - StrToUpper( TYPEget_name( t ) ), - TYPEtd_name( t ), - SEL_ITEMget_dmname( t ), - ClassName( TYPEget_name( t ) ), - TYPEtd_name( t ) - ); - } - if( TYPEis_select( t ) ) { - fprintf( f, - " // %s\n" /* item name */ - " if (%s -> CanBe (se -> eDesc))\n" - " { \n" - "\t_%s.AssignEntity (se);\n" /* underlying data member */ - "\treturn SetUnderlyingType (%s);\n" /* td */ - " }\n", - StrToUpper( TYPEget_name( t ) ), - TYPEtd_name( t ), - SEL_ITEMget_dmname( t ), - TYPEtd_name( t ) - ); - } - - LISTod; - fprintf( f, " // should never be here - done in Select class\n" ); - PRINT_SELECTBUG_WARNING( f ) ; - fprintf( f, - "#ifdef __SUNCPLUSPLUS__\n" - " std::cerr << se -> EntityName () << std::endl;\n" - "#endif\n" - " return 0;\n}\n" ); - - /* SELECT::NewSelect */ - snm = SelectName( TYPEget_name( type ) ); - fprintf( f, "\nSCLP23(Select) * \n%s::NewSelect ()\n{\n", snm ); - - fprintf( f, " %s * tmp = new %s();\n", snm, snm ); - fprintf( f, " return tmp;\n}\n" ); } From 117ba3972f1d16ab21379cfee12aedca694fdf47 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Fri, 17 Feb 2012 14:12:26 +0100 Subject: [PATCH 06/19] SCL unittest fix --- .../unitary_schemas/index_attribute.py | 2 +- .../examples/unitary_schemas/test_array.py | 2 +- .../test_array_of_simple_types.py | 2 +- .../unitary_schemas/test_derived_attribute.py | 88 +----------------- .../unitary_schemas/test_enum_entity_name.py | 11 ++- .../unitary_schemas/test_enums_same_name.py | 2 +- .../test_multiple_inheritance.py | 2 +- .../unitary_schemas/test_named_type.py | 2 +- .../unitary_schemas/test_select_data_type.py | 2 +- .../test_single_inheritance.py | 2 +- .../test_single_inheritance_multi_level.py | 2 +- .../python/SCL/SimpleDataTypes.pyc | Bin 7205 -> 7815 bytes src/fedex_python/python/SCL/__init__.py | 2 +- src/fedex_python/python/SCL/__init__.pyc | Bin 258 -> 259 bytes src/fedex_python/python/SCL_unittest.py | 22 ++++- 15 files changed, 44 insertions(+), 97 deletions(-) diff --git a/src/fedex_python/examples/unitary_schemas/index_attribute.py b/src/fedex_python/examples/unitary_schemas/index_attribute.py index 4982859ff..b069d7ff5 100644 --- a/src/fedex_python/examples/unitary_schemas/index_attribute.py +++ b/src/fedex_python/examples/unitary_schemas/index_attribute.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * common_datum_list = 'LIST TYPE Not implemented' diff --git a/src/fedex_python/examples/unitary_schemas/test_array.py b/src/fedex_python/examples/unitary_schemas/test_array.py index 3f85ef484..65107c4fb 100644 --- a/src/fedex_python/examples/unitary_schemas/test_array.py +++ b/src/fedex_python/examples/unitary_schemas/test_array.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * diff --git a/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py b/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py index e34d9600a..bacdcb7b6 100644 --- a/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py +++ b/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * diff --git a/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py b/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py index 69723d30c..85f9d5d47 100644 --- a/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py +++ b/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * @@ -13,40 +13,9 @@ #################### class vector(BaseEntityClass): '''Entity vector definition. - - :param x - :type x:REAL - - :param y - :type y:REAL ''' - def __init__( self , x,y, ): - self.x = x - self.y = y - - @apply - def x(): - def fget( self ): - return self._x - def fset( self, value ): - # Mandatory argument - if value==None: - raise AssertionError('Argument x is mantatory and can not be set to None') - check_type(value,REAL) - self._x = value - return property(**locals()) - - @apply - def y(): - def fget( self ): - return self._y - def fset( self, value ): - # Mandatory argument - if value==None: - raise AssertionError('Argument y is mantatory and can not be set to None') - check_type(value,REAL) - self._y = value - return property(**locals()) + # This class does not define any attribute. + pass #################### # ENTITY circle # @@ -133,53 +102,6 @@ def fset( self, value ): #################### class point(BaseEntityClass): '''Entity point definition. - - :param x - :type x:REAL - - :param y - :type y:REAL - - :param z - :type z:REAL ''' - def __init__( self , x,y,z, ): - self.x = x - self.y = y - self.z = z - - @apply - def x(): - def fget( self ): - return self._x - def fset( self, value ): - # Mandatory argument - if value==None: - raise AssertionError('Argument x is mantatory and can not be set to None') - check_type(value,REAL) - self._x = value - return property(**locals()) - - @apply - def y(): - def fget( self ): - return self._y - def fset( self, value ): - # Mandatory argument - if value==None: - raise AssertionError('Argument y is mantatory and can not be set to None') - check_type(value,REAL) - self._y = value - return property(**locals()) - - @apply - def z(): - def fget( self ): - return self._z - def fset( self, value ): - # Mandatory argument - if value==None: - raise AssertionError('Argument z is mantatory and can not be set to None') - check_type(value,REAL) - self._z = value - return property(**locals()) + # This class does not define any attribute. + pass diff --git a/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py b/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py index 96aee837a..528a9fa44 100644 --- a/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py +++ b/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * # ENUMERATION TYPE simple_datum_reference_modifier @@ -12,3 +12,12 @@ 'line', 'translation', ]) + +#################### + # ENTITY line # +#################### +class line(BaseEntityClass): + '''Entity line definition. + ''' + # This class does not define any attribute. + pass diff --git a/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py b/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py index 41a5112a0..f3030e452 100644 --- a/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py +++ b/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * # ENUMERATION TYPE hair_color diff --git a/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py b/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py index 784c2539f..4ede2bc18 100644 --- a/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py +++ b/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * text = STRING diff --git a/src/fedex_python/examples/unitary_schemas/test_named_type.py b/src/fedex_python/examples/unitary_schemas/test_named_type.py index f8dced66c..ef366876d 100644 --- a/src/fedex_python/examples/unitary_schemas/test_named_type.py +++ b/src/fedex_python/examples/unitary_schemas/test_named_type.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * measure = REAL diff --git a/src/fedex_python/examples/unitary_schemas/test_select_data_type.py b/src/fedex_python/examples/unitary_schemas/test_select_data_type.py index 95de3b070..613ff0627 100644 --- a/src/fedex_python/examples/unitary_schemas/test_select_data_type.py +++ b/src/fedex_python/examples/unitary_schemas/test_select_data_type.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * diff --git a/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py b/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py index 7a9d6ac53..a37ee44e9 100644 --- a/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py +++ b/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * length_measure = REAL diff --git a/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py b/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py index 9113d4cbf..0c8e5cec5 100644 --- a/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py +++ b/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py @@ -4,7 +4,7 @@ from SCL.SCLBase import * from SCL.SimpleDataTypes import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * length_measure = REAL diff --git a/src/fedex_python/python/SCL/SimpleDataTypes.pyc b/src/fedex_python/python/SCL/SimpleDataTypes.pyc index 4e015cfe88ffe5293a9d36a987599226cf167f34..6a9b3e0e057bbd66450647e1e7699f98df1810c3 100644 GIT binary patch delta 759 zcmZ2#(QeCr@e?oC4sW}S>`}~)!3+!x`k}?CMaB9h8Tq-1#riI(WvMy(!6m5$&N+$2 z#XgxyMTtd~`o%@b`e~^tsTJ`Bl|Yqw`cP_efVkM?YUU`am?XaW1M?RaDjD^kLzm*?Ow{q*?;p;M>`}}tVhjunlM`jcChuU5f^oz*XR&-?LGZS5N;4vOn%t9F o5j+vW*GO{V!pTT-LXy!;aFvsfN=Jh^n-gWa;abEdJIlEM09r^P9{>OV diff --git a/src/fedex_python/python/SCL/__init__.py b/src/fedex_python/python/SCL/__init__.py index 96522a17f..ebced4874 100644 --- a/src/fedex_python/python/SCL/__init__.py +++ b/src/fedex_python/python/SCL/__init__.py @@ -1 +1 @@ -__all__ = ['SCLBase','SimpleDataTypes','AggregationDataType','TypeChecker','ConstructedDataTypes','Expr','Part21'] +__all__ = ['SCLBase','SimpleDataTypes','AggregationDataTypes','TypeChecker','ConstructedDataTypes','Expr','Part21'] diff --git a/src/fedex_python/python/SCL/__init__.pyc b/src/fedex_python/python/SCL/__init__.pyc index 44f764573e6c5d20fa9c9b93a8eb959c7b6d04c2..86f73b2053fa29def2e59b0a5bf9abed8048b92d 100644 GIT binary patch delta 43 ycmZo-YGz`;_=%S*IM8k)dyIq#0|SF&dU{c6dSXdtex6HWNn%K4L2B{Dsty1h$_{q` delta 42 xcmZo>YGPu)_=%TmYa!o6_84(t1_lPl^z@?C^u&_P{5+S$lEje8g4BuC9RM0G4pjgE diff --git a/src/fedex_python/python/SCL_unittest.py b/src/fedex_python/python/SCL_unittest.py index b32f737ab..86e26e2c0 100644 --- a/src/fedex_python/python/SCL_unittest.py +++ b/src/fedex_python/python/SCL_unittest.py @@ -34,7 +34,7 @@ from SCL.SimpleDataTypes import * from SCL.TypeChecker import * from SCL.ConstructedDataTypes import * -from SCL.AggregationDataType import * +from SCL.AggregationDataTypes import * # # Simple data types @@ -161,8 +161,24 @@ def test_create_array(self): self.fail('ExpectedException not thrown') def test_array_bounds(self): - a = ARRAY() - + a = ARRAY(3,8,REAL) + try: + a[2] + except IndexError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + try: + a[9] + except IndexError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + def test_array_unique(self): # if UNIQUE is not set to True (False by default), # the array may contain the same instance at different From d56795946c7b39fecf8bdcb5c91c190874f1e0fe Mon Sep 17 00:00:00 2001 From: tpaviot Date: Fri, 17 Feb 2012 18:50:26 +0100 Subject: [PATCH 07/19] Improvements in the aggregates support and Part21 importer as well --- .../python/SCL/AggregationDataTypes.py | 8 +- src/fedex_python/python/SCL/Part21.py | 93 +++---------------- src/fedex_python/python/SCL/TypeChecker.py | 19 +++- src/fedex_python/python/SCL/as1.stp | 35 ------- src/fedex_python/python/SCL/essa_par.py | 52 +++++++---- src/fedex_python/python/SCL_unittest.py | 10 +- src/fedex_python/src/classes_python.c | 62 +++++++++++-- 7 files changed, 137 insertions(+), 142 deletions(-) delete mode 100644 src/fedex_python/python/SCL/as1.stp diff --git a/src/fedex_python/python/SCL/AggregationDataTypes.py b/src/fedex_python/python/SCL/AggregationDataTypes.py index a841313f8..fe241f149 100644 --- a/src/fedex_python/python/SCL/AggregationDataTypes.py +++ b/src/fedex_python/python/SCL/AggregationDataTypes.py @@ -95,6 +95,12 @@ def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False, OPTIONAL=F list_size = bound_2 - bound_1 + 1 self._container = list_size*[None] + def bound_1(self): + return self._bound_1 + + def bound_2(self): + return self._bound_2 + def __getitem__(self, index): if index0 and not self._aggr_scope: - instance_attributes.append(self._aggregate_scope) - self._aggregate_scope = [] - elif len(self._aggregate_scope)>0 and self._aggr_scope: - pass - else: - instance_attributes.append(at) + print "instance_attributes:",instance_attributes a = object_(*instance_attributes) - - def map_express_to_python(self,attr): - """ Map EXPRESS to python""" - if attr in ["$","''"]: #optional argument - return None - elif attr.startswith('#'): #entity_id - return attr[1:] - else: - return map_string_to_num(attr) - if __name__ == "__main__": import time import sys - #sys.path.append("..") - #from config_control_design import * - #p21loader = Part21Loader("as1-oc-214.stp") - #file = Part21Loader("as1-tu-203.stp") - #file = Part21Loader("HAYON.stp") - p21loader = Part21Parser("as1.stp") - print p21loader._instances_definition - #print "Creating instances" - #p21population = Part21Population(p21loader) - #p21population.create_entity_instances() - #t2 = time.time() - #print "Creating instances took: %s s \n" % ((t2-t1)) \ No newline at end of file + from config_control_design import * + p21loader = Part21Parser("gasket1.p21") + print "Creating instances" + p21population = Part21Population(p21loader) diff --git a/src/fedex_python/python/SCL/TypeChecker.py b/src/fedex_python/python/SCL/TypeChecker.py index 86ba17b52..e8c40e0c5 100644 --- a/src/fedex_python/python/SCL/TypeChecker.py +++ b/src/fedex_python/python/SCL/TypeChecker.py @@ -31,6 +31,17 @@ from ConstructedDataTypes import ENUMERATION, SELECT +RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH = False + +def cast_python_list_to_aggregate(lst, aggregate): + """ This function casts a python list to an aggregate type. For instance: + [1.,2.,3.]-> ARRAY(1,3,REAL)""" + aggregate_lower_bound = aggregate.bound_1() + aggregate_upper_bound = aggregate.bound_2() + for idx in range(aggregate_lower_bound,aggregate_upper_bound+1): + aggregate[idx] = lst[idx-aggregate_lower_bound] + return aggregate + def check_type(instance, expected_type): """ This function checks wether an object is an instance of a given class returns False or True @@ -46,8 +57,10 @@ def check_type(instance, expected_type): else: type_match = isinstance(instance,expected_type) if not type_match: - raise TypeError('Type of argument number_of_sides must be %s (you passed %s)'%(expected_type,type(instance))) + if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH: + raise TypeError('Type of argument number_of_sides must be %s (you passed %s)'%(expected_type,type(instance))) + else: + print "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(expected_type, type(instance)) + return False else: return True - - \ No newline at end of file diff --git a/src/fedex_python/python/SCL/as1.stp b/src/fedex_python/python/SCL/as1.stp deleted file mode 100644 index c2f1c219d..000000000 --- a/src/fedex_python/python/SCL/as1.stp +++ /dev/null @@ -1,35 +0,0 @@ -ISO-10303-21; -HEADER; -FILE_DESCRIPTION(('Open CASCADE Model'),'2;1'); -FILE_NAME('Open CASCADE Shape Model','2008-07-24T15:00:20',( - '--- Datakit Converter ---'),('--- Datakit www.datakit.com---'), - ' Release Version Jun 30 2008','Open CASCADE 6.1',' '); -FILE_SCHEMA(('AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }')); -ENDSEC; -DATA; -#1 = APPLICATION_PROTOCOL_DEFINITION('international standard', - 'automotive_design',2000,#2); -#2 = APPLICATION_CONTEXT( - 'core data for automotive mechanical design processes'); -#3 = SHAPE_DEFINITION_REPRESENTATION(#4,#10); -#4 = PRODUCT_DEFINITION_SHAPE('$','$',#5); -#5 = PRODUCT_DEFINITION('design','',#6,#9); -#6 = PRODUCT_DEFINITION_FORMATION('','',#7); -#7 = PRODUCT('as1','as1','',(#8)); -#8 = PRODUCT_CONTEXT('',#2,'mechanical'); -#9 = PRODUCT_DEFINITION_CONTEXT('part definition',#2,'design'); -#10 = SHAPE_REPRESENTATION('',(#11,#15,#19,#23,#27),#31); -#11 = AXIS2_PLACEMENT_3D('',#12,#13,#14); -#12 = CARTESIAN_POINT('',(0.E+000,0.E+000,0.E+000)); -#13 = DIRECTION('',(0.E+000,0.E+000,1.)); -#14 = DIRECTION('',(1.,0.E+000,0.E+000)); -#15 = AXIS2_PLACEMENT_3D('',#16,#17,#18); -#16 = CARTESIAN_POINT('',(-10.,75.,60.)); -#17 = DIRECTION('',(1.,0.E+000,0.E+000)); -#18 = DIRECTION('',(0.E+000,0.E+000,-1.)); -#19 = AXIS2_PLACEMENT_3D('',#20,#21,#22); -#20 = CARTESIAN_POINT('',(5.,125.,20.)); -#21 = DIRECTION('',(0.E+000,0.E+000,1.)); -#22 = DIRECTION('',(1.,0.E+000,0.E+000)); -ENDSEC; -END-ISO-10303-21; diff --git a/src/fedex_python/python/SCL/essa_par.py b/src/fedex_python/python/SCL/essa_par.py index 376aa8875..00f75957f 100644 --- a/src/fedex_python/python/SCL/essa_par.py +++ b/src/fedex_python/python/SCL/essa_par.py @@ -19,36 +19,56 @@ def process_nested_parent_str(attr_str): current_param += ch return params -idx = 0 -def process_nested_parent_str2(attr_str): +def process_nested_parent_str2(attr_str,idx=0): ''' The first letter should be a parenthesis input string: "(1,4,(5,6),7)" output: ['1','4',['5','6'],'7'] ''' - global idx - acc=0 - print 'Entering function with string %s and index %i'%(attr_str,idx) + #print 'Entering function with string %s'%(attr_str) params = [] current_param = '' - for i,ch in enumerate(attr_str): - idx += 1 - acc +=1 + k = 0 + while (ktype) { + case array_: + fprintf(file,"ARRAY"); + break; + case bag_: + fprintf(file,"BAG"); + break; + case set_: + fprintf(file,"SET"); + break; + case list_: + fprintf(file,"LIST"); + break; + default: + break; + } +} + /* * * A recursive function to export aggregate to python @@ -721,6 +747,7 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { // fset fprintf(file,"\t\tdef fset( self, value ):\n"); t = VARget_type( v ); + attr_type = GetAttrTypeName(t); if (!VARis_derived(v) && !VARget_inverse(v)) { @@ -729,21 +756,42 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { fprintf(file, "\t\t# Mandatory argument\n"); fprintf(file,"\t\t\tif value==None:\n"); fprintf(file,"\t\t\t\traise AssertionError('Argument %s is mantatory and can not be set to None')\n",attrnm); + fprintf(file,"\t\t\tif not check_type(value,"); + if( TYPEis_aggregate( t ) ) { + process_aggregate(file,t); + fprintf(file,"):\n"); + } + else { + fprintf(file,"%s):\n",attr_type); + } } else { fprintf(file,"\t\t\tif value != None: # OPTIONAL attribute\n\t"); + fprintf(file,"\t\t\tif not check_type(value,"); + if( TYPEis_aggregate( t ) ) { + process_aggregate(file,t); + fprintf(file,"):\n\t"); + } + else { + fprintf(file,"%s):\n\t",attr_type); + } } // check wether attr_type is aggr or explicit if( TYPEis_aggregate( t ) ) { - fprintf(file,"\t\t\tcheck_type(value,"); - process_aggregate(file,t); - fprintf(file,")\n"); + //fprintf(file,"\t\t\tcheck_type(value,"); + //process_aggregate(file,t); + //fprintf(file,")\n"); + 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\tcheck_type(value,"); - //printf(attr_type); - //is_python_keyword(attr_type);// printf("pou"); - fprintf(file,"%s)\n",attr_type); + //fprintf(file,"\t\t\tif not check_type(value,"); + //fprintf(file,"%s):\n",attr_type); + fprintf(file, "\t\t\t\tself._%s = %s(value)\n",attrnm,attr_type); + fprintf(file, "\t\t\telse:\n\t"); + // try to cas } fprintf(file,"\t\t\tself._%s = value\n",attrnm); } From 50b9032d3202a3f76fb18dd22fd336497b8b9e4c Mon Sep 17 00:00:00 2001 From: tpaviot Date: Sat, 18 Feb 2012 20:09:55 +0100 Subject: [PATCH 08/19] LIST better implementation --- .../python/SCL/AggregationDataTypes.py | 54 +++++++++++++++++- .../python/SCL/SimpleDataTypes.pyc | Bin 7815 -> 7165 bytes src/fedex_python/python/SCL/TypeChecker.py | 9 +-- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/fedex_python/python/SCL/AggregationDataTypes.py b/src/fedex_python/python/SCL/AggregationDataTypes.py index fe241f149..437936b86 100644 --- a/src/fedex_python/python/SCL/AggregationDataTypes.py +++ b/src/fedex_python/python/SCL/AggregationDataTypes.py @@ -126,16 +126,64 @@ def __setitem__(self, index, value): raise AssertionError("UNIQUE keyword prevent inserting this instance.") self._container[index-self._bound_1] = value -class LIST(list, BaseAggregate): +class LIST(object): """A list data type has as its domain sequences of like elements. The optional lower and upper bounds, which are integer-valued expressions, define the minimum and maximum number of elements that can be held in the collection defined by a list data type. A list data type definition may optionally specify that a list value cannot contain duplicate elements. """ - def __init__( self , bound1 , bound2 , base_type ): - BaseAggregate.__init__( self , bound1 , bound2 , base_type ) + def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False): + if not type(bound_1)==int: + raise TypeError("LIST lower bound must be an integer") + # bound_2 can be set to None + if not type(bound_2)==int: + raise TypeError("LIST upper bound must be an integer") + if not bound_1>=0: + raise AssertionError("LIST lower bound must be greater of equal to 0") + if not (bound_1 <= bound_2): + raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") + # set up class attributes + self._bound_1 = bound_1 + self._bound_2 = bound_2 + self._base_type = base_type + self._unique = UNIQUE + self._optional = OPTIONAL + # preallocate list elements + list_size = bound_2 - bound_1 + 1 + self._container = list_size*[None] + def bound_1(self): + return self._bound_1 + + def bound_2(self): + return self._bound_2 + + def __getitem__(self, index): + if indexself._bound_2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + else: + value = self._container[index-self._bound_1] + if not self._optional and value==None: + raise AssertionError("Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first."%index) + return value + + def __setitem__(self, index, value): + if indexself._bound_2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + else: + # first check the type of the value + check_type(value,self._base_type) + # then check if the value is already in the array + if self._unique: + if value in self._container: + raise AssertionError("UNIQUE keyword prevent inserting this instance.") + self._container[index-self._bound_1] = value + class BAG(tuple, BaseAggregate): """A bag data type has as its domain unordered collections of like elements. The optional lower and upper bounds, which are integer-valued expressions, de ne the minimum and maximum diff --git a/src/fedex_python/python/SCL/SimpleDataTypes.pyc b/src/fedex_python/python/SCL/SimpleDataTypes.pyc index 6a9b3e0e057bbd66450647e1e7699f98df1810c3..82038bef6851d4982a9015e460679b1c18a0bd34 100644 GIT binary patch delta 145 zcmZp-{cFyC@e?nXw~zfs_9$i+AqED9$%b;`llL-*LO6_q!ke>LzOW#8+c>2e5j;)q s$*f@BW=6q(NaEqb$q@0$AQOZnqnY4(CLfiKhI2Mo$do{}8OntL0Qh$twg3PC delta 763 zcmexs-fqi&@e?oC4sW}S>`~0F!3+!x`k}?CMaB9h8Tq-1#riI(WvMy(!6m5$&N+$2 z#XgxyMTtd~`o%@b`e~^tsTJ`Bl|Yqw`cNv^*++kJDsv8XOxk>vnVpqNMm^xrW2BN% vLR`zJ<*GgW|ET4veS&4wa+QU69usxKYVs<{JnERVSw^azN ARRAY(1,3,REAL)""" aggregate_lower_bound = aggregate.bound_1() aggregate_upper_bound = aggregate.bound_2() - for idx in range(aggregate_lower_bound,aggregate_upper_bound+1): - aggregate[idx] = lst[idx-aggregate_lower_bound] + if type(obj)==list: + for idx in range(aggregate_lower_bound,aggregate_upper_bound+1): + aggregate[idx] = obj[idx-aggregate_lower_bound] return aggregate def check_type(instance, expected_type): From d87d07a26c84f26ef62b06d216678e5f5b03b113 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Sun, 19 Feb 2012 08:29:38 +0100 Subject: [PATCH 09/19] Added Model module/class --- src/fedex_python/python/SCL/Model.py | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/fedex_python/python/SCL/Model.py diff --git a/src/fedex_python/python/SCL/Model.py b/src/fedex_python/python/SCL/Model.py new file mode 100644 index 000000000..9a3f0e87b --- /dev/null +++ b/src/fedex_python/python/SCL/Model.py @@ -0,0 +1,55 @@ +# Copyright (c) 2011-2012, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +class Model(objet): + """ The container for entity instances + """ + def __init_(self): + print "Model initialized" + self._instances = [] + + def add_instance(self, entity_instance): + self._instances.append(entity_instance) + + def remove_instance(self, entity_instance): + self._instances.remove(entity_instance) + + def get_instances(self): + return self._instances + + def export_to_p21file(self, filename): + raise AssertionError("Not implemented") + + def export_to_p28file(self, filename): + raise AssertionError("Not implemented") + + + From 5f88f509b27d06612ec613ab361f7fc9d3deb26b Mon Sep 17 00:00:00 2001 From: tpaviot Date: Sun, 19 Feb 2012 23:47:59 +0100 Subject: [PATCH 10/19] Improved docstring for aggregate --- src/fedex_python/src/classes_python.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/fedex_python/src/classes_python.c b/src/fedex_python/src/classes_python.c index 5db4b79f7..94a4c564a 100644 --- a/src/fedex_python/src/classes_python.c +++ b/src/fedex_python/src/classes_python.c @@ -649,7 +649,15 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { generate_attribute_name( v, attrnm ); t = VARget_type( v ); fprintf(file,"\n\t:param %s\n",attrnm); - fprintf(file,"\t:type %s:%s\n",attrnm, GetAttrTypeName(t)); + //fprintf(file,"\t:type %s:%s\n",attrnm, GetAttrTypeName(t)); + fprintf(file,"\t:type %s:",attrnm); + if( TYPEis_aggregate( t ) ) { + process_aggregate(file,t); + fprintf(file,"\n"); + } + else { + fprintf(file,"%s\n",GetAttrTypeName(t)); + } attr_count_tmp++; LISTod fprintf(file,"\t'''\n"); From d6da97ec30b882d5b830e86211e844ebcee510f4 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Sun, 19 Feb 2012 23:51:09 +0100 Subject: [PATCH 11/19] Small spelling fix --- .../python/SCL/SimpleDataTypes.pyc | Bin 7165 -> 7815 bytes src/fedex_python/python/SCL/__init__.pyc | Bin 259 -> 320 bytes src/fedex_python/src/classes_python.c | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fedex_python/python/SCL/SimpleDataTypes.pyc b/src/fedex_python/python/SCL/SimpleDataTypes.pyc index 82038bef6851d4982a9015e460679b1c18a0bd34..c24617749bd3e16c02f6ddbc9fcf2526b181e9a7 100644 GIT binary patch delta 763 zcmexs-fqi&@e?oCrV7W6>`~0F!3+!x`k}?CMaB9h8Tq-1#riI(WvMy(!6m5$&N+$2 z#XgxyMTtd~`o%@b`e~^tsTJ`Bl|Yqw`cNv^*++kJDsv8XOxk>vnVpqNMm^xrW2BN% vLR`zJ<*GgW|ET4veS&4wa+QU69usxKYVs<{JnERVSw^azNKPIF delta 145 zcmZp-{cFyC@e?nXw~zfs_9$i+AqED9$%b;`llL-*LO6_q!ke>LzOW#8+c>2e5j;)q s$*f@BW=6q(NaEqb$q@0$AQOZnqnY4(CLfiKhI2Mo$do{}8OntL0Qh$twg3PC diff --git a/src/fedex_python/python/SCL/__init__.pyc b/src/fedex_python/python/SCL/__init__.pyc index 86f73b2053fa29def2e59b0a5bf9abed8048b92d..36ca58348cd9430a16921ee3a3ec73d85677cc23 100644 GIT binary patch delta 84 zcmZo>I>5w!@e?oCrV7W2?3W#V7#JAzLyJ?3iuFq}@^cf5^<7fSQgif!OHvD*a}tY- heKM1Z5{oMJi;I%=(^6AXE8+_(fhzO#q142CssIEXAA|q^ delta 24 fcmX@W)Xc2p_RB2%3=9mDr5RNLUup(j diff --git a/src/fedex_python/src/classes_python.c b/src/fedex_python/src/classes_python.c index 94a4c564a..93735f42c 100644 --- a/src/fedex_python/src/classes_python.c +++ b/src/fedex_python/src/classes_python.c @@ -508,7 +508,7 @@ GetAttrTypeName(Type t) { } else if (TYPEis_logical(t)) { - attr_type = "LOGCIAL"; + attr_type = "LOGICAL"; } else if (TYPEis_boolean(t)) { From 37594fc4a2e870bf1cbc46c0445e9230cc28127a Mon Sep 17 00:00:00 2001 From: tpaviot Date: Mon, 20 Feb 2012 06:46:00 +0100 Subject: [PATCH 12/19] Code clean-up: remove unused code --- src/fedex_python/src/classes_python.c | 1293 +------------------------ 1 file changed, 3 insertions(+), 1290 deletions(-) diff --git a/src/fedex_python/src/classes_python.c b/src/fedex_python/src/classes_python.c index 93735f42c..4d0735898 100644 --- a/src/fedex_python/src/classes_python.c +++ b/src/fedex_python/src/classes_python.c @@ -413,39 +413,6 @@ ENTITYhead_print( Entity entity, FILE * file, Schema schema ) { fprintf( file, " public SCLP23(Application_instance) {\n" ); } -#if 0 - /* this code is old non-working multiple inheritance code */ - - list = ENTITYget_supertypes( entity ); - if( ! LISTempty( list ) ) { - LISTdo( list, e, Entity ) - /* if there\'s no super class yet, - or the super class doesn\'t have any attributes - */ - if( ( ! super ) || ( ! ENTITYhas_explicit_attributes( super ) ) ) { - super = e; - ++ super_cnt; - } else { - printf( "WARNING: multiple inheritance not implemented.\n" ); - printf( "\tin ENTITY %s\n\tSUPERTYPE %s IGNORED.\n\n", - ENTITYget_name( entity ), ENTITYget_name( e ) ); - } - LISTod; - fprintf( file, " public %s {\n ", ENTITYget_classname( super ) ); - - /* for multiple inheritance - LISTdo (list, e, Entity) - sprintf (buf, " public %s, ", ENTITYget_classname (e)); - move (buf); - LISTod; - sprintf (buf - 2, " {\n"); - move (buf); - fprintf(file,buffer); - */ - } else { /* if entity has no supertypes, it's at top of hierarchy */ - fprintf( file, " public SCLP23(Application_instance) {\n" ); - } -#endif } @@ -604,7 +571,7 @@ process_aggregate (FILE *file, Type t) { void LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { - int attr_count_tmp = attr_count;//, attr_count_tmp2 = 0; + int attr_count_tmp = attr_count; char attrnm [BUFSIZ], parent_attrnm[BUFSIZ]; char * attr_type; bool generate_constructor = true; //by default, generates a python constructor @@ -631,7 +598,6 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { if (num_parent > 0) fprintf(file,","); //separator for parent classes names if (is_python_keyword(ENTITYget_name(e))) {fprintf(file,"%s_",ENTITYget_name(e));} else {fprintf(file,"%s",ENTITYget_name(e));} - //fprintf( file, "\t/* parent: %s */\n", ENTITYget_name( e ) ); num_parent++; LISTod; } @@ -649,7 +615,6 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { generate_attribute_name( v, attrnm ); t = VARget_type( v ); fprintf(file,"\n\t:param %s\n",attrnm); - //fprintf(file,"\t:type %s:%s\n",attrnm, GetAttrTypeName(t)); fprintf(file,"\t:type %s:",attrnm); if( TYPEis_aggregate( t ) ) { process_aggregate(file,t); @@ -665,7 +630,7 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { * Before writing constructor, check if this entity has any attribute * other wise just a 'pass' statement is enough */ - attr_count_tmp = 0;//attr_count; + attr_count_tmp = 0; int num_derived_inverse_attr = 0; LISTdo(ENTITYget_attributes( entity ), v, Variable) if (VARis_derived(v) || VARget_inverse(v)) { @@ -693,11 +658,8 @@ LIBdescribe_entity( Entity entity, FILE * file, Schema schema ) { int num_parent = 0, index_attribute = 0; if( ! LISTempty( list ) ) { LISTdo( list, e, Entity ) - //num_attributes = get_local_attribute_number(e); //number of attributes for the current superclass - //index_attribute = 0; /* search attribute names for superclass */ LISTdo(ENTITYget_attributes( e ), v2, Variable) - //if (index_attribute set_null ();\n" ); - - /* 3. put attribute on attributes list */ - fprintf( file, " attributes.push (a);\n" ); - - /* if it is redefining another attribute make connection of - redefined attribute to redefining attribute */ - if( VARis_type_shifter( a ) ) { - fprintf( file, " MakeRedefined(a, \"%s\");\n", - VARget_simple_name( a ) ); - } - } - count++; - } - - LISTod; - - attr_list = ENTITYget_all_attributes( entity ); - - LISTdo( attr_list, a, Variable ) - /* if (VARis_overrider (entity, a)) { */ - if( VARis_derived( a ) ) { - fprintf( file, " MakeDerived (\"%s\");\n", - VARget_simple_name( a ) ); - } - LISTod; - fprintf( file, "}\n" ); - - /* copy constructor */ - /* LIBcopy_constructor (entity, file); */ - entnm = ENTITYget_classname( entity ); - fprintf( file, "%s::%s (%s& e ) \n", entnm, entnm, entnm ); - fprintf( file, "\t{ CopyAs((SCLP23(Application_instance_ptr)) &e);\t}\n" ); - - /* print destructor */ - /* currently empty, but should check to see if any attributes need - to be deleted -- attributes will need reference count */ - - entnm = ENTITYget_classname( entity ); - fprintf( file, "%s::~%s () { }\n", entnm, entnm ); - - /* Open OODB reInit function */ - fprintf( file, "\n#ifdef __O3DB__\n" ); - fprintf( file, "void \n%s::oodb_reInit ()\n{", entnm ); - fprintf( file, "\teDesc = %s%s%s;\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - - count = attr_count; - attr_list = ENTITYget_attributes( entity ); - index = get_attribute_number( entity ); - - LISTdo( attr_list, a, Variable ) - /* if the attribute is Explicit, assign the Descriptor */ - if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) { - generate_attribute_name( a, attrnm ); - /* 1. assign the Descriptor for the STEPattributes */ - fprintf( file, "\tattributes [%d].aDesc = %s%d%s%s;\n", - index, - ATTR_PREFIX, count, - ( VARis_type_shifter( a ) ? "R" : "" ), - attrnm ); - } - index++, - count++; - LISTod; - fprintf( file, "}\n" - "#endif\n\n" ); - - } /********************/ @@ -1114,196 +829,7 @@ LIBstructor_print( Entity entity, FILE * file, Schema schema ) { void LIBstructor_print_w_args( Entity entity, FILE * file, Schema schema ) { - Linked_List attr_list; - Type t; - char attrnm [BUFSIZ]; - - Linked_List list; - __attribute__( ( unused ) ) Entity super = 0; - int super_cnt = 0; - - /* added for calling parents constructor if there is one */ - char parentnm [BUFSIZ]; - char * parent = 0; - Entity parentEntity = 0; - - const char * entnm; - int count = attr_count; - int first = 1; - - if( multiple_inheritance ) { - - /* //////////// */ - list = ENTITYget_supertypes( entity ); - if( ! LISTempty( list ) ) { - parentEntity = ( Entity )LISTpeek_first( list ); - if( parentEntity ) { - strcpy( parentnm, ENTITYget_classname( parentEntity ) ); - parent = parentnm; - } else { - parent = 0; /* no parent */ - } - } else { - parent = 0; /* no parent */ - } - - /* ENTITYget_classname returns a static buffer so don't call it twice - before it gets used - (I didn't write it) - I had to move it below - the above use. DAS */ - entnm = ENTITYget_classname( entity ); - /* constructor definition */ - if( parent ) - fprintf( file, "%s::%s (SCLP23(Application_instance) *se, int *addAttrs) : %s(se, (addAttrs ? &addAttrs[1] : 0)) \n", entnm, entnm, - parentnm ); - else { - fprintf( file, "%s::%s( SCLP23(Application_instance) *se, int *addAttrs)\n", entnm, entnm ); - } - - fprintf( file, "{\n" ); - - /* ////MULTIPLE INHERITANCE//////// */ - /* super = ENTITYput_superclass (entity); */ - - fprintf( file, "\t/* Set this to point to the head entity. */\n" ); - fprintf( file, " HeadEntity(se); \n" ); - - fprintf( file, "\n" ); - list = ENTITYget_supertypes( entity ); - if( ! LISTempty( list ) ) { - LISTdo( list, e, Entity ) - /* if there\'s no super class yet, - or the super class doesn\'t have any attributes - */ - fprintf( file, "\t/* parent: %s */\n", ENTITYget_classname( e ) ); - - super = e; - super_cnt++; - if( super_cnt == 1 ) { - /* ignore the 1st parent */ - fprintf( file, - "\t/* Ignore the first parent since it is */\n %s\n", - "\t/* part of the main inheritance hierarchy */" ); - } else { - fprintf( file, "#if 0 \n" ); - fprintf( file, - "\t/* Optionally use the following to replace the line following \n" ); - fprintf( file, - "\t the endif. Use this to turn off adding attributes in \n" ); - fprintf( file, - "\t diamond shaped hierarchies for each additional parent at this\n" ); - fprintf( file, - "\t level. You currently must hand edit this for it to work. */\n" ); - fprintf( file, " int attrFlags[3]; // e.g. \n" ); - fprintf( file, " attrFlags[0] = 1; // add parents attrs\n" ); - fprintf( file, - " attrFlags[1] = 1; // add parent of parents attrs\n" ); - fprintf( file, - " attrFlags[2] = 0; // do not add parent of parent of parents attrs\n" ); - fprintf( file, - " // In *imaginary* hierarchy turn off attrFlags[2] since it \n" ); - fprintf( file, - " // would be the parent that has more than one path to it.\n" ); - fprintf( file, - " se->AppendMultInstance(new %s(se, attrFlags)); \n", - ENTITYget_classname( e ) ); - fprintf( file, "#endif \n" ); - fprintf( file, " se->AppendMultInstance(new %s(se, 0)); \n", - ENTITYget_classname( e ) ); - /* printf("\tin ENTITY %s\n\thandling SUPERTYPE %s cp wArgs\n\n", - ENTITYget_name (entity), ENTITYget_name (e));*/ - } - LISTod; - - } else { /* if entity has no supertypes, it's at top of hierarchy */ - fprintf( file, "\t/* no SuperTypes */\n" ); - } - - /* ////MULTIPLE INHERITANCE//////// */ - - /* attributes */ - /* fprintf (file, "\n STEPattribute * a;\n");*/ - - /* what if entity comes from other schema? */ - fprintf( file, "\n eDesc = %s%s%s;\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - - attr_list = ENTITYget_attributes( entity ); - - LISTdo( attr_list, a, Variable ) - if( VARget_initializer( a ) == EXPRESSION_NULL ) { - /* include attribute if it is not derived */ - generate_attribute_name( a, attrnm ); - t = VARget_type( a ); - - /* 1. declare the AttrDescriptor */ - /* this is now in the header */ - /* fprintf(file,"extern AttrDescriptor *%s%d%s;\n",*/ - /* ATTR_PREFIX,count,VARget_name(a));*/ - - /* if the attribute is Explicit, make a STEPattribute */ - /* if (VARis_simple_explicit (a)) {*/ - if( ( ! VARget_inverse( a ) ) && ( ! VARis_derived( a ) ) ) { - /* 1. create a new STEPattribute */ - - fprintf( file, " " - "%sa = new STEPattribute(*%s%d%s%s, %s &_%s);\n", - ( first ? "STEPattribute *" : "" ), - /* first time through declare a */ - ATTR_PREFIX, count, - ( VARis_type_shifter( a ) ? "R" : "" ), - attrnm, - ( TYPEis_entity( t ) ? "(SCLP23(Application_instance_ptr) *)" : "" ), - attrnm ); - - if( first ) { - first = 0 ; - } - /* 2. initialize everything to NULL (even if not optional) */ - - fprintf( file, " a -> set_null ();\n" ); - - fprintf( file, - "\t/* Put attribute on this class' %s\n", - "attributes list so the */\n\t/*access functions still work. */" ); - /* 3. put attribute on this class' attributes list so the - access functions still work */ - fprintf( file, " attributes.push (a);\n" ); - fprintf( file, - "\t/* Put attribute on the attributes list %s\n", - "for the */\n\t/* main inheritance heirarchy. */" ); - /* ////MULTIPLE INHERITANCE//////// */ - /* 4. put attribute on attributes list for the main - inheritance heirarchy */ - fprintf( file, " if(!addAttrs || addAttrs[0])\n" ); - fprintf( file, " se->attributes.push (a);\n" ); - - /* if it is redefining another attribute make connection of - redefined attribute to redefining attribute */ - if( VARis_type_shifter( a ) ) { - fprintf( file, " MakeRedefined(a, \"%s\");\n", - VARget_simple_name( a ) ); - } - /* ////MULTIPLE INHERITANCE//////// */ - } - count++; - } - - LISTod; - - attr_list = ENTITYget_all_attributes( entity ); - - LISTdo( attr_list, a, Variable ) - /* if (VARis_overrider (entity, a)) { */ - if( VARis_derived( a ) ) { - fprintf( file, " MakeDerived (\"%s\");\n", - VARget_simple_name( a ) ); - } - LISTod; - fprintf( file, "}\n" ); - } /* end if(multiple_inheritance) */ - } -/********************/ /****************************************************************** ** Procedure: ENTITYlib_print @@ -1316,15 +842,9 @@ LIBstructor_print_w_args( Entity entity, FILE * file, Schema schema ) { ** Side Effects: generates code segment for c++ library file ** Status: ok 1/15/91 ******************************************************************/ - void ENTITYlib_print( Entity entity, FILE * file, Schema schema ) { LIBdescribe_entity( entity, file, schema ); - //LIBstructor_print( entity, file, schema ); - //if( multiple_inheritance ) { - // LIBstructor_print_w_args( entity, file, schema ); - //} - //LIBmemberFunctionPrint( entity, file ); } //FIXME should return bool @@ -1347,326 +867,13 @@ TYPEis_builtin( const Type t ) { return 0; } -/* go down through a type'sbase type chain, - Make and print new TypeDescriptors for each type with no name. - - This function should only be called for types that don't have an - associated Express name. Currently this only includes aggregates. - If this changes this function needs to be changed to support the type - that changed. This function prints TypeDescriptors for types - without names and it will go down through the type chain until it hits - a type that has a name. i.e. when it hits a type with a name it stops. - There are only two places where a type can not have a name - both - cases are aggregate types. - 1. an aggregate created in an attr declaration - e.g. names : ARRAY [1:3] of STRING; - 2. an aggregate that is an element of another aggregate. - e.g. TYPE Label = STRING; END_TYPE; - TYPE listSetOfLabel = LIST of SET of Label; END_TYPE; - LIST of SET of Label has a name i.e. listSetOfReal - SET of Label does not have a name and this function should be called - to generate one. - This function will not generate the code to handle Label. - - Type t contains the Type with no Express name that needs to have - TypeDecriptor[s] generated for it. - buf needs to have space declared enough to hold the name of the var - that can be referenced to refer to the type that was created for - Type t. -*/ + void print_typechain( FILE * f, const Type t, char * buf, Schema schema ) { } -/****************************************************************** - ** Procedure: ENTITYincode_print - ** Parameters: Entity *entity -- entity being processed - ** FILE* file -- file being written to - ** Returns: - ** Description: generates code to enter entity in STEP registry - ** This goes to the .init.cc file - ** Side Effects: - ** Status: ok 1/15/91 - ******************************************************************/ void ENTITYincode_print( Entity entity, FILE * file, Schema schema ) { -#define entity_name ENTITYget_name(entity) -#define schema_name SCHEMAget_name(schema) - char attrnm [BUFSIZ]; - char dict_attrnm [BUFSIZ]; - const char * super_schema; - char * tmp, *tmp2; - -#ifdef NEWDICT - /* DAS New SDAI Dictionary 5/95 */ - /* insert the entity into the schema descriptor */ - fprintf( file, - "\t((SDAIAGGRH(Set,EntityH))%s%s->Entities())->Add(%s%s%s);\n", - SCHEMA_PREFIX, schema_name, schema_name, ENT_PREFIX, entity_name ); -#endif - - if( ENTITYget_abstract( entity ) ) { - fprintf( file, "\t%s%s%s->AddSupertype_Stmt(\"", - schema_name, ENT_PREFIX, entity_name ); - if( entity->u.entity->subtype_expression ) { - fprintf( file, "ABSTRACT SUPERTYPE OF (" ); - tmp = SUBTYPEto_string( entity->u.entity->subtype_expression ); - tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); - fprintf( file, "%s)\");\n", format_for_stringout( tmp, tmp2 ) ); - free( tmp ); - free( tmp2 ); - } else { - fprintf( file, "ABSTRACT SUPERTYPE\");\n" ); - } - } else { - if( entity->u.entity->subtype_expression ) { - fprintf( file, "\t%s%s%s->AddSupertype_Stmt(\"", - schema_name, ENT_PREFIX, entity_name ); - fprintf( file, "SUPERTYPE OF (" ); - tmp = SUBTYPEto_string( entity->u.entity->subtype_expression ); - tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); - fprintf( file, "%s)\");\n", format_for_stringout( tmp, tmp2 ) ); - free( tmp ); - free( tmp2 ); - } - } - /* - if (entity->u.entity->subtype_expression) { - tmp = SUBTYPEto_string(entity->u.entity->subtype_expression); - tmp2 = (char*)malloc( sizeof(char) * (strlen(tmp)+BUFSIZ) ); - fprintf(file,"\t%s%s%s->AddSupertype_Stmt(\"(%s)\");\n", - schema_name,ENT_PREFIX,entity_name,format_for_stringout(tmp,tmp2)); - free(tmp); - free(tmp2); - } - */ - /* - LISTdo(ENTITYget_subtypes(entity),sub,Entity) - fprintf(file," %s%s%s->AddSubtype(%s%s%s);\n", - schema_name,ENT_PREFIX,entity_name, - schema_name,ENT_PREFIX,ENTITYget_name(sub)); - LISTod - */ - LISTdo( ENTITYget_supertypes( entity ), sup, Entity ) - /* set the owning schema of the supertype */ - super_schema = SCHEMAget_name( ENTITYget_schema( sup ) ); - /* print the supertype list for this entity */ - fprintf( file, " %s%s%s->AddSupertype(%s%s%s);\n", - schema_name, ENT_PREFIX, entity_name, - super_schema, - ENT_PREFIX, ENTITYget_name( sup ) ); - - /* add this entity to the subtype list of it's supertype */ - fprintf( file, " %s%s%s->AddSubtype(%s%s%s);\n", - super_schema, - ENT_PREFIX, ENTITYget_name( sup ), - schema_name, ENT_PREFIX, entity_name ); - LISTod - - LISTdo( ENTITYget_attributes( entity ), v, Variable ) - generate_attribute_name( v, attrnm ); - /* do EXPLICIT and DERIVED attributes first */ - /* if ( ! VARget_inverse (v)) {*/ - /* first make sure that type descriptor exists */ - if( TYPEget_name( v->type ) ) { - if( ( !TYPEget_head( v->type ) ) && - ( TYPEget_body( v->type )->type == entity_ ) ) { - /* fprintf(file, "\t%s%d%s%s = new %sAttrDescriptor(\"%s\",%s%s%s,%s,%s,%s,*%s%s%s);\n", */ - fprintf( file, "\t%s%d%s%s =\n\t new %s" - "(\"%s\",%s%s%s,\n\t %s,%s%s,\n\t *%s%s%s);\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm, - - ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), - - /* attribute name param */ - generate_dict_attr_name( v, dict_attrnm ), - - /* following assumes we are not in a nested */ - /* entity otherwise we should search upward */ - /* for schema */ - /* attribute's type */ - TYPEget_name( - TYPEget_body( v->type )->entity->superscope ), - ENT_PREFIX, TYPEget_name( v->type ), - - ( VARget_optional( v ) ? "LTrue" : "LFalse" ), - - ( VARget_unique( v ) ? "LTrue" : "LFalse" ), - - /* Support REDEFINED */ - ( VARget_inverse( v ) ? "" : - ( VARis_derived( v ) ? ", AttrType_Deriving" : - ( VARis_type_shifter( v ) ? ", AttrType_Redefining" : ", AttrType_Explicit" ) ) ), - - schema_name, ENT_PREFIX, TYPEget_name( entity ) - ); - } else { - /* type reference */ - /* fprintf(file," %s%d%s%s = new %sAttrDescriptor(\"%s\",%s%s%s,%s,%s,%s,*%s%s%s);\n",*/ - fprintf( file, " %s%d%s%s =\n\t new %s" - "(\"%s\",%s%s%s,\n\t %s,%s%s,\n\t *%s%s%s);\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm, - - ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), - - /* attribute name param */ - generate_dict_attr_name( v, dict_attrnm ), - - SCHEMAget_name( v->type->superscope ), - TD_PREFIX, TYPEget_name( v->type ), - - ( VARget_optional( v ) ? "LTrue" : "LFalse" ), - - ( VARget_unique( v ) ? "LTrue" : "LFalse" ), - - ( VARget_inverse( v ) ? "" : - ( VARis_derived( v ) ? ", AttrType_Deriving" : - ( VARis_type_shifter( v ) ? ", AttrType_Redefining" : ", AttrType_Explicit" ) ) ), - - schema_name, ENT_PREFIX, TYPEget_name( entity ) - ); - } - } else if( TYPEis_builtin( v->type ) ) { - /* the type wasn\'t named -- it must be built in or aggregate */ - - /* fprintf(file," %s%d%s%s = new %sAttrDescriptor(\"%s\",%s%s,%s,%s,%s,*%s%s%s);\n",*/ - fprintf( file, " %s%d%s%s =\n\t new %s" - "(\"%s\",%s%s,\n\t %s,%s%s,\n\t *%s%s%s);\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm, - ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), - /* attribute name param */ - generate_dict_attr_name( v, dict_attrnm ), - /* not sure about 0 here */ TD_PREFIX, FundamentalType( v->type, 0 ), - ( VARget_optional( v ) ? "LTrue" : - "LFalse" ), - ( VARget_unique( v ) ? "LTrue" : - "LFalse" ), - ( VARget_inverse( v ) ? "" : - ( VARis_derived( v ) ? ", AttrType_Deriving" : - ( VARis_type_shifter( v ) ? - ", AttrType_Redefining" : - ", AttrType_Explicit" ) ) ), - schema_name, ENT_PREFIX, TYPEget_name( entity ) - ); - } else { - /* manufacture new one(s) on the spot */ - char typename_buf[MAX_LEN]; - print_typechain( file, v->type, typename_buf, schema ); - /* fprintf(file," %s%d%s%s = new %sAttrDescriptor(\"%s\",%s,%s,%s,%s,*%s%s%s);\n",*/ - fprintf( file, " %s%d%s%s =\n\t new %s" - "(\"%s\",%s,%s,%s%s,\n\t *%s%s%s);\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm, - ( VARget_inverse( v ) ? "Inverse_attribute" : ( VARis_derived( v ) ? "Derived_attribute" : "AttrDescriptor" ) ), - /* attribute name param */ - generate_dict_attr_name( v, dict_attrnm ), - typename_buf, - ( VARget_optional( v ) ? "LTrue" : - "LFalse" ), - ( VARget_unique( v ) ? "LTrue" : - "LFalse" ), - ( VARget_inverse( v ) ? "" : - ( VARis_derived( v ) ? ", AttrType_Deriving" : - ( VARis_type_shifter( v ) ? - ", AttrType_Redefining" : - ", AttrType_Explicit" ) ) ), - schema_name, ENT_PREFIX, TYPEget_name( entity ) - ); - } - - fprintf( file, " %s%s%s->Add%sAttr (%s%d%s%s);\n", - schema_name, ENT_PREFIX, TYPEget_name( entity ), - ( VARget_inverse( v ) ? "Inverse" : "Explicit" ), - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm ); - - if( VARis_derived( v ) && v->initializer ) { - tmp = EXPRto_string( v->initializer ); - tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) ); - fprintf( file, "\t%s%d%s%s->initializer_(\"%s\");\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm, format_for_stringout( tmp, tmp2 ) ); - free( tmp ); - free( tmp2 ); - } - if( VARget_inverse( v ) ) { - fprintf( file, "\t%s%d%s%s->inverted_attr_id_(\"%s\");\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), - attrnm, v->inverse_attribute->name->symbol.name ); - if( v->type->symbol.name ) { - fprintf( file, - "\t%s%d%s%s->inverted_entity_id_(\"%s\");\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, - v->type->symbol.name ); - fprintf( file, "// inverse entity 1 %s\n", v->type->symbol.name ); - } else { - /* fprintf(file,"// inverse entity %s",TYPE_body_out(v->type));*/ - switch( TYPEget_body( v->type )->type ) { - case entity_: - fprintf( file, - "\t%s%d%s%s->inverted_entity_id_(\"%s\");\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, - TYPEget_body( v->type )->entity->symbol.name ); - fprintf( file, "// inverse entity 2 %s\n", TYPEget_body( v->type )->entity->symbol.name ); - break; - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - fprintf( file, - "\t%s%d%s%s->inverted_entity_id_(\"%s\");\n", - ATTR_PREFIX, attr_count, - ( VARis_derived( v ) ? "D" : - ( VARis_type_shifter( v ) ? "R" : - ( VARget_inverse( v ) ? "I" : "" ) ) ), attrnm, - TYPEget_body( v->type )->base->symbol.name ); - fprintf( file, "// inverse entity 3 %s\n", TYPEget_body( v->type )->base->symbol.name ); - break; - default: - printf( "Error in %s, line %d: type %d not handled by switch statement.", __FILE__, __LINE__, TYPEget_body( v->type )->type ); - abort(); - } - } - } -attr_count++; - -LISTod - -fprintf( file, "\treg.AddEntity (*%s%s%s);\n", - schema_name, ENT_PREFIX, entity_name ); - -#undef schema_name } /****************************************************************** @@ -1693,297 +900,18 @@ ENTITYPrint( Entity entity, FILES * files, Schema schema ) { void MODELPrintConstructorBody( Entity entity, FILES * files, Schema schema /*, int index*/ ) { - const char * n; - DEBUG( "Entering MODELPrintConstructorBody for %s\n", n ); - - n = ENTITYget_classname( entity ); - - fprintf( files->lib, " eep = new SCLP23(Entity_extent);\n" ); - - - fprintf( files->lib, " eep->definition_(%s%s%s);\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - fprintf( files->lib, " _folders.Append(eep);\n\n" ); - - /* - fprintf (files->lib, " %s__set_var SdaiModel_contents_%s::%s_get_extents()\n", - n, SCHEMAget_name(schema), n); - - fprintf(files->create," %s%s%s = new EntityDescriptor(\"%s\",%s%s,%s, (Creator) create_%s);\n", - - PrettyTmpName (ENTITYget_name(entity)), - SCHEMA_PREFIX,SCHEMAget_name(schema), - (ENTITYget_abstract(entity)?"LTrue":"LFalse"), - ENTITYget_classname (entity) - ); - - - fprintf (files->lib, - "{\n return (%s__set_var)((_folders.retrieve(%d))->instances_());\n}\n", - n, index); - */ } void MODELPrint( Entity entity, FILES * files, Schema schema, int index ) { - - const char * n; - DEBUG( "Entering MODELPrint for %s\n", n ); - - n = ENTITYget_classname( entity ); - fprintf( files->lib, "\n%s__set_var SdaiModel_contents_%s::%s_get_extents()\n", - n, SCHEMAget_name( schema ), n ); - fprintf( files->lib, - "{\n return (%s__set_var)((_folders.retrieve(%d))->instances_());\n}\n", - n, index ); - /* - fprintf (files->lib, - "{\n return (%s__set_var)((_folders[%d])->instances_());\n}\n", - n, index); - */ - - /* //////////////// */ - /* - fprintf (files->inc, "\n/////////\t ENTITY %s\n\n", n); - ENTITYinc_print (entity, files -> inc,schema); - fprintf (files->inc, "\n/////////\t END_ENTITY %s\n\n", n); - - fprintf (files->lib, "\n/////////\t ENTITY %s\n\n", n); - ENTITYlib_print (entity, files -> lib,schema); - fprintf (files->lib, "\n/////////\t END_ENTITY %s\n\n", n); - - fprintf (files->init, "\n/////////\t ENTITY %s\n\n", n); - ENTITYincode_print (entity, files -> init, schema); - fprintf (files->init, "/////////\t END_ENTITY %s\n", n); - */ - DEBUG( "DONE MODELPrint\n" ) ; } -/* -getEntityDescVarName(Entity entity) -{ - SCHEMAget_name(schema),ENT_PREFIX,ENTITYget_name(entity), -} -*/ - -/* print in include file: class forward prototype, class typedefs, and - extern EntityDescriptor. `externMap' = 1 if entity must be instantiated - with external mapping (see Part 21, sect 11.2.5.1). */ void ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap ) { - const char * n; - Linked_List wheres; - /* char buf[BUFSIZ],buf2[BUFSIZ]; */ - char * whereRule, *whereRule_formatted = ""; - int whereRule_formatted_size = 0; - char * ptr, *ptr2; - char * uniqRule, *uniqRule_formatted; - Linked_List uniqs; - int i; - - fprintf( files->create, "\t%s%s%s = new EntityDescriptor(\n\t\t", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - fprintf( files->create, " \"%s\", %s%s, %s, ", - PrettyTmpName( ENTITYget_name( entity ) ), - SCHEMA_PREFIX, SCHEMAget_name( schema ), - ( ENTITYget_abstract( entity ) ? "LTrue" : - "LFalse" ) ); - fprintf( files->create, "%s,\n\t\t", externMap ? "LTrue" : - "LFalse" ); - - fprintf( files->create, " (Creator) create_%s );\n", - ENTITYget_classname( entity ) ); - /* add the entity to the Schema dictionary entry */ - fprintf( files->create, "\t%s%s->AddEntity(%s%s%s);\n", SCHEMA_PREFIX, SCHEMAget_name( schema ), SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - - wheres = TYPEget_where( entity ); - - if( wheres ) { - fprintf( files->create, - "\t%s%s%s->_where_rules = new Where_rule__list;\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - - LISTdo( wheres, w, Where ) - whereRule = EXPRto_string( w->expr ); - ptr2 = whereRule; - - if( whereRule_formatted_size == 0 ) { - whereRule_formatted_size = 3 * BUFSIZ; - whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); - } else if( ( strlen( whereRule ) + 300 ) > whereRule_formatted_size ) { - free( whereRule_formatted ); - whereRule_formatted_size = strlen( whereRule ) + BUFSIZ; - whereRule_formatted = ( char * )malloc( sizeof( char ) * whereRule_formatted_size ); - } - whereRule_formatted[0] = '\0'; - /* - printf("whereRule length: %d\n",strlen(whereRule)); - printf("whereRule_formatted size: %d\n",whereRule_formatted_size); - */ - if( w->label ) { - strcpy( whereRule_formatted, w->label->name ); - strcat( whereRule_formatted, ": (" ); - ptr = whereRule_formatted + strlen( whereRule_formatted ); - while( *ptr2 ) { - if( *ptr2 == '\n' ) { - ; - } else if( *ptr2 == '\\' ) { - *ptr = '\\'; - ptr++; - *ptr = '\\'; - ptr++; - - } else if( *ptr2 == '(' ) { - *ptr = '\\'; - ptr++; - *ptr = 'n'; - ptr++; - *ptr = '\\'; - ptr++; - *ptr = 't'; - ptr++; - *ptr = *ptr2; - ptr++; - } else { - *ptr = *ptr2; - ptr++; - } - ptr2++; - } - *ptr = '\0'; - - strcat( ptr, ");\\n" ); - } else { - /* no label */ - strcpy( whereRule_formatted, "(" ); - ptr = whereRule_formatted + strlen( whereRule_formatted ); - - while( *ptr2 ) { - if( *ptr2 == '\n' ) { - ; - } else if( *ptr2 == '\\' ) { - *ptr = '\\'; - ptr++; - *ptr = '\\'; - ptr++; - - } else if( *ptr2 == '(' ) { - *ptr = '\\'; - ptr++; - *ptr = 'n'; - ptr++; - *ptr = '\\'; - ptr++; - *ptr = 't'; - ptr++; - *ptr = *ptr2; - ptr++; - } else { - *ptr = *ptr2; - ptr++; - } - ptr2++; - } - *ptr = '\0'; - strcat( ptr, ");\\n" ); - } - fprintf( files->create, "\twr = new Where_rule(\"%s\");\n", whereRule_formatted ); - fprintf( files->create, "\t%s%s%s->_where_rules->Append(wr);\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - - free( whereRule ); - ptr2 = whereRule = 0; - LISTod - } - - uniqs = entity->u.entity->unique; - - if( uniqs ) { - fprintf( files->create, - "\t%s%s%s->_uniqueness_rules = new Uniqueness_rule__set;\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - - if( whereRule_formatted_size == 0 ) { - uniqRule_formatted = ( char * )malloc( sizeof( char ) * 2 * BUFSIZ ); - whereRule_formatted = uniqRule_formatted; - } else { - uniqRule_formatted = whereRule_formatted; - } - - /*******/ - /* - DASBUG - * take care of qualified attribute names like SELF\entity.attrname - * add parent entity to the uniqueness rule - * change EntityDescriptor::generate_express() to generate the UNIQUE clause - */ - LISTdo( uniqs, list, Linked_List ) - i = 0; - fprintf( files->create, "\tur = new Uniqueness_rule(\"" ); - LISTdo( list, v, Variable ) - i++; - if( i == 1 ) { - /* print label if present */ - if( v ) { - fprintf( files->create, "%s : ", StrToUpper( ( ( Symbol * )v )->name ) ); - } - } else { - if( i > 2 ) { - fprintf( files->create, ", " ); - } - uniqRule = EXPRto_string( v->name ); - fprintf( files->create, "%s", uniqRule ); - } - LISTod - fprintf( files->create, ";\\n\");\n" ); - fprintf( files->create, "\t%s%s%s->_uniqueness_rules->Append(ur);\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - LISTod - /********/ - - } - - if( whereRule_formatted_size > 0 ) { - free( whereRule_formatted ); - } - - n = ENTITYget_classname( entity ); - fprintf( files->classes, "\nclass %s;\n", n ); - fprintf( files->classes, "typedef %s * \t%sH;\n", n, n ); - fprintf( files->classes, "typedef %s * \t%s_ptr;\n", n, n ); - fprintf( files->classes, "typedef %s_ptr\t%s_var;\n", n, n ); - - fprintf( files->classes, - "#define %s__set \tSCLP23(DAObject__set)\n", n ); - - fprintf( files->classes, - "#define %s__set_var \tSCLP23(DAObject__set_var)\n", n ); - - fprintf( files ->classes, "extern EntityDescriptor \t*%s%s%s;\n", - SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) ); - } void MODELprint_new( Entity entity, FILES * files, Schema schema ) { - const char * n; - - n = ENTITYget_classname( entity ); - fprintf( files->inc, "\n %s__set_var %s_get_extents();\n", n, n ); - /* - fprintf(files->create," %s%s%s = new EntityDescriptor(\"%s\",%s%s,%s, (Creator) create_%s);\n", - SCHEMAget_name(schema),ENT_PREFIX,ENTITYget_name(entity), - PrettyTmpName (ENTITYget_name(entity)), - SCHEMA_PREFIX,SCHEMAget_name(schema), - (ENTITYget_abstract(entity)?"LTrue":"LFalse"), - ENTITYget_classname (entity) - ); - */ - /* - fprintf(files ->inc,"extern EntityDescriptor \t*%s%s%s;\n", - SCHEMAget_name(schema),ENT_PREFIX,ENTITYget_name(entity)); - */ - } /****************************************************************** @@ -2007,32 +935,10 @@ MODELprint_new( Entity entity, FILES * files, Schema schema ) { ******************************************************************/ const char * EnumCElementName( Type type, Expression expr ) { - - static char buf [BUFSIZ]; - sprintf( buf, "%s__", - EnumName( TYPEget_name( type ) ) ); - strcat( buf, StrToLower( EXPget_name( expr ) ) ); - - return buf; } char * CheckEnumSymbol( char * s ) { - - static char b [BUFSIZ]; - if( strcmp( s, "sdaiTRUE" ) - && strcmp( s, "sdaiFALSE" ) - && strcmp( s, "sdaiUNKNOWN" ) ) { - /* if the symbol is not a reserved one */ - return ( s ); - - } else { - strcpy( b, s ); - strcat( b, "_" ); - printf( "** warning: the enumerated value %s is already being used ", s ); - printf( " and has been changed to %s **\n", b ); - return ( b ); - } } void @@ -2250,20 +1156,6 @@ Type_Description( const Type t, char * buf ) { } } -/************************************************************************** - ** Procedure: TYPEprint_typedefs - ** Parameters: const Type type - ** Returns: - ** Description: - ** Prints in Sdaiclasses.h typedefs, forward declarations, and externs - ** for user-defined types. Only a fraction of the typedefs and decla- - ** rations are needed in Sdaiclasses.h. Enum's and selects must actu- - ** ally be defined before objects (such as entities) which use it can - ** be defined. So forward declarations will not serve any purpose. - ** Other redefined types and aggregate types may be declared here. - ** Side Effects: - ** Status: 16-Mar-1993 kcm; updated 04-Feb-1997 dar - **************************************************************************/ void TYPEprint_typedefs( Type t, FILE * classes ) { } @@ -2297,96 +1189,6 @@ isMultiDimAggregateType( const Type t ) { reference since it has an Express name associated with it. */ int TYPEget_RefTypeVarNm( const Type t, char * buf, Schema schema ) { - - /* It looks like TYPEget_head(t) is true when processing a type - that refers to another type. e.g. when processing "name" in: - TYPE name = label; ENDTYPE; TYPE label = STRING; ENDTYPE; DAS */ - if( TYPEget_head( t ) ) { - /* this means that it is defined in an Express TYPE stmt and - it refers to another Express TYPE stmt */ - /* it would be a reference_ type */ - /* a TypeDescriptor of the form t_ */ - sprintf( buf, "%s%s%s", - SCHEMAget_name( TYPEget_head( t )->superscope ), - TYPEprefix( t ), TYPEget_name( TYPEget_head( t ) ) ); - return 1; - } else { - switch( TYPEget_body( t )->type ) { - case integer_: - case real_: - case boolean_: - case logical_: - case string_: - case binary_: - case number_: - /* one of the SCL builtin TypeDescriptors of the form - t_STRING_TYPE, or t_REAL_TYPE */ - sprintf( buf, "%s%s", TD_PREFIX, FundamentalType( t, 0 ) ); - return 1; - break; - - case enumeration_: /* enums don't have a referent type */ - case select_: /* selects are handled differently elsewhere, they - refer to several TypeDescriptors */ - return 0; - break; - - case entity_: - sprintf( buf, "%s", TYPEtd_name( t ) ); - /* following assumes we are not in a nested entity */ - /* otherwise we should search upward for schema */ - /* TYPEget_name(TYPEget_body(t)->entity->superscope), - ENT_PREFIX,TYPEget_name(t) ); */ - return 1; - break; - - case aggregate_: - case array_: - case bag_: - case set_: - case list_: - /* referent TypeDescriptor will be the one for the element unless it - is a multidimensional aggregate then return 0 */ - - if( isMultiDimAggregateType( t ) ) { - if( TYPEget_name( TYPEget_body( t )->base ) ) { - sprintf( buf, "%s%s%s", - SCHEMAget_name( TYPEget_body( t )->base->superscope ), - TYPEprefix( t ), TYPEget_name( TYPEget_body( t )->base ) ); - return 1; - } - - /* if the multi aggr doesn't have a name then we are out of scope - of what this function can do */ - return 0; - } else { - /* for a single dimensional aggregate return TypeDescriptor - for element */ - /* being an aggregate implies that base below is not 0 */ - - if( TYPEget_body( TYPEget_body( t )->base )->type == enumeration_ || - TYPEget_body( TYPEget_body( t )->base )->type == select_ ) { - - sprintf( buf, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); - return 1; - } else if( TYPEget_name( TYPEget_body( t )->base ) ) { - if( TYPEget_body( TYPEget_body( t )->base )->type == entity_ ) { - sprintf( buf, "%s", TYPEtd_name( TYPEget_body( t )->base ) ); - return 1; - } - sprintf( buf, "%s%s%s", - SCHEMAget_name( TYPEget_body( t )->base->superscope ), - TYPEprefix( t ), TYPEget_name( TYPEget_body( t )->base ) ); - return 1; - } - return TYPEget_RefTypeVarNm( TYPEget_body( t )->base, buf, schema ); - } - break; - default: - return 0; - } - } - /* return 0; // this stmt will never be reached */ } @@ -2410,18 +1212,6 @@ TYPEprint_descriptions( const Type type, FILES * files, Schema schema ) { strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - /* define type descriptor pointer */ - /* put extern def in header, put the real definition in .cc file */ - - /* put extern def in header (DAR - moved to TYPEprint_typedef's - - * see fn header comments.)*/ - /* - fprintf(files->inc,"extern %s \t*%s;\n", - GetTypeDescriptorName(type), tdnm); - */ - - /* in source - declare the real definition of the pointer */ - /* i.e. in the .cc file */ if( TYPEis_enumeration( type ) && ( i = TYPEget_ancestor( type ) ) != NULL ) { /* If we're a renamed enum type, just print a few typedef's to the // original and some specialized create functions: */ @@ -2448,9 +1238,7 @@ TYPEprint_descriptions( const Type type, FILES * files, Schema schema ) { case enumeration_: TYPEenum_lib_print( type, files -> lib ); break; - case select_: - //TYPEselect_lib_print (type, files -> lib); break; default: break; @@ -2492,72 +1280,6 @@ printEnumAggrCrBody( FILE * lib, const Type type ) { void TYPEprint_init( const Type type, FILE * ifile, Schema schema ) { - char tdnm [BUFSIZ]; - char typename_buf[MAX_LEN]; - - strncpy( tdnm, TYPEtd_name( type ), BUFSIZ ); - - if( isAggregateType( type ) ) { - if( !TYPEget_head( type ) ) { - if( TYPEget_body( type )->lower ) - fprintf( ifile, "\t%s->Bound1(%d);\n", tdnm, - TYPEget_body( type )->lower->u.integer ); - if( TYPEget_body( type )->upper ) - fprintf( ifile, "\t%s->Bound2(%d);\n", tdnm, - TYPEget_body( type )->upper->u.integer ); - if( TYPEget_body( type )->flags.unique ) { - fprintf( ifile, "\t%s->UniqueElements(\"LTrue\");\n", tdnm ); - } - /* fprintf(ifile, "\t%s->UniqueElements(%d);\n", tdnm, - TYPEget_body(type)->flags.unique); */ - if( TYPEget_body( type )->flags.optional ) { - fprintf( ifile, "\t%s->OptionalElements(\"LTrue\");\n", tdnm ); - } - /* fprintf(ifile, "\t%s->OptionalElements(%d);\n", tdnm, - TYPEget_body(type)->flags.optional);*/ - } - } - - /* fill in the TD's values in the SchemaInit function (it is already - declared with basic values) */ - - if( TYPEget_RefTypeVarNm( type, typename_buf, schema ) ) { - fprintf( ifile, "\t%s->ReferentType(%s);\n", tdnm, typename_buf ); - } else { - switch( TYPEget_body( type )->type ) { - case aggregate_: /* aggregate_ should not happen? DAS */ - case array_: - case bag_: - case set_: - case list_: { - - if( isMultiDimAggregateType( type ) ) { - print_typechain( ifile, TYPEget_body( type )->base, - typename_buf, schema ); - fprintf( ifile, " %s->ReferentType(%s);\n", tdnm, - typename_buf ); - } - break; - } - default: - break; - } - } - - /* DAR - moved fn call below from TYPEselect_print to here to put all init - ** info together. */ - if( TYPEis_select( type ) ) { - TYPEselect_init_print( type, ifile, schema ); - } -#ifdef NEWDICT - /* DAS New SDAI Dictionary 5/95 */ - /* insert the type into the schema descriptor */ - fprintf( ifile, - "\t((SDAIAGGRH(Set,DefinedTypeH))%s%s->Types())->Add((DefinedTypeH)%s);\n", - SCHEMA_PREFIX, SCHEMAget_name( schema ), tdnm ); -#endif - /* insert into type dictionary */ - fprintf( ifile, "\treg.AddType (*%s);\n", tdnm ); } /* print name, fundamental type, and description initialization function @@ -2565,15 +1287,6 @@ TYPEprint_init( const Type type, FILE * ifile, Schema schema ) { void TYPEprint_nm_ft_desc( Schema schema, const Type type, FILE * f, char * endChars ) { - - fprintf( f, "\t\t \"%s\",\t// Name\n", - PrettyTmpName( TYPEget_name( type ) ) ); - fprintf( f, "\t\t %s,\t// FundamentalType\n", - FundamentalType( type, 1 ) ); - fprintf( f, "\t\t %s%s,\t// Originating Schema\n", - SCHEMA_PREFIX, SCHEMAget_name( schema ) ); - fprintf( f, "\t\t \"%s\"%s\t// Description\n", - TypeDescription( type ), endChars ); } From 5f345c700eef1973240351a960d6a6b2aafacdbb Mon Sep 17 00:00:00 2001 From: tpaviot Date: Tue, 21 Feb 2012 06:50:30 +0100 Subject: [PATCH 13/19] Better support for enum and aggr typedefs --- src/fedex_python/src/classes_misc_python.c | 11 --- src/fedex_python/src/classes_python.c | 74 +++++++++++++-- .../src/classes_wrapper_python.cc | 11 --- src/fedex_python/src/multpass_python.c | 10 +- src/fedex_python/src/selects_python.c | 92 ------------------- 5 files changed, 72 insertions(+), 126 deletions(-) diff --git a/src/fedex_python/src/classes_misc_python.c b/src/fedex_python/src/classes_misc_python.c index 28fe661b8..8032f60ce 100644 --- a/src/fedex_python/src/classes_misc_python.c +++ b/src/fedex_python/src/classes_misc_python.c @@ -201,7 +201,6 @@ FILEcreate( const char * filename ) { void FILEclose( FILE * file ) { - //fprintf( file, "#endif\n" ); fclose( file ); } @@ -269,16 +268,6 @@ ClassName( const char * oldname ) { } newname [j] = '\0'; return ( newname ); - - /****** This procedure gets rid of '_' and is no longer being used - if (oldname [i] != '_') newname [j] = ToLower (oldname [i]); - else { *//* character is '_' *//* -newname [j] = ToUpper (oldname [++i]); -if (oldname [i] == '\0') --i; -} -++i; -++j; -*******/ } const char * diff --git a/src/fedex_python/src/classes_python.c b/src/fedex_python/src/classes_python.c index 4d0735898..5ab6c6c79 100644 --- a/src/fedex_python/src/classes_python.c +++ b/src/fedex_python/src/classes_python.c @@ -522,6 +522,48 @@ print_aggregate_type(FILE *file, Type t) { } } +void +process_aggregate_with_guillemets (FILE *file, Type t) { + Expression lower = AGGR_TYPEget_lower_limit(t); + char *lower_str = EXPRto_string(lower); + Expression upper = AGGR_TYPEget_upper_limit(t); + char *upper_str = NULL; + if (upper == LITERAL_INFINITY) { + upper_str = "None"; + } + else { + upper_str = EXPRto_string(upper); + } + switch(TYPEget_body( t )->type) { + case array_: + fprintf(file,"ARRAY"); + break; + case bag_: + fprintf(file,"BAG"); + break; + case set_: + fprintf(file,"SET"); + break; + case list_: + fprintf(file,"LIST"); + break; + default: + break; + } + fprintf(file,"(%s,%s,",lower_str,upper_str); + //write base type + Type base_type = TYPEget_base_type(t); + if (TYPEis_aggregate(base_type)) { + process_aggregate(file,base_type); + fprintf(file,")"); //close parenthesis + } + else { + char * array_base_type = GetAttrTypeName(TYPEget_base_type(t)); + fprintf(file,"'%s')",array_base_type); + } + +} + /* * * A recursive function to export aggregate to python @@ -945,14 +987,30 @@ void TYPEenum_lib_print( const Type type, FILE * f ) { DictionaryEntry de; Expression expr; - //const char * n; /* pointer to class name */ char c_enum_ele [BUFSIZ]; + // begin the new enum type + if (is_python_keyword(TYPEget_name( type ))) { + fprintf( f, "\n# ENUMERATION TYPE %s_\n", TYPEget_name( type ) ); + } + else { + fprintf( f, "\n# ENUMERATION TYPE %s\n", TYPEget_name( type ) ); + } + // first write all the values of the enum + DICTdo_type_init( ENUM_TYPEget_items( type ), &de, OBJ_ENUM ); + while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { + strncpy( c_enum_ele, EnumCElementName( type, expr ), BUFSIZ ); + if (is_python_keyword(EXPget_name(expr))) { + fprintf(f,"%s_ = '%s_'\n",EXPget_name(expr),EXPget_name(expr)); + } + else { + fprintf(f,"%s = '%s'\n",EXPget_name(expr),EXPget_name(expr)); + } + } + // then outputs the enum if (is_python_keyword(TYPEget_name( type ))) { - fprintf( f, "# ENUMERATION TYPE %s_\n", TYPEget_name( type ) ); fprintf(f,"%s_ = ENUMERATION([",TYPEget_name( type )); } else { - fprintf( f, "# ENUMERATION TYPE %s\n", TYPEget_name( type ) ); fprintf(f,"%s = ENUMERATION([",TYPEget_name( type )); } /* set up the dictionary info */ @@ -963,10 +1021,10 @@ TYPEenum_lib_print( const Type type, FILE * f ) { while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { strncpy( c_enum_ele, EnumCElementName( type, expr ), BUFSIZ ); if (is_python_keyword(EXPget_name(expr))) { - fprintf(f,"\n\t'%s_',",EXPget_name(expr)); + fprintf(f,"\n\'%s_,",EXPget_name(expr)); } else { - fprintf(f,"\n\t'%s',",EXPget_name(expr)); + fprintf(f,"\n\t%s,",EXPget_name(expr)); } } fprintf(f,"\n\t])\n"); @@ -1225,14 +1283,14 @@ TYPEprint_descriptions( const Type type, FILES * files, Schema schema ) { { fprintf(files->lib, "%s = ",TYPEget_name(type)); char * output = FundamentalType(type,0); - if (!strcmp(output,"ARRAY_TYPE")) { + if( TYPEis_aggregate( type ) ) { process_aggregate(files->lib,type); fprintf(files->lib,"\n"); - } + } else { fprintf(files->lib,"%s\n",output); } - } + } else { switch( TYPEget_body( type )->type ) { case enumeration_: diff --git a/src/fedex_python/src/classes_wrapper_python.cc b/src/fedex_python/src/classes_wrapper_python.cc index bb2a4e769..99aeef1aa 100644 --- a/src/fedex_python/src/classes_wrapper_python.cc +++ b/src/fedex_python/src/classes_wrapper_python.cc @@ -328,21 +328,10 @@ SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol, } sprintf( fnm, "%s.h", sufnm ); - //if( !( incfile = ( files -> inc ) = FILEcreate( fnm ) ) ) { - // return; - //} - /* Generate local to SCHEMA.init.cc file */ - /* fprintf(incfile,"Schema *%s%s;\n",*/ - /* SCHEMA_PREFIX,SCHEMAget_name(schema));*/ - - /* fprintf (incfile, "extern void %sInit (Registry & r);\n", schnm);*/ - /* fprintf (incfile, "extern void SchemaInit (Registry & r);\n");*/ - np = fnm + strlen( fnm ) - 1; /* point to end of constant part of string */ /* 2. class source file */ sprintf( np, "py" ); - //if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { if( !( libfile = ( files -> lib ) = FILEcreate( fnm ) ) ) { return; } diff --git a/src/fedex_python/src/multpass_python.c b/src/fedex_python/src/multpass_python.c index d1b5b5fca..bd1cdb4c5 100644 --- a/src/fedex_python/src/multpass_python.c +++ b/src/fedex_python/src/multpass_python.c @@ -70,7 +70,6 @@ void print_schemas_separate( Express express, void * complexCol, FILES * files ) /* First set all marks we'll be using to UNPROCESSED/NOTKNOWN: */ initializeMarks( express ); - //FIXME SdaiAll.cc:12:24: warning: unused variable ā€˜is’ [-Wunused-variable] (also for ui & ri) //fprintf( files->create, " Interface_spec_ptr is;\n Used_item_ptr ui;\n Referenced_item_ptr ri;\n Uniqueness_rule_ptr ur;\n Where_rule_ptr wr;\n Global_rule_ptr gr;\n" ); while( !complete ) { @@ -147,7 +146,8 @@ void print_schemas_separate( Express express, void * complexCol, FILES * files ) // of addAggrTypedefs.) */ DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA ); while( ( schema = ( Scope )DICTdo( &de ) ) != 0 ) { - addAggrTypedefs( schema, files->classes ); + //addAggrTypedefs( schema, files->classes ); + addAggrTypedefs( schema, files->lib ); } /* On our way out, print the necessary statements to add support for @@ -614,11 +614,13 @@ static void addAggrTypedefs( Schema schema, FILE * classes ) // 2D aggr's and higher only need type GenericAggr defined // which is built-in. */ printf("in addAggrTypedefs. %s is enum or select.\n",TYPEget_name(t)); + //strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); + //printf("%s;%s",nm,TYPEget_ctype( t )); //if( firsttime ) { - // fprintf( classes, "\n// Aggregate types (from all sche" ); - // fprintf( classes, "mas) which depend on other types:\n" ); + // fprintf( classes, "The first TIME\n" ); // firsttime = FALSE; //} + //fprintf(classes,"in addAggrTypedefs. %s is enum or select.\n",TYPEget_name(t)); //strncpy( nm, ClassName( TYPEget_name( t ) ), BUFSIZ ); //fprintf( classes, "typedef %s\t%s;\n", // TYPEget_ctype( t ), nm ); diff --git a/src/fedex_python/src/selects_python.c b/src/fedex_python/src/selects_python.c index db3393852..09fa9d92e 100644 --- a/src/fedex_python/src/selects_python.c +++ b/src/fedex_python/src/selects_python.c @@ -722,98 +722,6 @@ TYPEselect_lib_print( const Type type, FILE * f, Schema schema ) { void TYPEselect_print( Type t, FILES * files, Schema schema ) { - SelectTag tag, tmp; - Type i, bt; /* type of elements in an aggregate */ - char nm[BUFSIZ], tdnm[BUFSIZ]; - FILE * inc = files->inc; - - /* if type is already marked, return */ - if( ( SelectTag )( tmp = TYPEget_clientData( t ) ) ) { - if( ( tmp ->started ) && ( ! tmp ->complete ) ) - fprintf( stderr, "WARNING: SELECT type %s causes circular references\n", - TYPEget_name( t ) ); - return; - } - - /* mark the type as being processed */ - tag = ( SelectTag ) malloc( sizeof( struct SelectTag_ ) ); - tag -> started = 1; - tag -> complete = 0; - TYPEput_clientData( t, tag ); - - - /* Check if we're a renamed type, e.g., TYPE B (sel) = A. If so, if A has - // been defined, we process B differently (with a couple of typedef's - - // some are printed in files->classes rather than here). If A has not been - // defined, we must recurse. */ - if( ( i = TYPEget_ancestor( t ) ) != NULL ) { - if( !TYPEget_clientData( i ) ) { - TYPEselect_print( i, files, schema ); - } - strncpy( nm, SelectName( TYPEget_name( t ) ), BUFSIZ ); - strncpy( tdnm, TYPEtd_name( t ), BUFSIZ ); - fprintf( inc, "typedef %s * \t%sH;\n", nm, nm ); - fprintf( inc, "typedef %s_ptr *\t%s_var;\n", nm, nm ); - /* Below are specialized create functions for the renamed sel type (both - // single and aggregate). The functions call the original sel's con- - // structor, passing the new sel's typedescriptor to create a hybrid - // entity - the original select pointing to a new typedesc. These fns - // give the user an easy way to create the renamed type properly. */ - fprintf( inc, "inline SCLP23(Select) *\ncreate_%s ()", nm ); - fprintf( inc, " { return new %s( %s ); }\n\n", nm, tdnm ); - fprintf( inc, "inline STEPaggregate *\ncreate_%ss ()", nm ); - fprintf( inc, " { return new %ss( %s ); }\n\n", nm, tdnm ); - return; - } - - LISTdo( SEL_TYPEget_items( t ), i, Type ) - - /* check the items for select types */ - /* and do the referenced select types first */ - - /* check aggregates too */ - /* set i to the bt and catch in next ifs */ - if( isAggregateType( i ) ) { - bt = TYPEget_base_type( i ); - /* DAR - corrected - prev'ly above line retrieved non-aggr base type. - // But unnec - we only need the item defined if it's a select or a 1D - // aggregate. If bt is also an aggr, we go on. */ - if( TYPEis_select( bt ) ) { - i = bt; - } else if( TYPEis_entity( bt ) ) { - i = bt; - } - } - - if( TYPEis_select( i ) && !TYPEget_clientData( i ) ) { - TYPEselect_print( i, files, schema ); - } - /* NOTE - there was a bug here because above if did not take into account - that i came from a different schema (and above loop would have printed - it here!). Taken care of by code in multpass.c which would not allow - us to get this far (wouldn't have called the type_print() fn's) if a - select has members in other schemas which haven't been processed. So, - now by definition i must have been processed already if it's in another - schema. So the above if will only reorder the printing of the sel's in - this schema, which is the intent. DAR */ - -#ifdef OBSOLETE - /* check the attributes to see if a select is referenced */ - if( TYPEis_entity( i ) ) { - LISTdo( ENTITYget_all_attributes( ENT_TYPEget_entity( i ) ), a, Variable ) - if( TYPEis_select( VARget_type( a ) ) ) { - TYPEselect_print( VARget_type( a ), files, schema ); - } - LISTod - } -#endif - LISTod - - //TYPEselect_inc_print( t, files -> inc ); - TYPEselect_lib_print( t, files -> lib, schema ); - /* TYPEselect_init_print (t, files -> init, schema); - DAR - moved to TYPEprint_init() - to keep init info together. */ - tag -> complete = 1; } #undef BASE_SELECT From 8cad6ec2aa73cfaa92a2646a8629a0aa838550f2 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Wed, 22 Feb 2012 17:54:00 +0100 Subject: [PATCH 14/19] Improvements in SELECT and ENUMERATION support --- ...modules.py => generate_schemas_modules.py} | 0 .../unitary_schemas/index_attribute.py | 30 ++- .../examples/unitary_schemas/test_array.py | 8 +- .../test_array_of_simple_types.py | 24 ++- .../unitary_schemas/test_derived_attribute.py | 18 +- .../unitary_schemas/test_enum_entity_name.py | 9 +- .../unitary_schemas/test_enums_same_name.py | 18 +- .../test_multiple_inheritance.py | 186 ++++++++++++------ .../unitary_schemas/test_named_type.py | 6 +- .../unitary_schemas/test_select_data_type.py | 90 ++++++--- .../test_single_inheritance.py | 24 ++- .../test_single_inheritance_multi_level.py | 24 ++- .../python/SCL/AggregationDataTypes.py | 9 +- .../python/SCL/ConstructedDataTypes.py | 122 +++++++++--- src/fedex_python/python/SCL/TypeChecker.py | 36 ++-- src/fedex_python/python/SCL/Utils.py | 70 +++++++ src/fedex_python/src/classes_python.c | 66 ++----- .../src/classes_wrapper_python.cc | 20 +- src/fedex_python/src/selects_python.c | 31 ++- 19 files changed, 538 insertions(+), 253 deletions(-) rename src/fedex_python/examples/unitary_schemas/{generate_shemas_modules.py => generate_schemas_modules.py} (100%) create mode 100644 src/fedex_python/python/SCL/Utils.py diff --git a/src/fedex_python/examples/unitary_schemas/generate_shemas_modules.py b/src/fedex_python/examples/unitary_schemas/generate_schemas_modules.py similarity index 100% rename from src/fedex_python/examples/unitary_schemas/generate_shemas_modules.py rename to src/fedex_python/examples/unitary_schemas/generate_schemas_modules.py diff --git a/src/fedex_python/examples/unitary_schemas/index_attribute.py b/src/fedex_python/examples/unitary_schemas/index_attribute.py index b069d7ff5..4b1e36826 100644 --- a/src/fedex_python/examples/unitary_schemas/index_attribute.py +++ b/src/fedex_python/examples/unitary_schemas/index_attribute.py @@ -7,8 +7,16 @@ from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * -common_datum_list = 'LIST TYPE Not implemented' +common_datum_list = LIST(1,None,'datum_reference_element') label = STRING +# SELECT TYPE datum_or_common_datum_ +if (not 'common_datum_list' in globals().keys()): + common_datum_list = 'common_datum_list' +if (not 'datum' in globals().keys()): + datum = 'datum' +datum_or_common_datum = SELECT( + 'common_datum_list', + 'datum') #################### # ENTITY shape_aspect # @@ -34,8 +42,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument name is mantatory and can not be set to None') - check_type(value,STRING) - self._name = value + if not check_type(value,STRING): + self._name = STRING(value) + else: + self._name = value return property(**locals()) @apply @@ -46,8 +56,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument of_shape is mantatory and can not be set to None') - check_type(value,product_definition_shape) - self._of_shape = value + if not check_type(value,product_definition_shape): + self._of_shape = product_definition_shape(value) + else: + self._of_shape = value return property(**locals()) #################### @@ -71,8 +83,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument base is mantatory and can not be set to None') - check_type(value,datum_or_common_datum) - self._base = value + if not check_type(value,datum_or_common_datum): + self._base = datum_or_common_datum(value) + else: + self._base = value return property(**locals()) #################### @@ -101,5 +115,3 @@ class datum(shape_aspect): ''' def __init__( self , shape_aspect__name , shape_aspect__of_shape , ): shape_aspect.__init__(self , shape_aspect__name , shape_aspect__of_shape , ) -# SELECT TYPE datum_or_common_datum -datum_or_common_datum=SELECT([common_datum_list,datum]) diff --git a/src/fedex_python/examples/unitary_schemas/test_array.py b/src/fedex_python/examples/unitary_schemas/test_array.py index 65107c4fb..cdfca5461 100644 --- a/src/fedex_python/examples/unitary_schemas/test_array.py +++ b/src/fedex_python/examples/unitary_schemas/test_array.py @@ -15,7 +15,7 @@ class point(BaseEntityClass): '''Entity point definition. :param coords - :type coords:(null) + :type coords:ARRAY(1,3,'REAL') ''' def __init__( self , coords, ): self.coords = coords @@ -28,6 +28,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument coords is mantatory and can not be set to None') - check_type(value,ARRAY(1,3,REAL)) - self._coords = value + if not check_type(value,ARRAY(1,3,'REAL')): + self._coords = ARRAY(value) + else: + self._coords = value return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py b/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py index bacdcb7b6..808e00d79 100644 --- a/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py +++ b/src/fedex_python/examples/unitary_schemas/test_array_of_simple_types.py @@ -15,13 +15,13 @@ class point(BaseEntityClass): '''Entity point definition. :param arr_real - :type arr_real:(null) + :type arr_real:ARRAY(1,3,'REAL') :param arr_string - :type arr_string:(null) + :type arr_string:ARRAY(1,3,'STRING') :param arr_integer - :type arr_integer:(null) + :type arr_integer:ARRAY(1,None,'INTEGER') ''' def __init__( self , arr_real,arr_string,arr_integer, ): self.arr_real = arr_real @@ -36,8 +36,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument arr_real is mantatory and can not be set to None') - check_type(value,ARRAY(1,3,REAL)) - self._arr_real = value + if not check_type(value,ARRAY(1,3,'REAL')): + self._arr_real = ARRAY(value) + else: + self._arr_real = value return property(**locals()) @apply @@ -48,8 +50,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument arr_string is mantatory and can not be set to None') - check_type(value,ARRAY(1,3,STRING)) - self._arr_string = value + if not check_type(value,ARRAY(1,3,'STRING')): + self._arr_string = ARRAY(value) + else: + self._arr_string = value return property(**locals()) @apply @@ -60,6 +64,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument arr_integer is mantatory and can not be set to None') - check_type(value,ARRAY(1,None,INTEGER)) - self._arr_integer = value + if not check_type(value,ARRAY(1,None,'INTEGER')): + self._arr_integer = ARRAY(value) + else: + self._arr_integer = value return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py b/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py index 85f9d5d47..083b03609 100644 --- a/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py +++ b/src/fedex_python/examples/unitary_schemas/test_derived_attribute.py @@ -51,8 +51,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument centre is mantatory and can not be set to None') - check_type(value,point) - self._centre = value + if not check_type(value,point): + self._centre = point(value) + else: + self._centre = value return property(**locals()) @apply @@ -63,8 +65,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument radius is mantatory and can not be set to None') - check_type(value,REAL) - self._radius = value + if not check_type(value,REAL): + self._radius = REAL(value) + else: + self._radius = value return property(**locals()) @apply @@ -75,8 +79,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument axis is mantatory and can not be set to None') - check_type(value,vector) - self._axis = value + if not check_type(value,vector): + self._axis = vector(value) + else: + self._axis = value return property(**locals()) @apply diff --git a/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py b/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py index 528a9fa44..d914e73c6 100644 --- a/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py +++ b/src/fedex_python/examples/unitary_schemas/test_enum_entity_name.py @@ -7,11 +7,16 @@ from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * + # ENUMERATION TYPE simple_datum_reference_modifier -simple_datum_reference_modifier = ENUMERATION([ +if (not 'line' in globals().keys()): + line = 'line' +if (not 'translation' in globals().keys()): + translation = 'translation' +simple_datum_reference_modifier = ENUMERATION( 'line', 'translation', - ]) + ) #################### # ENTITY line # diff --git a/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py b/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py index f3030e452..254760893 100644 --- a/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py +++ b/src/fedex_python/examples/unitary_schemas/test_enums_same_name.py @@ -7,13 +7,23 @@ from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * + # ENUMERATION TYPE hair_color -hair_color = ENUMERATION([ +if (not 'bald' in globals().keys()): + bald = 'bald' +if (not 'red' in globals().keys()): + red = 'red' +hair_color = ENUMERATION( 'bald', 'red', - ]) + ) + # ENUMERATION TYPE favorite_color -favorite_color = ENUMERATION([ +if (not 'clear' in globals().keys()): + clear = 'clear' +if (not 'red' in globals().keys()): + red = 'red' +favorite_color = ENUMERATION( 'clear', 'red', - ]) + ) diff --git a/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py b/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py index 4ede2bc18..c8d111fc5 100644 --- a/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py +++ b/src/fedex_python/examples/unitary_schemas/test_multiple_inheritance.py @@ -7,6 +7,14 @@ from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * +# SELECT TYPE classification_item_ +if (not 'person_and_organization_address' in globals().keys()): + person_and_organization_address = 'person_and_organization_address' +if (not 'address' in globals().keys()): + address = 'address' +classification_item = SELECT( + 'person_and_organization_address', + 'address') text = STRING identifier = STRING label = STRING @@ -73,8 +81,10 @@ def fget( self ): return self._internal_location def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._internal_location = value + if not check_type(value,STRING): + self._internal_location = STRING(value) + else: + self._internal_location = value return property(**locals()) @apply @@ -83,8 +93,10 @@ def fget( self ): return self._street_number def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._street_number = value + if not check_type(value,STRING): + self._street_number = STRING(value) + else: + self._street_number = value return property(**locals()) @apply @@ -93,8 +105,10 @@ def fget( self ): return self._street def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._street = value + if not check_type(value,STRING): + self._street = STRING(value) + else: + self._street = value return property(**locals()) @apply @@ -103,8 +117,10 @@ def fget( self ): return self._postal_box def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._postal_box = value + if not check_type(value,STRING): + self._postal_box = STRING(value) + else: + self._postal_box = value return property(**locals()) @apply @@ -113,8 +129,10 @@ def fget( self ): return self._town def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._town = value + if not check_type(value,STRING): + self._town = STRING(value) + else: + self._town = value return property(**locals()) @apply @@ -123,8 +141,10 @@ def fget( self ): return self._region def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._region = value + if not check_type(value,STRING): + self._region = STRING(value) + else: + self._region = value return property(**locals()) @apply @@ -133,8 +153,10 @@ def fget( self ): return self._postal_code def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._postal_code = value + if not check_type(value,STRING): + self._postal_code = STRING(value) + else: + self._postal_code = value return property(**locals()) @apply @@ -143,8 +165,10 @@ def fget( self ): return self._country def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._country = value + if not check_type(value,STRING): + self._country = STRING(value) + else: + self._country = value return property(**locals()) @apply @@ -153,8 +177,10 @@ def fget( self ): return self._facsimile_number def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._facsimile_number = value + if not check_type(value,STRING): + self._facsimile_number = STRING(value) + else: + self._facsimile_number = value return property(**locals()) @apply @@ -163,8 +189,10 @@ def fget( self ): return self._telephone_number def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._telephone_number = value + if not check_type(value,STRING): + self._telephone_number = STRING(value) + else: + self._telephone_number = value return property(**locals()) @apply @@ -173,8 +201,10 @@ def fget( self ): return self._electronic_mail_address def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._electronic_mail_address = value + if not check_type(value,STRING): + self._electronic_mail_address = STRING(value) + else: + self._electronic_mail_address = value return property(**locals()) @apply @@ -183,8 +213,10 @@ def fget( self ): return self._telex_number def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._telex_number = value + if not check_type(value,STRING): + self._telex_number = STRING(value) + else: + self._telex_number = value return property(**locals()) #################### @@ -194,7 +226,7 @@ class personal_address(address): '''Entity personal_address definition. :param people - :type people:(null) + :type people:SET(1,None,'person') :param description :type description:STRING @@ -212,8 +244,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument people is mantatory and can not be set to None') - check_type(value,SET(1,None,person)) - self._people = value + if not check_type(value,SET(1,None,'person')): + self._people = SET(value) + else: + self._people = value return property(**locals()) @apply @@ -222,8 +256,10 @@ def fget( self ): return self._description def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._description = value + if not check_type(value,STRING): + self._description = STRING(value) + else: + self._description = value return property(**locals()) #################### @@ -233,7 +269,7 @@ class organizational_address(address): '''Entity organizational_address definition. :param organizations - :type organizations:(null) + :type organizations:SET(1,None,'organization') :param description :type description:STRING @@ -251,8 +287,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument organizations is mantatory and can not be set to None') - check_type(value,SET(1,None,organization)) - self._organizations = value + if not check_type(value,SET(1,None,'organization')): + self._organizations = SET(value) + else: + self._organizations = value return property(**locals()) @apply @@ -261,8 +299,10 @@ def fget( self ): return self._description def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._description = value + if not check_type(value,STRING): + self._description = STRING(value) + else: + self._description = value return property(**locals()) #################### @@ -281,13 +321,13 @@ class person(BaseEntityClass): :type first_name:STRING :param middle_names - :type middle_names:(null) + :type middle_names:LIST(1,None,'STRING') :param prefix_titles - :type prefix_titles:(null) + :type prefix_titles:LIST(1,None,'STRING') :param suffix_titles - :type suffix_titles:(null) + :type suffix_titles:LIST(1,None,'STRING') ''' def __init__( self , id,last_name,first_name,middle_names,prefix_titles,suffix_titles, ): self.id = id @@ -305,8 +345,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument id is mantatory and can not be set to None') - check_type(value,STRING) - self._id = value + if not check_type(value,STRING): + self._id = STRING(value) + else: + self._id = value return property(**locals()) @apply @@ -315,8 +357,10 @@ def fget( self ): return self._last_name def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._last_name = value + if not check_type(value,STRING): + self._last_name = STRING(value) + else: + self._last_name = value return property(**locals()) @apply @@ -325,8 +369,10 @@ def fget( self ): return self._first_name def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._first_name = value + if not check_type(value,STRING): + self._first_name = STRING(value) + else: + self._first_name = value return property(**locals()) @apply @@ -335,8 +381,10 @@ def fget( self ): return self._middle_names def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,LIST(1,None,STRING)) - self._middle_names = value + if not check_type(value,LIST(1,None,'STRING')): + self._middle_names = LIST(value) + else: + self._middle_names = value return property(**locals()) @apply @@ -345,8 +393,10 @@ def fget( self ): return self._prefix_titles def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,LIST(1,None,STRING)) - self._prefix_titles = value + if not check_type(value,LIST(1,None,'STRING')): + self._prefix_titles = LIST(value) + else: + self._prefix_titles = value return property(**locals()) @apply @@ -355,8 +405,10 @@ def fget( self ): return self._suffix_titles def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,LIST(1,None,STRING)) - self._suffix_titles = value + if not check_type(value,LIST(1,None,'STRING')): + self._suffix_titles = LIST(value) + else: + self._suffix_titles = value return property(**locals()) #################### @@ -385,8 +437,10 @@ def fget( self ): return self._id def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._id = value + if not check_type(value,STRING): + self._id = STRING(value) + else: + self._id = value return property(**locals()) @apply @@ -397,8 +451,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument name is mantatory and can not be set to None') - check_type(value,STRING) - self._name = value + if not check_type(value,STRING): + self._name = STRING(value) + else: + self._name = value return property(**locals()) @apply @@ -407,8 +463,10 @@ def fget( self ): return self._description def fset( self, value ): if value != None: # OPTIONAL attribute - check_type(value,STRING) - self._description = value + if not check_type(value,STRING): + self._description = STRING(value) + else: + self._description = value return property(**locals()) #################### @@ -418,10 +476,10 @@ class person_and_organization_address(organizational_address,personal_address): '''Entity person_and_organization_address definition. :param organizational_address_organizations - :type organizational_address_organizations:(null) + :type organizational_address_organizations:SET(1,1,'organization') :param personal_address_people - :type personal_address_people:(null) + :type personal_address_people:SET(1,1,'person') ''' def __init__( self , organizational_address__organizations , organizational_address__description , personal_address__people , personal_address__description , organizational_address_organizations,personal_address_people, ): organizational_address.__init__(self , organizational_address__organizations , organizational_address__description , ) @@ -437,8 +495,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument organizational_address_organizations is mantatory and can not be set to None') - check_type(value,SET(1,1,organization)) - self._organizational_address_organizations = value + if not check_type(value,SET(1,1,'organization')): + self._organizational_address_organizations = SET(value) + else: + self._organizational_address_organizations = value return property(**locals()) @apply @@ -449,8 +509,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument personal_address_people is mantatory and can not be set to None') - check_type(value,SET(1,1,person)) - self._personal_address_people = value + if not check_type(value,SET(1,1,'person')): + self._personal_address_people = SET(value) + else: + self._personal_address_people = value return property(**locals()) -# SELECT TYPE classification_item -classification_item=SELECT([person_and_organization_address,address]) diff --git a/src/fedex_python/examples/unitary_schemas/test_named_type.py b/src/fedex_python/examples/unitary_schemas/test_named_type.py index ef366876d..5020f9b0c 100644 --- a/src/fedex_python/examples/unitary_schemas/test_named_type.py +++ b/src/fedex_python/examples/unitary_schemas/test_named_type.py @@ -30,6 +30,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument line_length is mantatory and can not be set to None') - check_type(value,REAL) - self._line_length = value + if not check_type(value,REAL): + self._line_length = REAL(value) + else: + self._line_length = value return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_select_data_type.py b/src/fedex_python/examples/unitary_schemas/test_select_data_type.py index 613ff0627..81652a777 100644 --- a/src/fedex_python/examples/unitary_schemas/test_select_data_type.py +++ b/src/fedex_python/examples/unitary_schemas/test_select_data_type.py @@ -7,6 +7,30 @@ from SCL.AggregationDataTypes import * from SCL.TypeChecker import check_type from SCL.Expr import * +# SELECT TYPE permanent_attachment_ +if (not 'glue' in globals().keys()): + glue = 'glue' +if (not 'weld' in globals().keys()): + weld = 'weld' +permanent_attachment = SELECT( + 'glue', + 'weld') +# SELECT TYPE temporary_attachment_ +if (not 'nail' in globals().keys()): + nail = 'nail' +if (not 'screw' in globals().keys()): + screw = 'screw' +temporary_attachment = SELECT( + 'nail', + 'screw') +# SELECT TYPE attachment_method_ +if (not 'permanent_attachment' in globals().keys()): + permanent_attachment = 'permanent_attachment' +if (not 'temporary_attachment' in globals().keys()): + temporary_attachment = 'temporary_attachment' +attachment_method = SELECT( + 'permanent_attachment', + 'temporary_attachment') #################### # ENTITY weld # @@ -28,8 +52,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument composition is mantatory and can not be set to None') - check_type(value,STRING) - self._composition = value + if not check_type(value,STRING): + self._composition = STRING(value) + else: + self._composition = value return property(**locals()) #################### @@ -56,8 +82,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument composition is mantatory and can not be set to None') - check_type(value,STRING) - self._composition = value + if not check_type(value,STRING): + self._composition = STRING(value) + else: + self._composition = value return property(**locals()) @apply @@ -68,8 +96,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument solvent is mantatory and can not be set to None') - check_type(value,STRING) - self._solvent = value + if not check_type(value,STRING): + self._solvent = STRING(value) + else: + self._solvent = value return property(**locals()) #################### @@ -100,8 +130,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument mounting is mantatory and can not be set to None') - check_type(value,STRING) - self._mounting = value + if not check_type(value,STRING): + self._mounting = STRING(value) + else: + self._mounting = value return property(**locals()) @apply @@ -112,8 +144,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument on is mantatory and can not be set to None') - check_type(value,STRING) - self._on = value + if not check_type(value,STRING): + self._on = STRING(value) + else: + self._on = value return property(**locals()) @apply @@ -124,8 +158,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument using is mantatory and can not be set to None') - check_type(value,attachment_method) - self._using = value + if not check_type(value,attachment_method): + self._using = attachment_method(value) + else: + self._using = value return property(**locals()) #################### @@ -152,8 +188,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument body_length is mantatory and can not be set to None') - check_type(value,REAL) - self._body_length = value + if not check_type(value,REAL): + self._body_length = REAL(value) + else: + self._body_length = value return property(**locals()) @apply @@ -164,8 +202,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument pitch is mantatory and can not be set to None') - check_type(value,REAL) - self._pitch = value + if not check_type(value,REAL): + self._pitch = REAL(value) + else: + self._pitch = value return property(**locals()) #################### @@ -192,8 +232,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument body_length is mantatory and can not be set to None') - check_type(value,REAL) - self._body_length = value + if not check_type(value,REAL): + self._body_length = REAL(value) + else: + self._body_length = value return property(**locals()) @apply @@ -204,12 +246,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument head_area is mantatory and can not be set to None') - check_type(value,REAL) - self._head_area = value + if not check_type(value,REAL): + self._head_area = REAL(value) + else: + self._head_area = value return property(**locals()) -# SELECT TYPE permanent_attachment -permanent_attachment=SELECT([glue,weld]) -# SELECT TYPE temporary_attachment -temporary_attachment=SELECT([nail,screw]) -# SELECT TYPE attachment_method -attachment_method=SELECT([permanent_attachment,temporary_attachment]) diff --git a/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py b/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py index a37ee44e9..b7873a7fa 100644 --- a/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py +++ b/src/fedex_python/examples/unitary_schemas/test_single_inheritance.py @@ -35,8 +35,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument item_name is mantatory and can not be set to None') - check_type(value,STRING) - self._item_name = value + if not check_type(value,STRING): + self._item_name = STRING(value) + else: + self._item_name = value return property(**locals()) @apply @@ -47,8 +49,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument number_of_sides is mantatory and can not be set to None') - check_type(value,INTEGER) - self._number_of_sides = value + if not check_type(value,INTEGER): + self._number_of_sides = INTEGER(value) + else: + self._number_of_sides = value return property(**locals()) #################### @@ -76,8 +80,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument height is mantatory and can not be set to None') - check_type(value,REAL) - self._height = value + if not check_type(value,REAL): + self._height = REAL(value) + else: + self._height = value return property(**locals()) @apply @@ -88,6 +94,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument width is mantatory and can not be set to None') - check_type(value,REAL) - self._width = value + if not check_type(value,REAL): + self._width = REAL(value) + else: + self._width = value return property(**locals()) diff --git a/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py b/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py index 0c8e5cec5..b241d55ec 100644 --- a/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py +++ b/src/fedex_python/examples/unitary_schemas/test_single_inheritance_multi_level.py @@ -35,8 +35,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument item_name is mantatory and can not be set to None') - check_type(value,STRING) - self._item_name = value + if not check_type(value,STRING): + self._item_name = STRING(value) + else: + self._item_name = value return property(**locals()) @apply @@ -47,8 +49,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument number_of_sides is mantatory and can not be set to None') - check_type(value,INTEGER) - self._number_of_sides = value + if not check_type(value,INTEGER): + self._number_of_sides = INTEGER(value) + else: + self._number_of_sides = value return property(**locals()) #################### @@ -85,8 +89,10 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument height is mantatory and can not be set to None') - check_type(value,REAL) - self._height = value + if not check_type(value,REAL): + self._height = REAL(value) + else: + self._height = value return property(**locals()) @apply @@ -97,6 +103,8 @@ def fset( self, value ): # Mandatory argument if value==None: raise AssertionError('Argument width is mantatory and can not be set to None') - check_type(value,REAL) - self._width = value + if not check_type(value,REAL): + self._width = REAL(value) + else: + self._width = value return property(**locals()) diff --git a/src/fedex_python/python/SCL/AggregationDataTypes.py b/src/fedex_python/python/SCL/AggregationDataTypes.py index 437936b86..901911f44 100644 --- a/src/fedex_python/python/SCL/AggregationDataTypes.py +++ b/src/fedex_python/python/SCL/AggregationDataTypes.py @@ -85,10 +85,17 @@ def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False, OPTIONAL=F raise TypeError("ARRAY upper bound must be an integer") if not (bound_1 <= bound_2): raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") + # the base type can be either a type or a string that defines a type + if type(base_type)==str: + if globals().has_key(base_type): + self._base_type = globals()[base_type] + else: + raise TypeError("%s does not name a type"%base_type) + else: + self._base_type = base_type # set up class attributes self._bound_1 = bound_1 self._bound_2 = bound_2 - self._base_type = base_type self._unique = UNIQUE self._optional = OPTIONAL # preallocate list elements diff --git a/src/fedex_python/python/SCL/ConstructedDataTypes.py b/src/fedex_python/python/SCL/ConstructedDataTypes.py index 18cdfbbdf..1ac59b9bd 100644 --- a/src/fedex_python/python/SCL/ConstructedDataTypes.py +++ b/src/fedex_python/python/SCL/ConstructedDataTypes.py @@ -29,39 +29,107 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -class ENUMERATION(list): - """ An ENUMERATION data type has as its domain an ordered set of names. The names represent +import sys + +def type_is_defined(type_str): + """ Look for the type definition in the global scope from the type string. + @TODO: find a better implementation than testing all modules! + """ + modules = sys.modules + for module in modules.values(): + if (module is not None) and (not '__' in module.__name__): + module_variables = vars(module) + if module_variables.has_key(type_str): + typ = module_variables[type_str] + return True, vars(module)[type_str] + return False,None + +class ENUMERATION(object): + """ EXPRESS definition : An ENUMERATION data type has as its domain an ordered set of names. The names represent values of the enumeration data type. + + Python implementation: + An enumeration is initialized from strings defining the types. + For instance, some EXPRESS definition: + TYPE ahead_or_behind = ENUMERATION OF + (ahead, + behind); + END_TYPE; -- ahead_or_behind + + is implemented in python with the line: + ahead_of_behind = ENUMERATION('ahead','behind') + + The ENUMERATION definition takes python strings because of the resolution ordre + that could be an issue. + + When getting the authorized types but the ENUMERATION, python looks for the object + definition from the globals() dictionary. """ - def __getattr__(self,attr_name): - if attr_name in self: - return attr_name - else: - raise AttributeError("This ENUMERATION has no element '%s'"%attr_name) - -class SELECT(list): + + def __init__(self,*kargs): + self._base_types = list(kargs) + + def get_allowed_types(self): + _auth_types = [] + for typ in self._base_types: + if type(typ)==str: + res,value = type_is_defined(typ) + if not res: + raise TypeError("'%s' does not name a type"%typ) + else: + _auth_types.append(value) + else: + _auth_types.append(ty) + return _auth_types + + def get_allowed_basic_types(self): + ''' if a select contains some subselect, goes down through the different + sublayers untill there is no more ''' + b = [] + _auth_types = self.get_allowed_types() + for _auth_type in _auth_types: + if isinstance(_auth_type,SELECT) or isinstance(_auth_type,ENUMERATION): + h = _auth_type.get_allowed_types() + b.extend(h) + return b + +class SELECT(object): """ A select data type has as its domain the union of the domains of the named data types in its select list. The select data type is a generalization of each of the named data types in its select list. """ - def get_aggregated_allowed_types(self): - """ This method returns a list of all types that are handle by this SELECT. - A SELECT can actually be an aggregate of many SELECTs""" - agg = [] - for allowed_type in self: - if isinstance(allowed_type,SELECT): - # in this case, we should recurse the select to get all subtypes - b = allowed_type.get_aggregated_allowed_types() - for elem in b: - agg.append(elem) + def __init__(self,*kargs): + self._base_types = list(kargs) + + def get_allowed_types(self): + _auth_types = [] + for typ in self._base_types: + if type(typ)==str: + res,value = type_is_defined(typ) + if not res: + raise TypeError("'%s' does not name a type"%typ) + else: + _auth_types.append(value) else: - agg.append(allowed_type) - return agg - + _auth_types.append(ty) + return _auth_types + + def get_allowed_basic_types(self): + ''' if a select contains some subselect, goes down through the different + sublayers untill there is no more ''' + b = [] + _auth_types = self.get_allowed_types() + for _auth_type in _auth_types: + if isinstance(_auth_type,SELECT) or isinstance(_auth_type,ENUMERATION): + h = _auth_type.get_allowed_types() + b.extend(h) + return b + if __name__=='__main__': - a = SELECT([1,2]) - b = SELECT([3,4]) - c = SELECT([a,b]) - print a.get_aggregated_allowed_types() - print c.get_aggregated_allowed_types() + class line: + pass + class point: + pass + a = ENUMERATION('line','point') + print a.get_allowed_types() \ No newline at end of file diff --git a/src/fedex_python/python/SCL/TypeChecker.py b/src/fedex_python/python/SCL/TypeChecker.py index 492612c12..7c6db89bd 100644 --- a/src/fedex_python/python/SCL/TypeChecker.py +++ b/src/fedex_python/python/SCL/TypeChecker.py @@ -31,7 +31,7 @@ from ConstructedDataTypes import ENUMERATION, SELECT -RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH = False +RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH = True def cast_python_object_to_aggregate(obj, aggregate): """ This function casts a python object to an aggregate type. For instance: @@ -42,26 +42,32 @@ def cast_python_object_to_aggregate(obj, aggregate): for idx in range(aggregate_lower_bound,aggregate_upper_bound+1): aggregate[idx] = obj[idx-aggregate_lower_bound] return aggregate - + def check_type(instance, expected_type): """ This function checks wether an object is an instance of a given class returns False or True """ type_match = False #by default, will be set to True if any match # in the case of an enumeration, we have to check if the instance is in the list - if isinstance(expected_type,ENUMERATION): - type_match = instance in expected_type - elif isinstance(expected_type,SELECT): + if (isinstance(expected_type,SELECT) or isinstance(expected_type,ENUMERATION)): # we check if the instance is of the type of any of the types that are in the SELECT - if type(instance) in expected_type.get_aggregated_allowed_types(): - type_match = True + allowed_types = expected_type.get_allowed_basic_types() + #if instance in allowed_types: + for allowed_type in allowed_types: + if isinstance(instance,allowed_type): + type_match = True + if not type_match: + if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH: + raise TypeError('Argument type must be %s (you passed %s)'%(allowed_types,type(instance))) + else: + print "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(allowed_types, type(instance)) + return False else: type_match = isinstance(instance,expected_type) - if not type_match: - if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH: - raise TypeError('Type of argument number_of_sides must be %s (you passed %s)'%(expected_type,type(instance))) - else: - print "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(expected_type, type(instance)) - return False - else: - return True + if not type_match: + if RAISE_EXCEPTION_IF_TYPE_DOES_NOT_MATCH: + raise TypeError('Argument type must be %s (you passed %s)'%(expected_type,type(instance))) + else: + print "WARNING: expected '%s' but passed a '%s', casting from python value to EXPRESS type"%(expected_type, type(instance)) + return False + return True diff --git a/src/fedex_python/python/SCL/Utils.py b/src/fedex_python/python/SCL/Utils.py new file mode 100644 index 000000000..7cce22494 --- /dev/null +++ b/src/fedex_python/python/SCL/Utils.py @@ -0,0 +1,70 @@ +# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com) +# All rights reserved. + +# This file is part of the StepClassLibrary (SCL). +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# Neither the name of the nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +''' This module provide string utils''' + +def process_nested_parent_str(attr_str,idx=0): + ''' + The first letter should be a parenthesis + input string: "(1,4,(5,6),7)" + output: ['1','4',['5','6'],'7'] + ''' + params = [] + current_param = '' + k = 0 + while (ktype) { - case array_: - fprintf(file,"ARRAY"); - break; - case bag_: - fprintf(file,"BAG"); - break; - case set_: - fprintf(file,"SET"); - break; - case list_: - fprintf(file,"LIST"); - break; - default: - break; - } - fprintf(file,"(%s,%s,",lower_str,upper_str); - //write base type - Type base_type = TYPEget_base_type(t); - if (TYPEis_aggregate(base_type)) { - process_aggregate(file,base_type); - fprintf(file,")"); //close parenthesis - } - else { - char * array_base_type = GetAttrTypeName(TYPEget_base_type(t)); - fprintf(file,"'%s')",array_base_type); - } - -} - /* * * A recursive function to export aggregate to python @@ -606,7 +564,8 @@ process_aggregate (FILE *file, Type t) { } else { char * array_base_type = GetAttrTypeName(TYPEget_base_type(t)); - fprintf(file,"%s)",array_base_type); + //fprintf(file,"%s)",array_base_type); + fprintf(file,"'%s')",array_base_type); } } @@ -999,19 +958,20 @@ TYPEenum_lib_print( const Type type, FILE * f ) { DICTdo_type_init( ENUM_TYPEget_items( type ), &de, OBJ_ENUM ); while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { strncpy( c_enum_ele, EnumCElementName( type, expr ), BUFSIZ ); + fprintf(f,"if (not '%s' in globals().keys()):\n",EXPget_name(expr)); if (is_python_keyword(EXPget_name(expr))) { - fprintf(f,"%s_ = '%s_'\n",EXPget_name(expr),EXPget_name(expr)); + fprintf(f,"\t%s_ = '%s_'\n",EXPget_name(expr),EXPget_name(expr)); } else { - fprintf(f,"%s = '%s'\n",EXPget_name(expr),EXPget_name(expr)); + fprintf(f,"\t%s = '%s'\n",EXPget_name(expr),EXPget_name(expr)); } } // then outputs the enum if (is_python_keyword(TYPEget_name( type ))) { - fprintf(f,"%s_ = ENUMERATION([",TYPEget_name( type )); + fprintf(f,"%s_ = ENUMERATION(",TYPEget_name( type )); } else { - fprintf(f,"%s = ENUMERATION([",TYPEget_name( type )); + fprintf(f,"%s = ENUMERATION(",TYPEget_name( type )); } /* set up the dictionary info */ @@ -1021,13 +981,13 @@ TYPEenum_lib_print( const Type type, FILE * f ) { while( 0 != ( expr = ( Expression )DICTdo( &de ) ) ) { strncpy( c_enum_ele, EnumCElementName( type, expr ), BUFSIZ ); if (is_python_keyword(EXPget_name(expr))) { - fprintf(f,"\n\'%s_,",EXPget_name(expr)); + fprintf(f,"\n\'%s_',",EXPget_name(expr)); } else { - fprintf(f,"\n\t%s,",EXPget_name(expr)); + fprintf(f,"\n\t'%s',",EXPget_name(expr)); } } - fprintf(f,"\n\t])\n"); + fprintf(f,"\n\t)\n"); } @@ -1281,13 +1241,17 @@ TYPEprint_descriptions( const Type type, FILES * files, Schema schema ) { if( TYPEget_RefTypeVarNm( type, typename_buf, schema ) ) { - fprintf(files->lib, "%s = ",TYPEget_name(type)); char * output = FundamentalType(type,0); if( TYPEis_aggregate( type ) ) { + fprintf(files->lib, "%s = ",TYPEget_name(type)); process_aggregate(files->lib,type); fprintf(files->lib,"\n"); } + else if(TYPEis_select(type)) { + TYPEselect_lib_print( type, files -> lib ); + } else { + fprintf(files->lib, "%s = ",TYPEget_name(type)); fprintf(files->lib,"%s\n",output); } } diff --git a/src/fedex_python/src/classes_wrapper_python.cc b/src/fedex_python/src/classes_wrapper_python.cc index 99aeef1aa..4bf3d4411 100644 --- a/src/fedex_python/src/classes_wrapper_python.cc +++ b/src/fedex_python/src/classes_wrapper_python.cc @@ -177,8 +177,8 @@ SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model, } SCOPEod; + // process redifined enumerations if( redefs ) { - // Here we process redefined enumerations. See note, 2 loops ago. SCOPEdo_types( scope, t, de ) if( t->search_id == CANPROCESS && TYPEis_enumeration( t ) ) { TYPEprint_descriptions( t, files, schema ); @@ -186,14 +186,7 @@ SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model, } SCOPEod; } - // Write Schema Classes for each entity - // This must be done *before* typedefs are defined - LISTdo( list, e, Entity ); - if( e->search_id == CANPROCESS ) { - ENTITYPrint( e, files, schema ); - e->search_id = PROCESSED; - } - LISTod; + /* do the select definitions next, since they depend on the others */ //fprintf( files->inc, "\n//\t***** Build the SELECT Types \t\n" ); // Note - say we have sel B, rename of sel A (as above by enum's). Here @@ -207,6 +200,15 @@ SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model, t->search_id = PROCESSED; } SCOPEod; + + // process each entity. This must be done *before* typedefs are defined + LISTdo( list, e, Entity ); + if( e->search_id == CANPROCESS ) { + ENTITYPrint( e, files, schema ); + e->search_id = PROCESSED; + } + LISTod; + LISTfree( list ); } diff --git a/src/fedex_python/src/selects_python.c b/src/fedex_python/src/selects_python.c index 09fa9d92e..4b901c1ec 100644 --- a/src/fedex_python/src/selects_python.c +++ b/src/fedex_python/src/selects_python.c @@ -684,22 +684,33 @@ void SELlib_print_protected( const Type type, FILE * f, const Schema schema ) { } - /******************* TYPEselect_lib_print prints the member functions (definitions) of a select class. *******************/ void TYPEselect_lib_print( const Type type, FILE * f, Schema schema ) { - // first prevent to use python keywords - if (is_python_keyword(TYPEget_name(type))) { - fprintf( f, "# SELECT TYPE %s_\n", TYPEget_name(type) ); - fprintf( f, "%s_=SELECT([",TYPEget_name(type)); + fprintf( f, "# SELECT TYPE %s_\n", TYPEget_name(type) ); + // writes the variable with strings + LISTdo( SEL_TYPEget_items( type ), t, Type ) + if (is_python_keyword(TYPEget_name(t))) { + fprintf(f,"if (not '%s_' in globals().keys()):\n",TYPEget_name(t)); + fprintf( f, "%s_ = '%s_'\n",TYPEget_name(t),TYPEget_name(t)); + } + else { + fprintf(f,"if (not '%s' in globals().keys()):\n",TYPEget_name(t)); + fprintf( f, "\t%s = '%s'\n",TYPEget_name(t),TYPEget_name(t)); + } + LISTod; + + // create the SELECT + if (is_python_keyword(TYPEget_name(type))) { + fprintf( f, "%s_ = SELECT(",TYPEget_name(type)); } else { - fprintf( f, "# SELECT TYPE %s\n", TYPEget_name(type) ); - fprintf( f, "%s=SELECT([",TYPEget_name(type)); + fprintf( f, "%s = SELECT(",TYPEget_name(type)); } + // first compute the number of types (necessary to insert commas) int nbr_select = 0; LISTdo( SEL_TYPEget_items( type ), t, Type ) @@ -709,15 +720,15 @@ TYPEselect_lib_print( const Type type, FILE * f, Schema schema ) { int num = 0; LISTdo( SEL_TYPEget_items( type ), t, Type ) if (is_python_keyword(TYPEget_name(t))) { - fprintf( f, "%s_",TYPEget_name(t)); + fprintf( f, "\n\t'%s_'",TYPEget_name(t)); } else { - fprintf( f, "%s",TYPEget_name(t)); + fprintf( f, "\n\t'%s'",TYPEget_name(t)); } if (num < nbr_select -1 ) fprintf(f,","); num++; LISTod; - fprintf(f,"])\n"); + fprintf(f,")\n"); } void From f053df82dbe91430c44177b552d6d11eaeef99b9 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Wed, 22 Feb 2012 17:58:55 +0100 Subject: [PATCH 15/19] Added other examples from unitary_schemas directory --- .../unitary_schemas/gcc_incomplete_type.py | 19 ++ .../examples/unitary_schemas/multiple_rep.py | 264 ++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 src/fedex_python/examples/unitary_schemas/gcc_incomplete_type.py create mode 100644 src/fedex_python/examples/unitary_schemas/multiple_rep.py diff --git a/src/fedex_python/examples/unitary_schemas/gcc_incomplete_type.py b/src/fedex_python/examples/unitary_schemas/gcc_incomplete_type.py new file mode 100644 index 000000000..72cec4b23 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/gcc_incomplete_type.py @@ -0,0 +1,19 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataTypes import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +maths_number = NUMBER +# SELECT TYPE atom_based_value_ +if (not 'maths_number' in globals().keys()): + maths_number = 'maths_number' +if (not 'atom_based_tuple' in globals().keys()): + atom_based_tuple = 'atom_based_tuple' +atom_based_value = SELECT( + 'maths_number', + 'atom_based_tuple') +atom_based_tuple = LIST(0,None,'atom_based_value') diff --git a/src/fedex_python/examples/unitary_schemas/multiple_rep.py b/src/fedex_python/examples/unitary_schemas/multiple_rep.py new file mode 100644 index 000000000..c0df05dd3 --- /dev/null +++ b/src/fedex_python/examples/unitary_schemas/multiple_rep.py @@ -0,0 +1,264 @@ +# 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. +from SCL.SCLBase import * +from SCL.SimpleDataTypes import * +from SCL.ConstructedDataTypes import * +from SCL.AggregationDataTypes import * +from SCL.TypeChecker import check_type +from SCL.Expr import * +text = STRING +representation_context = STRING +identifier = STRING +shape_definition = STRING +transformation = STRING +representation_item = STRING +characterized_product_definition = STRING +# SELECT TYPE characterized_definition_ +if (not 'characterized_object' in globals().keys()): + characterized_object = 'characterized_object' +if (not 'characterized_product_definition' in globals().keys()): + characterized_product_definition = 'characterized_product_definition' +if (not 'shape_definition' in globals().keys()): + shape_definition = 'shape_definition' +characterized_definition = SELECT( + 'characterized_object', + 'characterized_product_definition', + 'shape_definition') +label = STRING +characterized_object = STRING + +#################### + # ENTITY representation_relationship # +#################### +class representation_relationship(BaseEntityClass): + '''Entity representation_relationship definition. + + :param name + :type name:STRING + + :param rep_1 + :type rep_1:representation + + :param rep_2 + :type rep_2:representation + ''' + def __init__( self , name,rep_1,rep_2, ): + self.name = name + self.rep_1 = rep_1 + self.rep_2 = rep_2 + + @apply + def name(): + def fget( self ): + return self._name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument name is mantatory and can not be set to None') + if not check_type(value,STRING): + self._name = STRING(value) + else: + self._name = value + return property(**locals()) + + @apply + def rep_1(): + def fget( self ): + return self._rep_1 + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument rep_1 is mantatory and can not be set to None') + if not check_type(value,representation): + self._rep_1 = representation(value) + else: + self._rep_1 = value + return property(**locals()) + + @apply + def rep_2(): + def fget( self ): + return self._rep_2 + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument rep_2 is mantatory and can not be set to None') + if not check_type(value,representation): + self._rep_2 = representation(value) + else: + self._rep_2 = value + return property(**locals()) + +#################### + # ENTITY shape_representation_relationship # +#################### +class shape_representation_relationship(representation_relationship): + '''Entity shape_representation_relationship definition. + ''' + def __init__( self , representation_relationship__name , representation_relationship__rep_1 , representation_relationship__rep_2 , ): + representation_relationship.__init__(self , representation_relationship__name , representation_relationship__rep_1 , representation_relationship__rep_2 , ) + +#################### + # ENTITY representation # +#################### +class representation(BaseEntityClass): + '''Entity representation definition. + + :param name + :type name:STRING + + :param items + :type items:SET(1,None,'STRING') + + :param context_of_items + :type context_of_items:STRING + ''' + def __init__( self , name,items,context_of_items, ): + self.name = name + self.items = items + self.context_of_items = context_of_items + + @apply + def name(): + def fget( self ): + return self._name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument name is mantatory and can not be set to None') + if not check_type(value,STRING): + self._name = STRING(value) + else: + self._name = value + return property(**locals()) + + @apply + def items(): + def fget( self ): + return self._items + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument items is mantatory and can not be set to None') + if not check_type(value,SET(1,None,'STRING')): + self._items = SET(value) + else: + self._items = value + return property(**locals()) + + @apply + def context_of_items(): + def fget( self ): + return self._context_of_items + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument context_of_items is mantatory and can not be set to None') + if not check_type(value,STRING): + self._context_of_items = STRING(value) + else: + self._context_of_items = value + return property(**locals()) + +#################### + # ENTITY property_definition # +#################### +class property_definition(BaseEntityClass): + '''Entity property_definition definition. + + :param name + :type name:STRING + + :param definition + :type definition:characterized_definition + ''' + def __init__( self , name,definition, ): + self.name = name + self.definition = definition + + @apply + def name(): + def fget( self ): + return self._name + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument name is mantatory and can not be set to None') + if not check_type(value,STRING): + self._name = STRING(value) + else: + self._name = value + return property(**locals()) + + @apply + def definition(): + def fget( self ): + return self._definition + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument definition is mantatory and can not be set to None') + if not check_type(value,characterized_definition): + self._definition = characterized_definition(value) + else: + self._definition = value + return property(**locals()) + +#################### + # ENTITY context_dependent_shape_representation # +#################### +class context_dependent_shape_representation(BaseEntityClass): + '''Entity context_dependent_shape_representation definition. + + :param representation_relation + :type representation_relation:shape_representation_relationship + ''' + def __init__( self , representation_relation, ): + self.representation_relation = representation_relation + + @apply + def representation_relation(): + def fget( self ): + return self._representation_relation + def fset( self, value ): + # Mandatory argument + if value==None: + raise AssertionError('Argument representation_relation is mantatory and can not be set to None') + if not check_type(value,shape_representation_relationship): + self._representation_relation = shape_representation_relationship(value) + else: + self._representation_relation = value + return property(**locals()) + +#################### + # ENTITY definitional_representation_relationship # +#################### +class definitional_representation_relationship(representation_relationship): + '''Entity definitional_representation_relationship definition. + ''' + def __init__( self , representation_relationship__name , representation_relationship__rep_1 , representation_relationship__rep_2 , ): + representation_relationship.__init__(self , representation_relationship__name , representation_relationship__rep_1 , representation_relationship__rep_2 , ) + +#################### + # ENTITY component_2d_location # +#################### +class component_2d_location(context_dependent_shape_representation,shape_representation_relationship,definitional_representation_relationship): + '''Entity component_2d_location definition. + + :param context_dependent_shape_representation_representation_relation + :type context_dependent_shape_representation_representation_relation:component_2d_location + ''' + def __init__( self , context_dependent_shape_representation__representation_relation , ): + context_dependent_shape_representation.__init__(self , context_dependent_shape_representation__representation_relation , ) + shape_representation_relationship.__init__(self , ) + definitional_representation_relationship.__init__(self , ) + + @apply + def context_dependent_shape_representation_representation_relation(): + def fget( self ): + return EvalDerivedAttribute(self,'''SELF''') + def fset( self, value ): + # 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()) From 59cf7ec1ed84cb3e61453bfbde819d86d9faea83 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Wed, 22 Feb 2012 22:42:06 +0100 Subject: [PATCH 16/19] Fixed unbounded list support --- .../python/SCL/AggregationDataTypes.py | 138 +++++++++++------- .../python/SCL/SimpleDataTypes.pyc | Bin 7815 -> 0 bytes src/fedex_python/python/SCL/__init__.pyc | Bin 320 -> 0 bytes src/fedex_python/python/SCL_unittest.py | 80 ++++++++++ 4 files changed, 162 insertions(+), 56 deletions(-) delete mode 100644 src/fedex_python/python/SCL/SimpleDataTypes.pyc delete mode 100644 src/fedex_python/python/SCL/__init__.pyc diff --git a/src/fedex_python/python/SCL/AggregationDataTypes.py b/src/fedex_python/python/SCL/AggregationDataTypes.py index 901911f44..42bee7cc6 100644 --- a/src/fedex_python/python/SCL/AggregationDataTypes.py +++ b/src/fedex_python/python/SCL/AggregationDataTypes.py @@ -32,37 +32,18 @@ from SimpleDataTypes import * from TypeChecker import * -class BaseAggregate(object): - """ A class that define common properties to ARRAY, LIST, SET and BAG. +def type_from_string(type_str): + """ Look for the type definition in the global scope from the type string. + @TODO: find a better implementation than testing all modules! """ - def __init__( self , bound1 , bound2 , base_type ): - # check that bound1bound2: - raise AssertionError("bound1 shall be less than or equal to bound2") - self._bound1 = bound1 - self._bound2 = bound2 - self._base_type = base_type - - def __getitem__(self, index): - if indexself._bound2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) - else: - return list.__getitem__(self,index) - - def __setitem__(self,index,value): - if indexself._bound2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) - elif not isinstance(value,self._base_type): - raise TypeError("%s type expected, passed %s."%(self._base_type, type(value))) - else: - # first find the length of the list, and extend it if ever - # the index is - list.__setitem__(self,index,value) + modules = sys.modules + for module in modules.values(): + if (module is not None) and (not '__' in module.__name__): + module_variables = vars(module) + if module_variables.has_key(type_str): + typ = module_variables[type_str] + return True, vars(module)[type_str] + return False,None class ARRAY(object): """An array data type has as its domain indexed, fixed-size collections of like elements. The lower @@ -144,22 +125,28 @@ def __init__( self , bound_1 , bound_2 , base_type , UNIQUE = False): if not type(bound_1)==int: raise TypeError("LIST lower bound must be an integer") # bound_2 can be set to None - if not type(bound_2)==int: + self._unbounded = False + if bound_2 == None: + self._unbounded = True + elif not type(bound_2)==int: raise TypeError("LIST upper bound must be an integer") if not bound_1>=0: raise AssertionError("LIST lower bound must be greater of equal to 0") - if not (bound_1 <= bound_2): + if (type(bound_2)==int and not (bound_1 <= bound_2)): raise AssertionError("ARRAY lower bound must be less than or equal to upper bound") # set up class attributes self._bound_1 = bound_1 self._bound_2 = bound_2 self._base_type = base_type self._unique = UNIQUE - self._optional = OPTIONAL - # preallocate list elements - list_size = bound_2 - bound_1 + 1 - self._container = list_size*[None] - + # preallocate list elements if bounds are both integers + if not self._unbounded: + list_size = bound_2 - bound_1 + 1 + self._container = list_size*[None] + # for unbounded list, this will come after + else: + self._container = [None] + def bound_1(self): return self._bound_1 @@ -167,29 +154,68 @@ def bound_2(self): return self._bound_2 def __getitem__(self, index): - if indexself._bound_2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + # case bounded + if not self._unbounded: + if indexself._bound_2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + else: + value = self._container[index-self._bound_1] + if value == None: + raise AssertionError("Value with index %i not defined. Please set the value first."%index) + return value + #case unbounded else: - value = self._container[index-self._bound_1] - if not self._optional and value==None: - raise AssertionError("Not OPTIONAL prevent the value with index %i from being None (default). Please set the value first."%index) - return value + if index-self._bound_1>len(self._container): + raise AssertionError("Value with index %i not defined. Please set the value first."%index) + else: + value = self._container[index-self._bound_1] + if value == None: + raise AssertionError("Value with index %i not defined. Please set the value first."%index) + return value def __setitem__(self, index, value): - if indexself._bound_2): - raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + # case bounded + if not self._unbounded: + if indexself._bound_2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound_2,index)) + else: + # first check the type of the value + check_type(value,self._base_type) + # then check if the value is already in the array + if self._unique: + if value in self._container: + raise AssertionError("UNIQUE keyword prevent inserting this instance.") + self._container[index-self._bound_1] = value + # case unbounded else: - # first check the type of the value - check_type(value,self._base_type) - # then check if the value is already in the array - if self._unique: - if value in self._container: - raise AssertionError("UNIQUE keyword prevent inserting this instance.") - self._container[index-self._bound_1] = value + if indexC6DR!fIV zt~p#?f;_Z!9{L9g^hfle=s)RS=~Lg@?>j?sZ%&-1jV)kDyv)qGf9K5MKmK`P?(ZjC z4+B;FP2vA<@UwMKsZgl{jGhXAqQaW`MyY2?eSU!ZDP?M^jf*qY(%)TbIP3K_6M`d%&CL(Dm-7Vo3AF#D|11G7u1uQO21KF zcv0Q|*nsdQ^~_TT7nQlF!Ugr({g1=T#hWWbZx-dvYkUK?7Uaz(#p^}6UQhXN_q6}`YaIeGz4{xZw`cJ8`4GeR4)4=9glpI>^XGRBUKg*3h)oEMr z>^;;Q*Eg?kzP+(=YvY3t-l=b|%;hs!wfp$Dx3?RW4WM~-n>${`V4xD{8Dou>fDI0& zRAaAR)Z9a=E%hB zd%5Y|iNVf;sFnHI>AKB=^|lGkNz)0rUi{m;^I&}snv2a{7V%KH$Y0gg`eng=Io3o zdTVTNJqY-Uf0f@~#LckZ!`=DL{t42FRq5`T@#7addnV@f<5eAH<+b*cP}?Aad(vlR z9~V1zP4B=ptkCeCTMv8$ARX4d#7;rlUuU##=AFV*QSKcN18(FFZ6PKStBfh z$RZ}1j2XSWvaEln-3~Wy-W-4ZQ5jH8bHae)!eVx#5KM#_lC2N~v43RX&y#(-$+ z6d=(hpVs=KlC(#0F%z0g6PS7g*g((G5H`C0m%tv~?}>e@Z5+Y@@?ztMobZ*&QtLF^ zGC;q~bkieH2Qx#CF)E7?DC7}nb(*WxLeYJP#gqG#gxz`&0dUcHi3#8gKnl)T zjPseN{U|dbbq%EqIjzebhUf_EJ5cYX7H%bOnwvwQvtXy=y|to0Wr9i4VRB`jsW6)i zyZlv2LJldxP*_v3{RFAP@d#ZY7lKPsn+%V}vXDe9Rt<8{ayw4_d|48!EU6Pb8-&{i zalgSl{<5%?7=9f;ho!FrOZjAHcYpi-^U8>CgVVoak;t+SeMN~g!i&m>a^5In!iU8; z6KF{@2#spr?@)Uo0qr%Uc~EqEf0Zg{zWumT`7~5cgYWG(c6RRvxRSpYCa`O8l}h8T zPW;XkX3f*SNf7Mx>Y#%O#0D5Rkv#PM zx!q|qX}I}Nj-V0*TopAHTK!&1Tg4`Mhnu-W266^;oQx^ZWg82-mZ4fiPrv1CM03h6ad)Hp+IbsL#TP6W10CXp?(%v{s=#pU9T3|^})mY zJ9qw@!^+pl1|kdNCr%FuDMRQrc{ry|@=j(j+f})UiL7r{b=!|&XBKk(M9Rm)#fFa@ z?`)PdN`x*LF3t;NqMgQY5yBQA3OxW^bkaBkw!wKwU9y7Y8s1Ite5>H(!;%mEp))JE zbSY_K2|X@IyFFBFEtp**ihH-x6vb^a(8nsO#lZA(@PQ(?Vn+5aq#o)G;M|Pk0zyI# zALV8MrpN~wr=C~oLOgRnsa)t>Q7zow+1+Y^Z9QV$H*A`_cTCO2Am#QH@oAYnGh!ey!)s|8BFog<9%GOE=d z!i-DRECC#tAVd6bWdKUL$r7L)p#~@jRN8!js=lQH7^sbr1Y{rG$C#erGI+c z4@>-;&H^IDc)~6s5CRPjPT*`bWux>!bCi&bf`R7(2cSUx2*80Opwz(Vwn}gdouY22 zkby8U+9-|wjlY11#2+#34$)}=L#|ZhsjrnnDtuO}I;ZSZ=A4Mli*{sUj+;$^wFb{n z4Vl7YwK#_~R>kKB2kalMPk8}U|4injq3TtV@wg|F{S6mi*C&4)B7~}r8)x=Pv%s5ReAU$y=l%URwkJBSvUjDvp-;efkEGvQ;pw`^Hr3I$zex~ z&T1XGbQi5MF{u4L<}%io#R6ztRy}mOk87j1`ng^fyDUp(nMXK&NU^e}A0fRXF3+ zoU2n0F#~`9`n9v|&vE^n1qFb)%9e`SSi2GNza3dn9(aTZ4|;9^Bc|GPWX|xuIWg;| zjPDm8hVVeu7cod*P(FS*6k`{$!Dwu}#({06#ykg}IvT7S1ri^-LSMd-u)LLrw;w)y zu)Ve0pz_3)LeiJ9C1W6?k+D7SJh}R@5L4{-q5Hn{D=N&cVVJ2c&M&>ObZ+U*#ktw@ UGqt6a3*NLh@68U4<=wpZAM32p00000 diff --git a/src/fedex_python/python/SCL/__init__.pyc b/src/fedex_python/python/SCL/__init__.pyc deleted file mode 100644 index 36ca58348cd9430a16921ee3a3ec73d85677cc23..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 320 zcmYL^%}&EG497hfD*_=d+`0Bd1ZRX89k&XQ3YT4?tTA0g+D5U5+SlSucom)iXPVR~ z{`&i8S^oXIIQtovuQeQACh<{>uEkmTGq6WskHOBto`79Ilfhc_466K87)}#aQ9c<$ zzD&7mgU6L&^F9V7z7lQOG!YxauJ5MCxik_|Y_a~rxCe{ABaXY8(N5r8z~>=EUP$t0 zBH!J<sR~2I@ydf&xCYm@ZinaPgi-QiM ekexaNxk+j5I>%byh?b7MZ+pA*_>h*982kfLD^j}v diff --git a/src/fedex_python/python/SCL_unittest.py b/src/fedex_python/python/SCL_unittest.py index 1a51a4930..2225cc45c 100644 --- a/src/fedex_python/python/SCL_unittest.py +++ b/src/fedex_python/python/SCL_unittest.py @@ -217,6 +217,86 @@ def test_array_optional(self): b[2] = REAL(5) b[3] = REAL(5) +# +# AggregationDataTypeSimple +# +class TestLIST(unittest.TestCase): + ''' + LIST test + ''' + def test_create_bounded_list(self): + LIST(1,7,REAL) + #upper and lower bounds can be negative + LIST(1,5,INTEGER) + # they even can be both 0 + LIST(0,0,REAL) + LIST(1,1,BOOLEAN) + # lower bound should be less or equal than upper bound + try: + LIST(3,2,REAL) + except AssertionError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + # lower bound should be greater or equal than zero + try: + LIST(-1,2,REAL) + except AssertionError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + + def test_create_unbounded_list(self): + a = LIST(0,None,REAL) + a[6] = REAL(6) + self.assertEqual(a[6],6) + b = LIST(10,None,REAL) + a[10] = REAL(7) + self.assertEqual(a[10],7) + + def test_list_bounds(self): + a = LIST(3,8,REAL) + try: + a[2] + except IndexError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + try: + a[9] + except IndexError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + + def test_list_unique(self): + # if UNIQUE is not set to True (False by default), + # the array may contain the same instance at different + # positions + a = LIST(1,4,REAL) + a[3] = REAL(4) + a[4] = REAL(4) + # however, if UNIQUE, then every instances in the + # array must be different + a = LIST(1,4,REAL,UNIQUE=True) + a[3] = REAL(4) + try: + a[3] = REAL(4) + except AssertionError: + pass + except e: + self.fail('Unexpected exception thrown:', e) + else: + self.fail('ExpectedException not thrown') + # # TypeChecker # From 1bbbc219ba9088d7f37a0ac5b2c566d296f45b50 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Wed, 22 Feb 2012 23:09:04 +0100 Subject: [PATCH 17/19] Fixed version and url in setup.py --- src/fedex_python/python/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fedex_python/python/setup.py b/src/fedex_python/python/setup.py index 6d90931c1..bda974879 100644 --- a/src/fedex_python/python/setup.py +++ b/src/fedex_python/python/setup.py @@ -34,10 +34,10 @@ from distutils.core import setup setup(name='SCL', - version='0.4', + version='0.5', description='Python STEP Class Library', author='Thomas Paviot', author_email='tpaviot@gmail.com', - url='http://www.python.org/sigs/distutils-sig/', + url='https://github.com/mpictor/StepClassLibrary', packages=['SCL'], ) \ No newline at end of file From ca155ce50de1913a638ea9dd03b708f6dd2c4b2d Mon Sep 17 00:00:00 2001 From: tpaviot Date: Wed, 22 Feb 2012 23:16:24 +0100 Subject: [PATCH 18/19] Fixed regression --- .../python/SCL/AggregationDataTypes.py | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/fedex_python/python/SCL/AggregationDataTypes.py b/src/fedex_python/python/SCL/AggregationDataTypes.py index 42bee7cc6..ec77152e1 100644 --- a/src/fedex_python/python/SCL/AggregationDataTypes.py +++ b/src/fedex_python/python/SCL/AggregationDataTypes.py @@ -32,18 +32,37 @@ from SimpleDataTypes import * from TypeChecker import * -def type_from_string(type_str): - """ Look for the type definition in the global scope from the type string. - @TODO: find a better implementation than testing all modules! +class BaseAggregate(object): + """ A class that define common properties to ARRAY, LIST, SET and BAG. """ - modules = sys.modules - for module in modules.values(): - if (module is not None) and (not '__' in module.__name__): - module_variables = vars(module) - if module_variables.has_key(type_str): - typ = module_variables[type_str] - return True, vars(module)[type_str] - return False,None + def __init__( self , bound1 , bound2 , base_type ): + # check that bound1bound2: + raise AssertionError("bound1 shall be less than or equal to bound2") + self._bound1 = bound1 + self._bound2 = bound2 + self._base_type = base_type + + def __getitem__(self, index): + if indexself._bound2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) + else: + return list.__getitem__(self,index) + + def __setitem__(self,index,value): + if indexself._bound2): + raise IndexError("ARRAY index out of bound (upper bound is %i, passed %i)"%(self._bound2,index)) + elif not isinstance(value,self._base_type): + raise TypeError("%s type expected, passed %s."%(self._base_type, type(value))) + else: + # first find the length of the list, and extend it if ever + # the index is + list.__setitem__(self,index,value) class ARRAY(object): """An array data type has as its domain indexed, fixed-size collections of like elements. The lower From b84921e9d8b496915d44d576bc982f3aecffd609 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Thu, 23 Feb 2012 05:25:28 +0100 Subject: [PATCH 19/19] Fixed unittest failure --- src/fedex_python/python/SCL_unittest.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/fedex_python/python/SCL_unittest.py b/src/fedex_python/python/SCL_unittest.py index 2225cc45c..6c26055cb 100644 --- a/src/fedex_python/python/SCL_unittest.py +++ b/src/fedex_python/python/SCL_unittest.py @@ -324,13 +324,5 @@ class P: def test_check_enum_type(self): enum = ENUMERATION(["my","string"]) -# -# Cast from list to aggregates -# -class CastTypeChecker(unittest.TestCase): - def test_cast_list_to_array(self): - a = [1.,2.,3.] - b = cast_python_list_to_aggregate(a,ARRAY(1,3,REAL)) - unittest.main()