/**************************************************************************
* PROJECT: DEMETER Version 4.0
* MODULE: GENERATION
* FILE: gen_prop_pat.c
* SYSTEM: C++ AT&T version 2.0 on sun, UNIX 4.3 BSD
*--------------------------------------------------------------------------
* COPYRIGHT (c) 1990 Northeastern University
* Prof. Karl J. Lieberherr
*--------------------------------------------------------------------------
* AUTHOR: Walter Hursch
*
* DATE: July 3, 1991
* REVISED:
*--------------------------------------------------------------------------
* DESCRIPTION:
* Generates some sample propagation patterns for the directory
* COMMON. This collection serves as a basis for simple programs
* that can be done with propagation patterns. It includes the
* following files:
*
* - void DEM_count_Ident( int& c )
* - void DEM_collect_Ident( Ident_list *l )
* - void DEM_print_Ident()
* - void DEM_traverse()
*
**************************************************************************/
/**************************************************************************
Class dictionary used (intermediate notation):
;;; produced by extract-cd '(I-P1|O-P1)'
;;; produced by extract-cd 'O-P1'
; : O-P1: intermediate notation
;;; O-P1=I-P2
Demeter_in = Input.
Input :
Cd_graph
*common*.
Cd_graph = < adjacencies > Nlist(Adjacency)
["*terminal_sets*" Comma_list(Vertex) "."].
Adjacency =
< source > Vertex
< ns > Neighbors
["*inherits_from*" Comma_list(Term)]
"." .
Neighbors :
Intermediate_ns
*common*.
Intermediate_ns :
Repetit |
Non_repetit *common*.
Non_repetit : Instantiable | Abstract *common*
List(Int_part).
Instantiable = "instantiable=".
Repetit = "repetition=" Term
[ Non_empty].
Non_empty = "*non_empty*".
Abstract = "abstract=".
Int_part : Required_int_part | Optional_int_part
*common* Labeled.
Required_int_part = "*required*".
Optional_int_part = "*optional*".
Vertex = < vertex_name > Ident .
Opt_labeled_term :
Labeled
*common* Term.
Labeled = "<" < label_name > Ident ">" .
Term :
Normal
*common* Vertex .
Normal = .
; parameterized classes
List(S) ~ {S}.
Nlist(S) ~ S {S}.
Comma_list(S) ~ S {"," S}.
**************************************************************************/
#include "generate.h"
#include
#include
#include
/*
* demeter_in = < input > input .
*/
void Demeter_in::gen_prop_pat( char* path )
{
const int string_size_max = 256;
fstream outFile;
char pp_filename[string_size_max];
char first_classname[string_size_max];
strcpy( first_classname, this -> get_first_classname() );
// create DEM_count_Ident.pp
strcpy( pp_filename, path );
strcat( pp_filename, "/DEM-count-ident.pp" );
outFile.open( pp_filename, ios::out );
if ( !outFile ) {
cerr << "gen_prop_pat error: cannot open "
<< pp_filename << " for output.\n";
exit( -1 );
}
outFile << "// Sample propagation pattern to count all objects of the\n"
<< "// class Ident in an object of class "
<< first_classname << ".\n\n"
<< "// Note: if class Ident is not used this propagation pattern \n"
<< "// does not work\n" << endl;
outFile << "*propagate*\n"
<< "*operation* void DEM_count_Ident( int& c )\n"
<< "*from* " << first_classname << " *to* Ident\n\n"
<< "*wrapper* DemIdent\n"
<< "(@ c++; )@" << endl;
outFile.close();
// create DEM_collect_Ident.pp
strcpy( pp_filename, path );
strcat( pp_filename, "/DEM-collect-ident.pp" );
outFile.open( pp_filename, ios::out );
if ( !outFile ) {
cerr << "gen_prop_pat error: cannot open "
<< pp_filename << " for output.\n";
exit( -1 );
}
outFile << "// Sample propagation pattern to collect all objects of the\n"
<< "// class Ident in an object of class "
<< first_classname << ".\n\n"
<< "// Note: if the classes Ident and Ident_list are not used \n"
<< "// this propagation pattern does not work\n" << endl;
outFile << "*propagate*\n"
<< "*operation* void DEM_collect_Ident( Ident_list * l )\n"
<< "*from* " << first_classname << " *to* DemIdent\n"
<< "*wrapper* DemIdent\n"
<< "(@ l -> append( this ); @)" << endl;
outFile.close();
// create DEM_print_Ident.pp
strcpy( pp_filename, path );
strcat( pp_filename, "/DEM-print-ident.pp" );
outFile.open( pp_filename, ios::out );
if ( !outFile ) {
cerr << "gen_prop_pat error: cannot open "
<< pp_filename << " for output.\n";
exit( -1 );
}
outFile << "// Sample propagation pattern to print all objects of the\n"
<< "// class Ident in an object of class "
<< first_classname << ".\n\n"
<< "// Note: if class Ident is not used this propagation pattern \n"
<< "// does not work\n" << endl;
outFile << "*propagate*\n"
<< "*operation* void DEM_print_Ident()\n"
<< "*from* " << first_classname << " *to* DemIdent\n"
<< "*wrapper* DemIdent\n"
<< "(@ this -> g_print(); @)" << endl;
outFile.close();
// create DEM_traverse.pp
strcpy( pp_filename, path );
strcat( pp_filename, "/DEM-traverse.pp" );
outFile.open( pp_filename, ios::out );
if ( !outFile ) {
cerr << "gen_prop_pat error: cannot open "
<< pp_filename << " for output.\n";
exit( -1 );
}
outFile << "// Sample propagation pattern to traverse all objects in an\n"
<< "// an object of class " << first_classname << ".\n\n";
outFile << "*propagate*\n"
<< "*operation* void DEM_traverse()\n"
<< "*from* " << first_classname << endl;
outFile.close();
}
/*-------------------------------------------------------------------------
* Method: char *get_first_classname()
*
* Fetches the first class name in the data dictionary.
*-----------------------------------------------------------------------*/
char *Demeter_in::get_first_classname()
{
return ( input -> get_first_classname() );
}
char *Input::get_first_classname() { return NULL;}
char *Cd_graph::get_first_classname()
{
return ( adjacencies -> get_first_classname() );
}
char *Adjacency_Nlist::get_first_classname()
{
Adjacency_list_iterator next_arg( *this );
Adjacency_ first_arg = next_arg();
// first_arg is always non-NULL because list is non-empty.
return ( first_arg -> get_class_name() );
}