Source (C++):

/*----d.h---*/

class D {

     private: int num;

     public:

     D(int x) { this->num=x; printf("Hello, this is %d\n", x); }

     work() { printf("This is %d working\n", this->num);

};

/*---a.cpp---*/

#include "d.h"

int g1=0;

D d1(1);

 

/*---b.cpp--*/

#include "d.h"

extern D d1;

D d2(2);

main() {

     int l2=0;

     D * d3=new D(3);

     d1.work();

     d2.work();

     d3->work();

     }

 

<?xml version="1.0" encoding="UTF-8"?>
<kdm:Segment xmi:version="2.1"

xmlns:xmi="http://www.omg.org/XMI"

xmlns:action="http://kdm.omg.org/action"

xmlns:code="http://kdm.omg.org/code"

xmlns:kdm="http://kdm.omg.org/kdm"

name="ClassD Example">
 
<model xmi:id="id.0" xmi:type="code:CodeModel">
    <codeElement xmi:id="id.1" xmi:type="code:CodeAssembly">
      <codeElement xmi:id="id.2" xmi:type="code:CompilationUnit" name="a.cpp">
       
<codeElement xmi:id="id.3" xmi:type="code:IncludeDirective" name="imp1">
          <codeRelation xmi:id="id.4" xmi:type="code:Includes" to="id.22" from="id.3"/>
        </codeElement>
        <codeElement xmi:id="id.5" xmi:type="code:StorableUnit" name="g1" type="id.105">
          <codeRelation xmi:id="id.6" xmi:type="code:HasValue" to="id.20" from="id.5"/>
        </codeElement>
        <codeElement xmi:id="id.7" xmi:type="code:StorableUnit" name="d1" type="id.23">
          <codeRelation xmi:id="id.8" xmi:type="code:HasType" to="id.23" from="id.7"/>
          <codeRelation xmi:id="id.9" xmi:type="code:ImplementationOf" to="id.47" from="id.7"/>
       
</codeElement>
        <codeElement xmi:id="id.10" xmi:type="code:CallableUnit" name="bi1">
         
<entryFlow xmi:id="id.11" to="id.12" from="id.10"/>
          <codeElement xmi:id="id.12" xmi:type="action:ActionElement" name="i1" kind="Assign">
            <actionRelation xmi:id="id.13" xmi:type="action:Reads" to="id.20" from="id.12"/>
            <actionRelation xmi:id="id.14" xmi:type="action:Writes" to="id.5" from="id.12"/>
            <actionRelation xmi:id="id.15" xmi:type="action:Flow" to="id.16" from="id.12"/>
          </codeElement>
          <codeElement xmi:id="id.16" xmi:type="action:ActionElement" name="i2" kind="Calls">
            <actionRelation xmi:id="id.17" xmi:type="action:Reads" to="id.21" from="id.16"/>
            <actionRelation xmi:id="id.18" xmi:type="action:Calls" to="id.25" from="id.16"/>
            <actionRelation xmi:id="id.19" xmi:type="action:Writes" to="id.7" from="id.16"/>
          </codeElement>
          <codeElement xmi:id="id.20" xmi:type="code:Value" name="0"/>
          <codeElement xmi:id="id.21" xmi:type="code:Value" name="1"/>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.22" xmi:type="code:SharedUnit" name="d.h">
        <codeElement xmi:id="id.23" xmi:type="code:ClassUnit" name="D">
          <codeElement xmi:id="id.24" xmi:type="code:MemberUnit" name="num" type="id.105" export="private"/>
          <codeElement xmi:id="id.25" xmi:type="code:MethodUnit" name="D">
            <entryFlow xmi:id="id.26" to="id.28" from="id.25"/>
            <codeElement xmi:id="id.27" xmi:type="code:Value" name="&quot;Hello, this is %d\n&quot;" type="id.111"/>
            <codeElement xmi:id="id.28" xmi:type="action:ActionElement" name="a4" kind="Assign">
              <actionRelation xmi:id="id.29" xmi:type="action:Reads" to="id.37" from="id.28"/>
              <actionRelation xmi:id="id.30" xmi:type="action:Writes" to="id.24" from="id.28"/>
              <actionRelation xmi:id="id.31" xmi:type="action:Flow" to="id.32" from="id.28"/>
            </codeElement>
            <codeElement xmi:id="id.32" xmi:type="action:ActionElement" name="a5" kind="Call">
              <actionRelation xmi:id="id.33" xmi:type="action:Reads" to="id.27" from="id.32"/>
              <actionRelation xmi:id="id.34" xmi:type="action:Reads" to="id.37" from="id.32"/>
              <actionRelation xmi:id="id.35" xmi:type="action:Calls" to="id.106" from="id.32"/>
           
</codeElement>
            <codeElement xmi:id="id.36" xmi:type="code:Signature" name="D">
             
<parameterUnit xmi:id="id.37" name="x" pos="1"/>
            </codeElement>
          </codeElement>
          <codeElement xmi:id="id.38" xmi:type="code:MethodUnit" name="work">
            <codeElement xmi:id="id.39" xmi:type="code:Value" name="&quot;This is %d working\n&quot;"/>
            <codeElement xmi:id="id.40" xmi:type="action:ActionElement" name="a6" kind="Call">
              <actionRelation xmi:id="id.41" xmi:type="action:Reads" to="id.39" from="id.40"/>
              <actionRelation xmi:id="id.42" xmi:type="action:Reads" to="id.24" from="id.40"/>
              <actionRelation xmi:id="id.43" xmi:type="action:Calls" to="id.106" from="id.40"/>
           
</codeElement>
          </codeElement>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.44" xmi:type="code:CompilationUnit" name="b.cpp">
       
<codeElement xmi:id="id.45" xmi:type="code:IncludeDirective" name="imp2">
          <codeRelation xmi:id="id.46" xmi:type="code:Includes" to="id.22" from="id.45"/>
        </codeElement>
        <codeElement xmi:id="id.47" xmi:type="code:StorableUnit" name="extern d1" kind="external"/>
        <codeElement xmi:id="id.48" xmi:type="code:CallableUnit" name="main">
          <entryFlow xmi:id="id.49" to="id.70" from="id.48"/>
          <codeElement xmi:id="id.50" xmi:type="code:StorableUnit" name="l2" type="id.105">
            <codeRelation xmi:id="id.51" xmi:type="code:HasValue" to="id.20" from="id.50"/>
          
</codeElement>
          <codeElement xmi:id="id.52" xmi:type="code:StorableUnit" name="d2">
           
<codeRelation xmi:id="id.53" xmi:type="code:HasType" to="id.23" from="id.52"/>
          </codeElement>
          <codeElement xmi:id="id.54" xmi:type="code:StorableUnit" name="d3" type="id.55">
            <codeElement xmi:id="id.55" xmi:type="code:PointerType">
              <itemUnit xmi:id="id.56" type="id.23">
                <codeRelation xmi:id="id.57" xmi:type="code:HasType" to="id.23" from="id.56"/>
              </itemUnit>
            </codeElement>
          </codeElement>
          <codeElement xmi:id="id.58" xmi:type="action:ActionElement" name="a1" kind="Call">
            <actionRelation xmi:id="id.59" xmi:type="action:Calls" to="id.38" from="id.58"/>
            <actionRelation xmi:id="id.60" xmi:type="action:Addresses" to="id.7" from="id.58"/>
            <actionRelation xmi:id="id.61" xmi:type="action:CompliesTo" to="id.47" from="id.58"/>
            <actionRelation xmi:id="id.62" xmi:type="action:Flow" to="id.63" from="id.58"/>
          </codeElement>
          <codeElement xmi:id="id.63" xmi:type="action:ActionElement" name="a2" kind="Call">
            <actionRelation xmi:id="id.64" xmi:type="action:Calls" to="id.38" from="id.63"/>
            <actionRelation xmi:id="id.65" xmi:type="action:Addresses" to="id.52" from="id.63"/>
            <actionRelation xmi:id="id.66" xmi:type="action:Flow" to="id.67" from="id.63"/>
          </codeElement>
          <codeElement xmi:id="id.67" xmi:type="action:ActionElement" name="a3" kind="Call">
            <actionRelation xmi:id="id.68" xmi:type="action:Calls" to="id.38" from="id.67"/>
            <actionRelation xmi:id="id.69" xmi:type="action:Addresses" to="id.56" from="id.67"/>
          </codeElement>
          <codeElement xmi:id="id.70" xmi:type="action:BlockUnit" name="bi2">
            <codeElement xmi:id="id.71" xmi:type="action:ActionElement" name="i3" kind="Assign">
              <actionRelation xmi:id="id.72" xmi:type="action:Reads" to="id.20" from="id.71"/>
              <actionRelation xmi:id="id.73" xmi:type="action:Writes" to="id.50" from="id.71"/>
              <actionRelation xmi:id="id.74" xmi:type="action:Flow" to="id.79" from="id.71"/>
            </codeElement>
            <codeElement xmi:id="id.75" xmi:type="action:ActionElement" name="i4" kind="New">
              <actionRelation xmi:id="id.76" xmi:type="action:Creates" to="id.23" from="id.75"/>
              <actionRelation xmi:id="id.77" xmi:type="action:Writes" to="id.54" from="id.75"/>
              <actionRelation xmi:id="id.78" xmi:type="action:Flow" to="id.79" from="id.75"/>
            </codeElement>
            <codeElement xmi:id="id.79" xmi:type="action:ActionElement" name="i5" kind="MethodCall">
              <actionRelation xmi:id="id.80" xmi:type="action:Reads" to="id.85" from="id.79"/>
              <actionRelation xmi:id="id.81" xmi:type="action:Addresses" to="id.54" from="id.79"/>
              <actionRelation xmi:id="id.82" xmi:type="action:Calls" to="id.25" from="id.79"/>
              <actionRelation xmi:id="id.83" xmi:type="action:Writes" to="id.56" from="id.79"/>
              <actionRelation xmi:id="id.84" xmi:type="action:Flow" to="id.58" from="id.79"/>
            </codeElement>
            <codeElement xmi:id="id.85" xmi:type="code:Value" name="3"/>
            <actionRelation xmi:id="id.86" xmi:type="action:Flow" to="id.71" from="id.70"/>
         
</codeElement>
        </codeElement>
        <codeElement xmi:id="id.87" xmi:type="code:CallableUnit" name="bi3">
         
<entryFlow xmi:id="id.88" to="id.89" from="id.87"/>
          <codeElement xmi:id="id.89" xmi:type="action:ActionElement" name="i6" kind="Call">
            <actionRelation xmi:id="id.90" xmi:type="action:Reads" to="id.93" from="id.89"/>
            <actionRelation xmi:id="id.91" xmi:type="action:Calls" to="id.25" from="id.89"/>
            <actionRelation xmi:id="id.92" xmi:type="action:Writes" to="id.52" from="id.89"/>
          </codeElement>
          <codeElement xmi:id="id.93" xmi:type="code:Value" name="2" type="id.105"/>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.94" xmi:type="code:CallableUnit" name="bi4" kind="unknown">
        <entryFlow xmi:id="id.95" to="id.96" from="id.94"/>
        <codeElement xmi:id="id.96" xmi:type="action:ActionElement" name="i7">
          <actionRelation xmi:id="id.97" xmi:type="action:Calls" to="id.10" from="id.96"/>
          <actionRelation xmi:id="id.98" xmi:type="action:Flow" to="id.99" from="id.96"/>
        </codeElement>
        <codeElement xmi:id="id.99" xmi:type="action:ActionElement" name="i8">
          <actionRelation xmi:id="id.100" xmi:type="action:Calls" to="id.87" from="id.99"/>
          <actionRelation xmi:id="id.101" xmi:type="action:Flow" to="id.102" from="id.96"/>
        </codeElement>
        <codeElement xmi:id="id.102" xmi:type="action:ActionElement" name="i9">
          <actionRelation xmi:id="id.103" xmi:type="action:Calls" to="id.48" from="id.102"/>
       
</codeElement>
      </codeElement>
    </codeElement>
    <codeElement xmi:id="id.104" xmi:type="code:LanguageUnit">
      <codeElement xmi:id="id.105" xmi:type="code:IntegerType" name="int"/>
      <codeElement xmi:id="id.106" xmi:type="code:CallableUnit" name="printf" type="id.107">
        <codeElement xmi:id="id.107" xmi:type="code:Signature" name="printf">
         
<parameterUnit xmi:id="id.108" type="id.105" kind="return" pos="0"/>
          <parameterUnit xmi:id="id.109" name="format" type="id.111" pos="1"/>
          <parameterUnit xmi:id="id.110" name="arguments" type="id.112" kind="variadic" pos="2"/>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.111" xmi:type="code:StringType" name="char *"/>
      <codeElement xmi:id="id.112" xmi:type="code:VoidType"/>
   
</codeElement>
  </model>
</kdm:Segment>