Browse Prior Art Database

Conditional Report Loops in Code Generation

IP.com Disclosure Number: IPCOM000123049D
Original Publication Date: 1998-Apr-01
Included in the Prior Art Database: 2005-Apr-04
Document File: 4 page(s) / 119K

Publishing Venue

IBM

Related People

Lindsay, TD: AUTHOR

Abstract

The purpose of this document is to describe a looping structure that is useful in the generation of code.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 42% of the total text.

Conditional Report Loops in Code Generation

      The purpose of this document is to describe a looping structure
that is useful in the generation of code.

      Conditional Repeat Loops In Code Generation

      PROBLEM:

      Situations arise in code generation when certain elements from
a list or lists are required to generate a snippet of code.  It may
be necessary to separate the code fragments with other snippets of
code and/or generate code before and after the snippet.  Often it is
not known if the list(s) contain any elements that meet the
condition. In  these situations, the user may not want to generate
any code at all. An  elegant and efficient method is required to
solve this problem.  The user  does not want to pre-process the
list(s) to see if it is necessary to emit the before and after code.
The code emitted in between each iteration of the loop should only
occur between each combination that meets the loops condition.

      For example, consider generating a class that represents a
table in a relational database.  Each column in the table would map
to an attribute of the class.  If the table has a key, which would
consist of one or more columns, then the user wants to create a
method that sets all of these attributes.

      Table Definition:
  Table 1. Employee Table
  Column Name      DataId           SQL Type         C++ Type
  firstname        true             CHAR(12)         char*
  job              false            CHAR(10)         char*
  lastname         true             CHAR(15)         char*
  salary           false            DECIMAL(9,2)     double

      Generated Code:
  class Employee
  {
  public:
    //
    // This method is used to set the key values of the
        Employee table
    //
    void setKeyAttributes(char* firstname, char* lastname);
    //
    // Key Attributes
    //
      // firstname
      void setFirstname(char* firstname);
      char* getFirstname();
      // lastname
      void setLastname(char* lastname);
      char* getLastname();
    //
    // Non-Key Attributes
    //
    .
    .
    .
  }

      IMPLEMENTATION

      Looping is achieved through the use of the repeat statement.
Options to the repeat statement consist of two parts.

      In the first part, known as the repeat list, the items to
iterate over are given.  The first time through the loop each member
in the repeat list is reset to the first element.  Through each
iteration of the loop, every item in the list is set to the next
element.  The loop ends when one of the members of the repeat list
reaches its last value or the stop condition (see below) is reached.

      The second part of the repeat statement consists of blocks of
code to execute bef...