The SoftBench static analysis database

Hewlett-Packard Journal, Feb, 1997 by Robert C. Bethke

The SoftBench static analysis database, Static.sadb, is a repository for generic program semantic information. Within SoftBench the database supports the static analyzer along with graphical editing and rule-based program checking. The data model is relatively general and currently supports C , C, FORTRAN, Pascal, and Ada.

The database also serves as a product and can be customized by the user. Its compiler interface and tool interface are documented and allow the integration of other languages and compilers and the use of custom analysis tools.

The Data Model

The underlying data is a set of persistent C objects. These objects serve to model the semantics of the program. The underlying persistent objects are isolated by the compiler interface and the tool interface. The isolation has important implications for allowing a variety of compiler integrations and provides flexibility in changing the underlying data management without affecting either the compilers or the tools.

Many of the persistent objects are language-generic (language-insensitive) and are intended to model all similar constructs. For example, a Struct object is used to model C structures and Pascal records. A Function object is used to model functions and procedures in all languages. In some cases, it is necessary to have language-specific objects because the semantics are too specific to apply to other languages. Examples of language-specific objects are C Class objects and Ada Module objects.

Each persistent object is assigned a unique object identifier known as a handle. Given an object's handle, it is possible to query the object by means of methods for relevant information such as its name, list of references, and so on. All associations among the persistent objects are maintained by these handles. For example, the association from a Variable object to its typedef object is maintained by the Variable's having the handle of its typedef as an attribute. One-to-many associations are maintained as a set of handles. For example, a File object will have a set of handles to associate all other source files included by it.

To illustrate associations, consider the following C code:

typedef struct S lint x; int y;} SType;

Stype var;

The associations among the semantic objects in this code fragment are shown in Fig. 1.

[Figure 1 ILLUSTRATION OMITTED]

Container objects are used to model scoping and binding and to organize the semantic objects for efficient updating and navigation. Each container has a set of handles for all objects contained in it and each object contained has the handle of its container. Examples of container objects are Files, Functions, and Classes. A File contains the program constructs defined in that source file, a Function contains its parameters and blocks, and a Class contains its members. For example, Fig. 2 shows the object containment for the following C class definition:

   Class cls {
      public:
        cls (int x) {mem=x;}
      private:
        int mem;
   };

The compiler interface is procedural in style and is intended to be easily added to most compilers. The interface is structured around the creation of objects and the establishment of associations and containment relationships among the objects.

The Tool Interface

From the tool perspective the database supports concurrency control to the extent of allowing multiple readers and one writer. A reader can have up to 256 databases open for reading. The reader must structure queries within a transaction and is allowed to leave the database open while it is being modified by a writer. The reader is notified of a change to the database via a callback when starting a transaction. Nested transactions are not supported.

The tool interface is a class library that reflects the underlying object model. Each persistent object is presented as a handle. Internally, each handle is mapped into a pointer to the real persistent object. All information pertaining to the object is made available via methods. Navigation among objects is supported by methods that return a handle or an iterator over a set of handles. For example, the following is a partial definition of the Symbol class.

   class Symbol {
      public:
        Symbol(PerHandle symbolhandle);
        Symbol();
        ~Symbol();

        // Name, kind and attributes of the symbol.
        char *Name() const;
        PerKind Rind() const;
        Attributes Attrib() const;

        // Enclosing scopes of the symbol.
        DBboolean EnclosingFile(File &file) const;
        DBboolean EnclosingBlock(Block &block)
          const;

        // Iterator to all reference lists for this
        // Symbol.
        ITERATOR(RefList) RefLists() const;

        protected:
          PerHandle SymbolHandle;
   };

The global SymbolTable is the root for all navigation. This object provides navigation and hashed searching to all globally scoped symbols. The following code segment illustrates how to access all globally scoped functions from the global SymbolTable.

 

BNET TalkbackShare your ideas and expertise on this topic

Please add your comment:

  1. You are currently: a Guest |
  2.  

Basic HTML tags that work in comments are: bold (<b></b>), italic (<i></i>), underline (<u></u>), and hyperlink (<a href></a)

advertisement
CXO UnpluggedSmart Business interviews on BNET

See and hear how senior level executives across the Asia Pacific are developing smart business ideas across a variety of sectors. The focus is on the future, and on how businesses need to evolve.

advertisement
  • Click Here
  • Click Here
  • Click Here
advertisement

Content provided in partnership with Thompson Gale