CSE 321 Closed Lab 4 Warm-up Exercise


This assignment has two parts. First, you will implement the Pretty_Print extension for Program (see the 321 class notes for the specs). Then, you will implement the Program_Kernel_1 component which is an implementation of Program_Kernel (see the 321 class notes for the specs). Look around the Program_Pretty_Print_1 and the Program_Kernel_1 components included in this handout. In Program_Kernel_1 pay particular attention to:

Before closed-lab on Friday, implement each of the operations in Program_Pretty_Print_1 and in Program_Kernel_1. Electronic copies of the necessary files will be provided in closed lab. Please do not attempt to complete and compile these files before closed lab.

Program_Pretty_Print_1

//  /*-------------------------------------------------------------------*\
//  |   Concrete Template : Program_Pretty_Print_1
//  \*-------------------------------------------------------------------*/

#ifndef CT_PROGRAM_PRETTY_PRINT_1
#define CT_PROGRAM_PRETTY_PRINT_1 1

///------------------------------------------------------------------------
/// Global Context --------------------------------------------------------
///------------------------------------------------------------------------

#include "AT/Program/Pretty_Print.h"
   
///------------------------------------------------------------------------
/// Interface -------------------------------------------------------------
///------------------------------------------------------------------------

concrete_template <
        concrete_instance class Statement,
        /*!
            implements
                abstract_instance Statement_Kernel <Statement>,
	    implements
	        abstract_instance Statement_Pretty_Print <Statement>
        !*/
        concrete_instance class Program_Base
        /*!
            implements
                abstract_instance Program_Kernel <Statement>
        !*/
    >
class Program_Pretty_Print_1 :
    implements
        abstract_instance Program_Pretty_Print <Statement>,
    extends
        concrete_instance Program_Base
{
private:

    local_procedure_body Print_Spaces (
	    alters Character_OStream& out,
            preserves Integer number_spaces
        )
    /*!
	requires
	    number_spaces >= 0 and
	    out.is_open = true
	ensures
	    out.is_open = true and
	    out.ext_name = #out.ext_name and
	    out.content = #out.content * MAKE_A_STRING (number_spaces, ' ')
    !*/
    {
        // Students to fill this in
    }

public:

    procedure_body Pretty_Print (
	    alters Character_OStream& out,
            preserves Integer indentation_factor
	)
    {
        // Students to fill this in
    }

};

#endif // CT_PROGRAM_PRETTY_PRINT_1

Program_Kernel_1

//  /*-------------------------------------------------------------------*\
//  |   Concrete Template : Program_Kernel_1
//  \*-------------------------------------------------------------------*/

#ifndef CT_PROGRAM_KERNEL_1
#define CT_PROGRAM_KERNEL_1 1

///------------------------------------------------------------------------
/// Global Context --------------------------------------------------------
///------------------------------------------------------------------------

#include "AT/Program/Kernel.h"
#include "CI/Statement/Kernel_1a.h"
#include "CT/Partial_Map/Kernel_1.h"

///------------------------------------------------------------------------
/// Interface -------------------------------------------------------------
///------------------------------------------------------------------------

concrete_template <
        concrete_instance class Statement =
            Statement_Kernel_1a,
        concrete_instance class Context =
            Partial_Map_Kernel_1 <
                    Text,
                    Statement
                >,
        concrete_instance class Rep =
            Representation <
                    Text,
                    Context,
                    Statement
                >
    >
class Program_Kernel_1 :
    implements
        abstract_instance Program_Kernel <Statement>,
    encapsulates
        concrete_instance Rep
{
private:

    rep_field_name (Rep, 0, Text, name_rep);
    rep_field_name (Rep, 1, Context, context_rep);
    rep_field_name (Rep, 2, Statement, body_rep);

    /*!
	convention
            IS_IDENTIFIER (self.name_rep) and
	    root (self.body_rep).kind = BLOCK and
	    for all name: IDENTIFIER, body: STATEMENT
	    where ((name, body) is in self.context_rep)
		(IS_LEGAL_USER_DEFINED_IDENTIFIER (name) and
		 root (body).kind = BLOCK)

	correspondence
	    self = (self.name_rep, self.context_rep, self.body_rep)
    !*/

public:

    standard_concrete_operations (Program_Kernel_1);

    procedure Swap_Name (
            alters Text& n
        )
    {
        // Students to fill this in
    }

    procedure Swap_Body (
            alters Statement& statement
        )
    {
        // Students to fill this in
    }

    procedure Add_To_Context (
            consumes Text& n,
            consumes Statement& statement
        )
    {
        // Students to fill this in
    }

    procedure Remove_From_Context (
            preserves Text n,
            produces Text& n_copy,
            produces Statement& statement
        )
    {   
        // Students to fill this in
    }           

    procedure Remove_Any_From_Context (
            produces Text& n,
            produces Statement& statement
        )
    {
        // Students to fill this in
    }

    function Boolean Is_In_Context (
            preserves Text n
        )
    {       
        // Students to fill this in
    }

    function Integer Size_Of_Context ()
    {
        // Students to fill this in
    }

};

#endif // CT_PROGRAM_KERNEL_1