SemmleCode Database Contents

SemmleCode stores a representation of the program in the relational database. This page gives details of exactly what facts about the program are stored, and how they are represented as relations that can be accessed via .QL.

You will only rarely need to find out this information, as most queries are conveniently expressed via the pre-defined classes and predicates in default.ql. Directly writing queries in terms of the primitive relations is like programming in Java without using the standard libraries, or even worse, without proper objects at all!

Nevertheless, a quick browse of this page should give you a feel for what information is in the database. Certain facts, like information about control flow, are currently not present in the database. If you have a need for them in writing your queries, let us know by posting on the Semmle forums.

There is no technical reason why SemmleCode is not storing the complete program - it's just a matter of supply (or our time) and demand (queries that you want to write). It's your decision of what goes in next.

Types: traditional databases versus .QL

Because .QL is an object-oriented language, it uses its own type system for defining relations, not the very rudimentary form of types found in traditional database systems. Every field in the database schema therefore has two types: one for the use of the underlying database, and one for .QL.

For example, here is the schema for the table that represents method declarations.

methods(
        unique int id: @method, 
	varchar(100) nodeName: string ref, 
	varchar(900) signature: string ref, 
	int typeid: @type ref, 
	int parentid: @reftype ref, 
	int cuid: @cu ref, 
	int location: @location ref);

This introduces a new primitive relation named methods. The next line declares a field named id (short for 'identifier'). Its type in the underlying database is just int, and it is a key for the methods table, indicated by the modifier unique. By contrast, in .QL, the field methods.id is given type @method; you cannot write queries in .QL that exploit the fact that the underlying type is int.

Column types

The declaration of the methods.id field doubles as the declaration of the type @method: we define that type to be any value occurring in this column of the methods table. Such a type defined simultaneously with a field is called a column type. All the other fields have types that are references to types that already exist elsewhere. For instance, the cuid field (short for Compilation Unit IDentifier) is a reference to the @cu type; and that type is defined in the table that represents compilation units.

Names of column types start, by convention, with the character '@'. Not all column types are introduced via a field declaration, however. Some of these are defined as the union of other types. For example:

@reftype = @interface | @class | @array | @typevariable;

This defines the notion of a reference type: it is an interface, or a class, or an array, or a type variable. Below we first summarize these derived column types, and then we present the schema itself.

Type definitions

This section presents all the column types that are defined as unions of other column types. Experts in type systems may note that the type definitions below are overlapping. SemmleCode has a highly sophisticated type inference algorithm for handling such overlapping types and the corresponding notion of type inclusion. When using it, you can just enjoy the flexibility it brings!

To find the definition of a type, just click on the reference.

Elements: any element of the program
@element = @cu | @package | @primitive | @class | @interface | 
           @method | @constructor | @modifier | @param | @field |
           @annotationelement | @annotation | @enumconstant |
           @typevariable | @array;
Java types, and members of reference types
@type = @primitive | @reftype;

@reftype = @interface | @class | @array | @typevariable;

@member = @method | @constructor | @field | @reftype | 
          @annotationelement | @enumconstant
Callables: methods and constructors
@typeormethod = @type | @method;

@callable = @method | @constructor;
Expressions: calls and field accesses
@expression = @fieldAccessExpr | @callExpr;

@fieldAccessExpr = @readsFieldExpr | @writesFieldExpr;

@callExpr = @makesMethodCallExpr | @makesConstructorCallExpr;
Locatables: elements that have a location
@locatable = @class | @interface | @method | @constructor | 
             @exception | @field | @readsFieldExpr | @writesFieldExpr |
             @makesMethodCallExpr | @makesConstructorCallExpr | 
             @annotationelement | @enumconstant | @typevariable | 
             @typebound | @array;
Named: elements that have a name
@named = @param | @member | @package | @typeormethod | @cu;
XML artefacts that accept children and that may be prefixed with a namespace
@xmlparent  = @xmlfile | @xmlelement;

