Source (C):

typedef enum {red, yellow,green} light;

int old_light;

void f() { old_light=(int) swap(green); }

light swap(light new_light){

     static light l=red;

     light tmp;

     tmp=l;

     l=new_light;

     return tmp;

}

 

<?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"

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

name="Enumerations Example">
  <model xmi:id="id.0" xmi:type="code:CodeModel" name="Variables">
    <codeElement xmi:id="id.1" xmi:type="code:CompilationUnit">
      <codeElement xmi:id="id.2" xmi:type="code:TypeUnit" name="light" type="id.6">
        <source xmi:id="id.3" language="C" snippet="typedef enum {red, yellow, green} light;">
          <region xmi:id="id.4" startLine="1" startPosition="1" endLine="40" endPosition="1" language="C" path="Examples/Light.c">
            <annotation xmi:id="id.5" text="This element illustrates SourceRegion that does not reference the InventoryModel"/>
          </region>
        </source>
        <codeElement xmi:id="id.6" xmi:type="code:EnumeratedType" name="light">
          <value xmi:id="id.7" name="red" type="id.6"/>
          <value xmi:id="id.8" name="yellow" type="id.6"/>
          <value xmi:id="id.9" name="green" type="id.6"/>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.10" xmi:type="code:CallableUnit" name="f" type="id.14" kind="regular">
        <source xmi:id="id.11" language="C" snippet="void f()">
          <annotation xmi:id="id.12" text="This element illustrates a SourceRef without a SourceRegion"/>
        </source>
        <entryFlow xmi:id="id.13" to="id.15"/>
        <codeElement xmi:id="id.14" xmi:type="code:Signature" name="f"/>
        <codeElement xmi:id="id.15" xmi:type="action:ActionElement" name="a0" kind="Compound">
          <source xmi:id="id.16" language="" snippet="">
            <annotation xmi:id="id.17" text="This element illustrates an empty SourceRef with a SourceRegion that references InventoryModel"/>
            <region xmi:id="id.18" file="id.69" startLine="3" startPosition="10" endLine="3" endPosition="42" language="C" path=""/>
          </source>
          <codeElement xmi:id="id.19" xmi:type="action:ActionElement" name="a1" kind="Call">
            <actionRelation xmi:id="id.20" xmi:type="action:Reads" to="id.9" from="id.19"/>
            <actionRelation xmi:id="id.21" xmi:type="action:Calls" to="id.30" from="id.19"/>
            <actionRelation xmi:id="id.22" xmi:type="action:Writes" to="id.28" from="id.19"/>
            <actionRelation xmi:id="id.23" xmi:type="action:Flow" to="id.24" from="id.19"/>
          </codeElement>
          <codeElement xmi:id="id.24" xmi:type="action:ActionElement" name="a2" kind="TypeCast">
            <actionRelation xmi:id="id.25" xmi:type="action:Reads" to="id.28" from="id.24"/>
            <actionRelation xmi:id="id.26" xmi:type="action:UsesType" to="id.67" from="id.19"/>
            <actionRelation xmi:id="id.27" xmi:type="action:Writes" to="id.63" from="id.24"/>
          </codeElement>
          <codeElement xmi:id="id.28" xmi:type="code:StorableUnit" name="r1" type="id.2" kind="register"/>
          <actionRelation xmi:id="id.29" xmi:type="action:Flow" to="id.19" from="id.15"/>
       
</codeElement>
      </codeElement>
      <codeElement xmi:id="id.30" xmi:type="code:CallableUnit" name="swap">
       
<source xmi:id="id.31" >
          <annotation xmi:id="id.32" text="This element illustrates a SourceRegion for the complete procedure"/>
          <region xmi:id="id.33" file="id.69" startLine="1" startPosition="1" endLine="1" endPosition="1" language="C" path=""/>
        </source>
        <entryFlow xmi:id="id.34" to="id.44" from="id.30"/>
        <codeElement xmi:id="id.35" xmi:type="code:Signature" name="swap">
          <source xmi:id="id.36" language="C" snippet="light swap(light new_light)"/>
          <parameterUnit xmi:id="id.37" name="swap" type="id.2" kind="return" pos="0"/>
          <parameterUnit xmi:id="id.38" name="new_light" type="id.2" pos="1"/>
        </codeElement>
        <codeElement xmi:id="id.39" xmi:type="code:StorableUnit" name="l" type="id.2" ext="" kind="static">
          <source xmi:id="id.40" language="C" snippet="static light l=red;"/>
          <codeRelation xmi:id="id.41" xmi:type="code:HasValue" to="id.7" from="id.39"/>
        </codeElement>
        <codeElement xmi:id="id.42" xmi:type="code:StorableUnit" name="tmp" type="id.2" kind="local">
          <source xmi:id="id.43" language="C" snippet="light tmp; "/>
        </codeElement>
        <codeElement xmi:id="id.44" xmi:type="action:ActionElement" name="init" kind="Assign">
          <actionRelation xmi:id="id.45" xmi:type="action:Reads" to="id.7" from="id.44"/>
          <actionRelation xmi:id="id.46" xmi:type="action:Writes" to="id.39"/>
          <actionRelation xmi:id="id.47" xmi:type="action:Flow" to="id.48" from="id.44"/>
        </codeElement>
        <codeElement xmi:id="id.48" xmi:type="action:ActionElement" name="a3" kind="Assign">
          <source xmi:id="id.49" language="C" snippet="tmp=l;">
            <region xmi:id="id.50" file="id.69" startLine="7" startPosition="5" endLine="7" endPosition="11"/>
          </source>
          <actionRelation xmi:id="id.51" xmi:type="action:Reads" to="id.39" from="id.48"/>
          <actionRelation xmi:id="id.52" xmi:type="action:Writes" to="id.42" from="id.48"/>
          <actionRelation xmi:id="id.53" xmi:type="action:Flow" to="id.54" from="id.48"/>
        </codeElement>
        <codeElement xmi:id="id.54" xmi:type="action:ActionElement" name="a4" kind="Assign">
          <source xmi:id="id.55" language="C" snippet="l=new_light"/>
          <actionRelation xmi:id="id.56" xmi:type="action:Reads" to="id.38" from="id.54"/>
          <actionRelation xmi:id="id.57" xmi:type="action:Writes" to="id.39" from="id.54"/>
          <actionRelation xmi:id="id.58" xmi:type="action:Flow" to="id.59" from="id.54"/>
        </codeElement>
        <codeElement xmi:id="id.59" xmi:type="action:ActionElement" name="a5" kind="Assign">
          <source xmi:id="id.60" language="C" snippet="return tmp;"/>
          <actionRelation xmi:id="id.61" xmi:type="action:Reads" to="id.42" from="id.59"/>
          <actionRelation xmi:id="id.62" xmi:type="action:Writes" to="id.37" from="id.59"/>
        </codeElement>
      </codeElement>
    </codeElement>
    <codeElement xmi:id="id.63" xmi:type="code:StorableUnit" name="old_light" type="id.67">
      <source xmi:id="id.64" language="C" snippet="int old_light;"/>
    </codeElement>
  </model>
  <model xmi:id="id.65" xmi:type="code:CodeModel" name="C common definitions">
   
<codeElement xmi:id="id.66" xmi:type="code:LanguageUnit">
      <codeElement xmi:id="id.67" xmi:type="code:IntegerType" name="int"/>
    </codeElement>
  </model>
  <model xmi:id="id.68" xmi:type="source:InventoryModel">
    <inventoryElement xmi:id="id.69" xmi:type="source:SourceFile" name="light.c" encoding="UTF-8"/>
 
</model>
</kdm:Segment>