( ESNUG 341 Item 15 ) -------------------------------------------- [1/26/00]

From: Janick Bergeron <janick@qualis.com>
Subject: Three Solutions To Fix The Vera "Missing Classes" Header Problem

Hi, John,

If you wanted user letters about VERA, all you had to do was ask.  You did
not need to place an ad in the EE Times.  :-)

When you implement a class to be used by some other source file, VERA can
automatically generate the header file that will contain all necessary
external declarations to satisfy the VERA compiler.  Think of the *.vr file
as the package body or the *.c file, and the *.vrh (automatically generated)
as the package or the *.h file.

There is one problem though: if your implementation uses other externally
declared classes (through #include directives), the necessary #include
directives are *NOT* included in the generated header file.  This requires
every user of your class to know what other file must be included
beforehand.  If you change something and require an additional file to be
included, everyone must change their code to include that file as well.
To put it politely: it violates the most basic data encapsulation principle.

For example, here's my class "myC" which uses classes "herC" and "hisC":

    #include "herC.vrh"
    #include "hisC.vrh"

    class myC extends herC {
       hisC   hisC_obj;
    }

The generated header file will be:

    /////////////////////////////////////////////////////////////////
    // Vera Header file created from myC.vr 
    /////////////////////////////////////////////////////////////////
    #ifndef INC__TMP_MYC_VRH
    #define INC__TMP_MYC_VRH

    extern class myC extends herC { 
      hisC hisC_obj;
    }

    #endif

Notice how the files "herC.vrh" and "hisC.vrh" are not included, even
though the declaration in the header file makes use of the classes defined
in them.  If I include the generated "myC.vrh" in another VERA source file
without manually including these header files:

    #include "myC.vrh"

I'll get a compilation error:

    Version: 4.1.3
    "myC.vrh", line 7 near <name> "herC" : parse error
    extern class myC extends herC { 
                             ^
    Compilation errors: 1

Because the VERA compiler does not know about "hisC" and "herC".


SOLUTION #1: Manually include are pre-requisite header file:

    #include "herC.vrh"
    #include "hisC.vrh"
    #include "myC.vrh"

As pointed out earlier, its a high-maintenance proposition and a violation
of the data encapsulation and hiding principle.


SOLUTION #2: Manually write the *.vrh file.

This is what C/C++ programmers do.  However, unlike C/C++, VERA does NOT
like a class to be declared both extern and local in the same file so you
cannot directly include the header file in the implementation file.  You
have to play preprocessor games with the "extern" keyword.  Also, the syntax
for declaring classes in header files is not as flexible: you cannot use
attribute blocks.  For example, this is illegal syntax in a header file
but perfectly legal in a source file:

    [extern] class myC {
       packed {
          integer count;
          string  name;
       }
    }

You'll have to explicitely put the attribute on each line:

    extern class myC {
       packed integer count;
       packed string  name;
    }


SOLUTION #3: Fix the stupid header files!

A PERL script can peruse the source file & add back any #include directives
to the generated header file.  John, please put my "vrhfix" script on your
website at http://www.DeepChip.com for downloading, OK?  Using "vrhfix",
the generated header file above now becomes:

    /////////////////////////////////////////////////////////////////
    // Vera Header file created from myC.vr 
    /////////////////////////////////////////////////////////////////
    #ifndef INC__TMP_MYC_VRH
    #define INC__TMP_MYC_VRH

    // Added by vrhfix, $Revision: 1.2$:
    #include "herC.vrh"
    #include "hisC.vrh"

    extern class myC extends herC { 
      hisC hisC_obj;
    }

    #endif

My Makefile target for compiling VERA now looks like this:

    %.vrh %.vro: %.vr
             vera -cmp -h $*.vr && vrhfix $*.vrh

I've already reported this enhancement request to the VERA group.  It should
be very easy to implement as the *_VRH symbols properly handle multiple 
inclusion of the same header file.  Any VERA code already written will
remain compatible with this solution.

    - Janick Bergeron
      Qualis Design Corporation                   Somewhere, Oregon



 Sign up for the DeepChip newsletter.
Email
 Read what EDA tool users really think.


Feedback About Wiretaps ESNUGs SIGN UP! Downloads Trip Reports Advertise

"Relax. This is a discussion. Anything said here is just one engineer's opinion. Email in your dissenting letter and it'll be published, too."
This Web Site Is Modified Every 2-3 Days
Copyright 1991-2024 John Cooley.  All Rights Reserved.
| Contact John Cooley | Webmaster | Legal | Feedback Form |

   !!!     "It's not a BUG,
  /o o\  /  it's a FEATURE!"
 (  >  )
  \ - / 
  _] [_     (jcooley 1991)