Link imported objects to objects from other analyzers

Create links between objects imported with the Universal Importer and objects that other analyzers have already saved in the analysis schema
Updated

Overview

Imported objects often call, or are called by, objects that another analyzer has created, for example database tables or Java methods. A .uax file can link to such objects in three ways:

  • by their numeric ID in the analysis schema, with the externalCaller and externalCallee attributes of link
  • by a reference that describes the object, with the uaxDBRef type
  • by calling a database function that returns the ID of the object

This page also explains how to attach top-level objects to the project without naming it.

Do not combine external links with parentLink: it gives inconsistent results. Foreign keys, constraints and common keys cannot be created this way.

Use externalCaller or externalCallee instead of caller or callee, with the ID of the object in the analysis schema, as found in the Keys.IdKey column:

<instance id="" instanceOf="callLink">
    <link caller="object1" externalCallee="1247" />
</instance>

Declare an instance of type uaxDBRef that describes the target object, then use it as caller or callee as if it were an imported object. The Universal Importer converts the reference to the ID of the matching object.

Describe the object with any of the following. Each is optional, but the more you give, the lower the risk of matching the wrong object:

  • identification/@name: the name of the object
  • identification/@fullName: the full name of the object
  • @objectType: the type of the object

For example, to create a call link from the imported object object1 to the PHP function f, already in the analysis schema:

<instance id="" instanceOf="callLink">
    <link caller="object1" callee="dbref-f" />
</instance>
<instance id="dbref-f" instanceOf="uaxDBRef" objectType="phpFunction">
    <identification name="f" fullName="C:\eiffel\test\file.php.phpFunction.f" />
</instance>

Objects with the same name

If several objects match the reference, no link is created and a warning is logged.

To link to all the objects that match, end the name with *. The * is not a wildcard: with the name f*, links are created to all objects named f, but not to objects named f2 or f33.

Write a PostgreSQL function that returns the ID of the target object, then reference it with the externalCallerSP or externalCalleeSP attribute of link:

function_name(argument_1, argument_2, ..., argument_n)

For example, to create links to and from the imported object f:

<instance id="" instanceOf="callLink">
    <link caller="f" externalCalleeSP="my_proc(test,2,function)" />
</instance>
<instance id="" instanceOf="callLink">
    <link externalCallerSP="my_proc(hello,11,member)" callee="f" />
</instance>
<instance id="" instanceOf="callLink">
    <link caller="f" externalCalleeSP="my_proc2(10,53)" />
</instance>

The Universal Importer gives each call a CALL_ID and writes its arguments to the UAX_SP_IN table of the analysis schema:

Column Type Description
CALL_ID Integer The ID of the call
PARAM_ORDER Integer The position of the argument
VALUE Varchar(100) The value of the argument
PROCEDURE_NAME Varchar(100) The name of the function

For the example above, the table contains:

CALL_ID PARAM_ORDER VALUE PROCEDURE_NAME
0 1 hello my_proc
0 2 11 my_proc
0 3 member my_proc
1 1 test my_proc
1 2 2 my_proc
1 3 function my_proc
2 1 10 my_proc2
2 2 53 my_proc2

Each function is called once. It must:

  1. Read all the rows of UAX_SP_IN whose PROCEDURE_NAME is its own name.
  2. For each CALL_ID, read the arguments in order and find the ID of the matching object.
  3. Write one row per call to the UAX_SP_OUT table:
Column Type Description
CALL_ID Integer The ID of the call
RESULT Integer The ID of the external caller or callee

For example, if UAX_SP_OUT contains (0, 1247), (1, 6214) and (2, 1748), object f gets a link from the object 1247, a link to the object 6214 and a link to the object 1748.

  • The function must compile and run without error.
  • The function must contain return 0.
  • If a call fails or finds no object, a warning is logged.

Attach top-level objects to the project

Top-level objects, which are directly under the project, can use the virtual reference %ProjectRoot% as the callee of their parentLink. It is replaced by the project, so you do not need to name the project in the .uax file:

<instance id="fileA" instanceOf="sourceFile">
    <identification name="fileA" fullName="C:\a.php" />
</instance>
<instance id="" instanceOf="parentLink">
    <link caller="fileA" callee="%ProjectRoot%" />
</instance>