Implemeted functions/rules prototypes (to be continued)

This commit is contained in:
tpaviot
2012-05-11 12:08:23 +02:00
parent ae8d48481a
commit 2dcfaedae2
6 changed files with 171 additions and 3 deletions
+11
View File
@@ -132,6 +132,13 @@ struct Scope_ {
#define SCOPEdo_entities(s,t,de) DICTdo_type_init(s->symbol_table,&de,OBJ_ENTITY); { \
Entity t; \
while (0 != (t = (Entity)DICTdo(&de))) {
#define SCOPEdo_functions(s,t,de) DICTdo_type_init(s->symbol_table,&de,OBJ_FUNCTION); { \
Entity t; \
while (0 != (t = (Entity)DICTdo(&de))) {
#define SCOPEdo_rules(s,t,de) DICTdo_type_init(s->symbol_table,&de,OBJ_RULE); { \
Entity t; \
while (0 != (t = (Entity)DICTdo(&de))) {
#define SCOPEod }}
/***********************/
@@ -143,5 +150,9 @@ extern SCL_EXPRESS_EXPORT void SCOPE_get_entities PROTO( ( Scope, Linked_Lis
extern SCL_EXPRESS_EXPORT Linked_List SCOPEget_entities PROTO( ( Scope ) );
extern SCL_EXPRESS_EXPORT Linked_List SCOPEget_entities_superclass_order PROTO( ( Scope ) );
extern SCL_EXPRESS_EXPORT Generic SCOPEfind PROTO( ( Scope, char *, int ) );
extern SCL_EXPRESS_EXPORT void SCOPE_get_functions PROTO( ( Scope, Linked_List ) );
extern SCL_EXPRESS_EXPORT Linked_List SCOPEget_functions PROTO( ( Scope ) );
extern SCL_EXPRESS_EXPORT void SCOPE_get_rules PROTO( ( Scope, Linked_List ) );
extern SCL_EXPRESS_EXPORT Linked_List SCOPEget_rules PROTO( ( Scope ) );
#endif /* SCOPE_H */
+43
View File
@@ -65,6 +65,49 @@ void SCOPE_get_entities( Scope scope, Linked_List result ) {
}
}
/** SCOPE_get_functions
* \sa SCOPEget_functions
*/
void SCOPE_get_functions( Scope scope, Linked_List result ) {
DictionaryEntry de;
Generic x;
DICTdo_type_init( scope->symbol_table, &de, OBJ_FUNCTION );
while( 0 != ( x = DICTdo( &de ) ) ) {
LISTadd_last( result, x );
}
}
/** SCOPE_get_functions
* \sa SCOPEget_functions
*/
Linked_List SCOPEget_functions( Scope scope ) {
Linked_List result = LISTcreate();
SCOPE_get_functions( scope, result );
return( result );
}
/** SCOPE_get_rules
* \sa SCOPEget_rules
*/
void SCOPE_get_rules( Scope scope, Linked_List result ) {
DictionaryEntry de;
Generic x;
DICTdo_type_init( scope->symbol_table, &de, OBJ_RULE );
while( 0 != ( x = DICTdo( &de ) ) ) {
LISTadd_last( result, x );
}
}
/** SCOPE_get_functions
* \sa SCOPEget_functions
*/
Linked_List SCOPEget_rules( Scope scope ) {
Linked_List result = LISTcreate();
SCOPE_get_rules( scope, result );
return( result );
}
/**
** \param scope scope to examine
** \return entities defined locally
+2
View File
@@ -103,6 +103,8 @@ FILE * FILEcreate( const char * );
void FILEclose( FILE * );
const char * ClassName( const char * );
const char * ENTITYget_classname( Entity );
void FUNCPrint( Function, FILES *, Schema );
void RULEPrint( Rule, FILES *, Schema );
void ENTITYPrint( Entity, FILES *, Schema );
const char * StrToConstant( const char * );
void TYPEselect_print( Type, FILES *, Schema );
+39
View File
@@ -0,0 +1,39 @@
# 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 <ORGANIZATION> 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.
__doc__ = "This module defines EXPRESS rules"
class Rule(object):
'''
This class describes a RULE
@TODO: to be implemented
'''
pass
+57 -1
View File
@@ -882,6 +882,63 @@ void
ENTITYincode_print( Entity entity, FILE * file, Schema schema ) {
}
/******************************************************************
** Procedure: RULEPrint
** Parameters: Rule *rule -- rule being processed
** FILE* file -- file being written to
** Returns:
** Description: drives the functions for printing out code in lib
** and initialization files for a specific rule
** Status: started 2012/3/1
******************************************************************/
void
RULEPrint(Rule rule, FILES * files, Schema schema) {
char * n = RULEget_name( rule );
char * param_name;
fprintf( files->lib, "\n####################\n # RULE %s #\n####################\n", n );
/* write function definition */
fprintf(files->lib, "%s = Rule()\n",n);
/* write parameter list */
//LISTdo(RULEget_parameters( rule ), v, Variable)
// param_name = EXPRto_string( VARget_name( v ) );
// fprintf(files->lib, "%s,",param_name);
//LISTod
//close function prototype
//fprintf(files->lib,"):\n");
/* so far, just raise "not implemented" */
//fprintf(files->lib, "\traise NotImplemented('Function %s not implemented)')\n",n);
}
/******************************************************************
** Procedure: FUNCPrint
** Parameters: Function *function -- function being processed
** FILE* file -- file being written to
** Returns:
** Description: drives the functions for printing out code in lib
** and initialization files for a specific function
** Status: started 2012/3/1
******************************************************************/
void
FUNCPrint(Function function, FILES * files, Schema schema) {
char * n = FUNCget_name( function );
char * param_name;
fprintf( files->lib, "\n####################\n # FUNCTION %s #\n####################\n", n );
/* write function definition */
fprintf(files->lib, "def %s(",n);
/* write parameter list */
LISTdo(FUNCget_parameters( function ), v, Variable)
param_name = EXPRto_string( VARget_name( v ) );
fprintf(files->lib, "%s,",param_name);
LISTod
//close function prototype
fprintf(files->lib,"):\n");
/* so far, just raise "not implemented" */
fprintf(files->lib, "\traise NotImplemented('Function %s not implemented)')\n",n);
}
/******************************************************************
** Procedure: ENTITYPrint
** Parameters: Entity *entity -- entity being processed
@@ -893,7 +950,6 @@ ENTITYincode_print( Entity entity, FILE * file, Schema schema ) {
** Status: complete 1/15/91
******************************************************************/
void
ENTITYPrint( Entity entity, FILES * files, Schema schema ) {
char * n = ENTITYget_name( entity );
+19 -2
View File
@@ -3,6 +3,7 @@
#include <string.h>
#include "complexSupport.h"
extern int corba_binding;
void use_ref( Schema, Express, FILES * );
@@ -142,6 +143,8 @@ void
SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model,
ComplexCollect * col, int cnt ) {
Linked_List list = SCOPEget_entities_superclass_order( scope );
Linked_List function_list = SCOPEget_functions(scope);
Linked_List rule_list = SCOPEget_rules(scope);
DictionaryEntry de;
Type i;
int redefs = 0;// index = 0;
@@ -207,9 +210,21 @@ SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model,
ENTITYPrint( e, files, schema );
e->search_id = PROCESSED;
}
LISTod;
LISTod;
LISTfree( list );
// process each function. This must be done *before* typedefs are defined
LISTdo( function_list, f, Function );
FUNCPrint( f, files, schema );
LISTod;
LISTfree( function_list );
// process each rule. This must be done *before* typedefs are defined
LISTdo( rule_list, r, Rule );
RULEPrint( r, files, schema );
LISTod;
LISTfree( rule_list );
}
@@ -346,6 +361,8 @@ SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol,
fprintf(libfile,"from SCL.AggregationDataTypes import *\n");
fprintf(libfile,"from SCL.TypeChecker import check_type\n");
fprintf(libfile,"from SCL.Expr import *\n");
fprintf(libfile,"from SCL.Builtin import *\n");
fprintf(libfile,"from SCL.Rules import *\n");
/********* export schema name *******/
fprintf(libfile,"\nschema_name = '%s'\n\n",SCHEMAget_name(schema));