@xmlnamespaceable = @xmlelement | @xmlattribute;
Files: compilation units and XML files
@file = @cu | @xmlfile;

Schema

The links in each of the relation schema below take you to the corresponding type definition.
Locations
locations(
        unique int id: @location, 
	int locatableid: @locatable ref, 
	int fileid: @file ref, 
	int startpos: int ref, 
	int length: int ref, 
	int startline: int ref, 
	int totallines: int ref,
	int totalcodelines: int ref,
	int totalcommentlines: int ref);
Packages
packages(
        unique int id: @package, 
	varchar(900) nodeName: string ref);
Compilation units
cus(
        unique int id: @cu, 
	varchar(900) nodeName: string ref, 
	varchar(900) cupath: string ref, 
	int parentid: @package ref, 
	varchar(16) extension: string ref, 
	int location: @location ref);
Imports
imports(
        unique int id: @import, 
	int holder: @typeorpackage ref, 
	varchar(900) name: string ref, 
	int kind: int ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Primitive types
primitives(
        unique int id: @primitive, 
	varchar(20) nodeName: string ref);
Modifiers
modifiers(
        unique int id: @modifier, 
	varchar(20) nodeName: string ref);

hasModifier(
        int id1: @element ref, 
	int id2: @modifier ref, 
	int cuid: @cu ref);
Classes
classes(
        unique int id: @class, 
	varchar(900) nodeName: string ref, 
	int parentid: @package ref, 
	int cuid: @cu ref, 
	int location: @location ref);

isAnonymClass /* is anonymous class */ (
        int classid: @class ref);

isLocalClass(
        int classid: @class ref);
Interfaces
interfaces(
        unique int id: @interface, 
	varchar(900) nodeName: string ref, 
	int parentid: @package ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Nested types
enclInReftype /* enclosed in reftype */ (
        int child: @reftype ref, 
	int parent: @reftype ref, 
	int cuid: @cu ref);
Inheritance
extendsReftype(
        int id1: @reftype ref, 
	int id2: @reftype ref, 
	int cuid: @cu ref);

implInterface /* implements interface */ (
        int id1: @class ref, 
	int id2: @interface ref, 
	int cuid: @cu ref);
Arrays
arrays(
        unique int id: @array, 
	varchar(900) nodeName: string ref,
	int elementtypeid: @type ref,
	int dimension: int ref
	int cuid: @cu ref, 
	int location: @location ref);
Fields
fields(
        unique int id: @field, 
	varchar(900) nodeName: string ref, 
	int typeid: @type ref, 
	int parentid: @reftype ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Constructors
constrs /* constructors */ (
        unique int id: @constructor, 
	varchar(900) nodeName: string ref, 
	varchar(900) signature: string ref, 
	int typeid: @type ref, 
	int parentid: @reftype ref,
	int cuid: @cu ref, 
	int location: @location ref);

isDefConstr /* is default constructor */ (
        int constructorid: @constructor ref);
Methods
methods(
        unique int id: @method, 
	varchar(900) nodeName: string ref, 
	varchar(900) signature: string ref, 
	int typeid: @type ref, 
	int parentid: @reftype ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Parameters of methods and constructors
params(
        unique int id: @param, 
	varchar(100) nodeName: string ref, 
	int typeid: @type ref, 
	int pos: int ref, 
	int parentid: @callable ref, 
	int cuid: @cu ref)
	int location: @location ref);
Exceptions in throws-clauses of methods and constructors
exceptions(
        unique int id: @exception, 
	int typeid: @type ref, 
	int parentid: @callable ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Field accesses by methods and constructors
readsField(
        unique int id: @readsFieldExpr, 
	int id1: @callable ref, 
	int id2: @field ref, 
	int cuid: @cu ref, 
	int location: @location ref);

writesField(
        unique int id: @writesFieldExpr, 
	int id1: @callable ref, 
	int id2: @field ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Method and constructor calls
callsMethod /* makes a method call */ (
        unique int id: @makesMethodCallExpr, 
	int id1: @callable ref, 
	int id2: @method ref, 
	int kind:  int ref, 
	int cuid: @cu ref, 
	int location: @location ref);

callsConstr /* makes a constructor call */ (
        unique int id: @makesConstructorCallExpr, 
	int id1: @callable ref, 
	int id2: @constructor ref, 
	int kind:  int ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Java 5 annotations
isAnnotType /* is annotation type */ (
        int interfaceid: @interface ref);

annotElems /* annotation elements */ (
        unique int id: @annotationelement, 
	varchar(900) nodeName: string ref, 
	int typeid: @type ref, 
	int parentid: @interface ref, 
	int cuid: @cu ref, 
	int location: @location ref);

annots /* annotations */ (
        unique int id: @annotation, 
	int parentid: @element ref, 
	int id2: @interface ref, 
	int cuid: @cu ref);

annotValue /* annotation value */ (
        int parentid: @annotation ref, 
	int id2: @annotationelement ref, 
	varchar(900) value: string ref, 
	int cuid: @cu ref);
Java 5 enumeration types
isEnumType(
        int classid: @class ref);

enumConsts /* enum constants */ (
        unique int id: @enumconstant, 
	varchar(100) nodeName: string ref, 
	int typeid: @type ref, 
	int parentid: @class ref, 
	int cuid: @cu ref, 
	int location: @location ref);
Java 5 generics
typeVars /* type variables */ (
        unique int id: @typevariable, 
	varchar(900) nodeName: string ref, 
	int pos: int ref, 
	int parentid: @typeormethod ref, 
	int cuid: @cu ref, 
	int location: @location ref);

typeBounds(
        unique int id: @typebound, 
	int typeid: @type ref, 
	int pos: int ref, 
	int parentid: @typevariable ref, 
	int cuid: @cu ref, 
	int location: @location ref);

typeArgs /* type arguments */ (
         int argumentid: @reftype ref, 
	int pos: int ref, 
	int parentid: @reftype ref, 
	int cuid: @cu ref;

isParameterized(
        int memberid: @member ref);

isRaw(
        int memberid: @member ref);

erasure(
        int memberid: @member ref, 
	int erasureid: @member ref);
XML
xmlFiles(
        unique int id: @xmlfile, 
	varchar(900) name: string ref, 
	varchar(900) path: string ref, 
	varchar(900) encoding: string ref);
	
xmlDTDs(
        unique int id: @xmldtd, 
	varchar(900) root: string ref, 
	varchar(900) publicId: string ref, 
	varchar(900) systemId: string ref,
	int fileid: @xmlfile ref);

xmlElements(
        unique int id: @xmlelement, 
	varchar(900) name: string ref, 
	int parentid: @xmlparent ref,
	int idx: int ref,
	int fileid: @xmlfile ref);

xmlAttrs /* XML attributes */ (
        unique int id: @xmlattribute, 
	int elementid: @xmlelement ref,
	varchar(900) name: string ref, 
	varchar(900) value: string ref, 
	int idx: int ref,
	int fileid: @xmlfile ref);

xmlNs /* XML namespaces */ (
        unique int id: @xmlnamespace, 
	varchar(900) prefixName: string ref, 
	varchar(900) URI: string ref, 
	int fileid: @xmlfile ref);

xmlHasNs /* is prefixed by namespace */ (
        int elementid: @xmlnamespaceable ref,
	int nsId: @xmlnamespace ref, 
	int fileid: @xmlfile ref);
	
xmlComments(
        unique int id: @xmlcomment, 
	varchar(900) text: string ref, 
	int parentid: @xmlparent ref,
	int fileid: @xmlfile ref);
  
xmlChars(
        unique int id: @xmlcharacters, 
	varchar(900) text: string ref, 
	int parentid: @xmlparent ref,
	int idx: int ref,
	boolean isCDATA: boolean ref,
	int fileid: @xmlfile ref);