Example of cparse Output
Let's assume you want to inspect this program:
/* main.c */
typedef struct coord_t {
int x, y;
} Coord;
int add(Coord a, Coord b, Coord *c) {
c->x = a.x + b.x;
c->y = a.y + b.y;
}
int main() {
Coord a, b, c;
a.x = a.y = 10;
b.x = b.y = 12;
add(a,b, &c);
printf("c = %d,%d\n", c.x, c.y);
}
If you run the command rigiparse main.c, you will get
the following output (we have reordered the tuples, eliminated duplicates,
and added some comments):
# Declaration of the Coord Data type ...
# Note that two types are defined: 'struct coord_t' and 'Coord'.
type coord_t(struct)^main.c^1 Datatype
type Coord^main.c^3 Datatype
isTheSameAs Coord^main.c^3 coord_t(struct)^main.c^1
# Declaration of the add Function ...
type add^main.c^5 Function
returns add^main.c^5 int
# Declaration of the parameters of the add Function ...
# Three tuples are emitted for every variable:
# - a type tuple to define a node for the variable
# - a hasType tuple to connect the variable node to the datatype node
# - an isDefinedIn tuple to connect the variable to the function
# it is defined in
type a^add^main.c^5^0 Variable
type b^add^main.c^5^0 Variable
type c^add^main.c^5^0 Variable
hasType a^add^main.c^5^0 Coord^main.c^3
hasType b^add^main.c^5^0 Coord^main.c^3
hasType c^add^main.c^5^0 Coord^main.c^3
isDefinedIn a^add^main.c^5^0 add^main.c^5
isDefinedIn b^add^main.c^5^0 add^main.c^5
isDefinedIn c^add^main.c^5^0 add^main.c^5
# Declaration of the main Function ...
type main^main.c^10 Function
returns main^main.c^10 int
# Declaration of the local variables of the add Function ...
type a^main^main.c^10^1 Variable
type b^main^main.c^10^1 Variable
type c^main^main.c^10^1 Variable
hasType a^main^main.c^10^1 Coord^main.c^3
hasType b^main^main.c^10^1 Coord^main.c^3
hasType c^main^main.c^10^1 Coord^main.c^3
isDefinedIn a^main^main.c^10^1 main^main.c^10
isDefinedIn b^main^main.c^10^1 main^main.c^10
isDefinedIn c^main^main.c^10^1 main^main.c^10
# Call of the add Function from the main Function ...
calls main^main.c^10 add^main.c^5
# The call by the main Function to the undefined printf Function
# follows. The printf function is not defined in main.c, so there
# is no type tuple for it. The relationship is still represented.
# The printf entity will be coerced to be the node type as specified
# by the Rigiarc domain file, or, if no type is specified with the
# arc, it will be assigned the first node type (node type 0) listed
# in the Riginode domain file.
calls main^main.c^10 printf
# Data references between the add Function and the Coord Data
# type follow. There is one each for the c->x and c->y
# references, one each for the a.x and a.y references, and one
# each for the b.x and b.y references (we elimited the duplicates).
accesses add^main.c^5 Coord^main.c^3
# Data references between the main Function and the Coord Data
# type follow. Again, there is one each for each reference.
accesses main^main.c^10 Coord^main.c^3
# Variable references between the main and add functions
# and their local variables resp. parameters. As before,
# there will be one for each reference, but we eliminated duplicates.
references add^main.c^5 a^add^main.c^5^0
references add^main.c^5 b^add^main.c^5^0
references add^main.c^5 c^add^main.c^5^0
references main^main.c^10 a^main^main.c^10^1
references main^main.c^10 add^main.c^5
references main^main.c^10 b^main^main.c^10^1
references main^main.c^10 c^main^main.c^10^1
references main^main.c^10 printf
# The tagged attributes don't a meaning in Rigi views. They are used
# by htmlrsf to html'ize source code.
tagged Coord^main.c^3 Coord^main.c^3
tagged coord_t(struct)^main.c^1 coord_t(struct)^main.c^1
tagged int int