ASIS表現を見る

package test is
   type t is record
      a : integer;
      b : integer := 10;
   end record;
end test;

手始めにこれがASISでどう見えるのかを探りたいと思います。
asistant。

initialize("")
set(c)
associate(c,"test","-FS")
open(c)
set(u, Library_Unit_Declaration("Test", c))
print(u)
set(d, unit_declaration(u))
print(d)
set(n, names(d))
print(n)
set(t, n(1))
print(t)
print(Defining_Name_Image(t))
set(items, Visible_Part_Declarative_Items(d, false))
print(items)
set(z, items(1))
print(z)
set(x, names(z))
print(x)
print(Defining_Name_Image(x(1)))
print(Element_Kind(z))
print(Declaration_Kind(z))
print(Element_Kind(x(1)))
print(Defining_Name_Kind(x(1)))
set(v, Type_Declaration_View(z))
print(v)
set(r, Record_Definition(v))
print(r)
set(f, Record_Components(r, false))
print(f)
print(names(f(1)))
print(names(f(2)))
set(i, names(f(1)))
print(Defining_Name_Image(i(1)))
close(c)
dissociate(c)
finalize("")
...>asistant test.scr
ASIStant - ASIS Tester And iNTerpreter, v1.5
(C) 1997-2006, Free Software Foundation, Inc.
  Asis Version: ASIS 2.0.R

initialize("")
set(c)
associate(c,"test","-FS")
open(c)
set(u, Library_Unit_Declaration("Test", c))
print(u)

Compilation Unit Debug_Image:
Unit Id:  3
   Unit name: test
   Kind:      A_PACKAGE
   Class:     A_PUBLIC_DECLARATION
   Origin:    AN_APPLICATION_UNIT
   Enclosing Context Id:  1
   Is consistent: TRUE
                                                                                                • -
set(d, unit_declaration(u)) print(d) A_PACKAGE_DECLARATION at ( 1 : 1 )-( 6 : 9 ) set(n, names(d)) print(n) Element_List size: 1 A_DEFINING_IDENTIFIER at ( 1 : 9 )-( 1 : 12 ) set(t, n(1)) print(t) A_DEFINING_IDENTIFIER at ( 1 : 9 )-( 1 : 12 ) print(Defining_Name_Image(t)) test set(items, Visible_Part_Declarative_Items(d, false)) print(items) Element_List size: 1 AN_ORDINARY_TYPE_DECLARATION at ( 2 : 4 )-( 5 : 14 ) set(z, items(1)) print(z) AN_ORDINARY_TYPE_DECLARATION at ( 2 : 4 )-( 5 : 14 ) set(x, names(z)) print(x) Element_List size: 1 A_DEFINING_IDENTIFIER at ( 2 : 9 )-( 2 : 9 ) print(Defining_Name_Image(x(1))) t print(Element_Kind(z)) A_DECLARATION print(Declaration_Kind(z)) AN_ORDINARY_TYPE_DECLARATION print(Element_Kind(x(1))) A_DEFINING_NAME print(Defining_Name_Kind(x(1))) A_DEFINING_IDENTIFIER set(v, Type_Declaration_View(z)) print(v) A_RECORD_TYPE_DEFINITION at ( 2 : 14 )-( 5 : 13 ) set(r, Record_Definition(v)) print(r) A_RECORD_DEFINITION at ( 2 : 14 )-( 5 : 13 ) set(f, Record_Components(r, false)) print(f) Element_List size: 2 A_COMPONENT_DECLARATION at ( 3 : 7 )-( 3 : 18 ) A_COMPONENT_DECLARATION at ( 4 : 7 )-( 4 : 24 ) print(names(f(1))) Element_List size: 1 A_DEFINING_IDENTIFIER at ( 3 : 7 )-( 3 : 7 ) print(names(f(2))) Element_List size: 1 A_DEFINING_IDENTIFIER at ( 4 : 7 )-( 4 : 7 ) set(i, names(f(1))) print(Defining_Name_Image(i(1))) a close(c) dissociate(c) finalize("")

情報が取れていることはわかる。これでrecordのI/Oマッパー自動生成とかもできそうです。
asistantではまどろっこしいので、asis2xml。

...>gcc -c -gnatt test.ads

...>asis2xml test.adt
Asis.Ada_Environments.Open:
tree file test.adt is not compile-only

理由がわからないので、Avatox。

...>avatox test.ads > a

で出力結果。

<?xml version="1.0" encoding="UTF-8" ?>
<codeRepresentation>
   <sourceLanguage name="Ada" languageVersion="95" compiler="GNAT 4.1.1"/>
   <pedigrees>
      <pedigree name="asis" xmlStyle="false">
         <standardInfo name="Ada Semantic Interface Specification (ASIS)" implementor="AdaCore (http://www.adacore.com)" implementorVersion="ASIS 2.0.R for GNAT 4.1.1"/>
      </pedigree>
      <pedigree name="avatoxAsis" xmlStyle="false">
         <processorInfo name="Avatox" implementor="McKae Technologies (www.mckae.com)" implementorVersion="1.1"/>
      </pedigree>
   </pedigrees>
   <A_PACKAGE pedigree="asis" unitName="test" startLine="1" endLine="6" startCol="1" endCol="9">
      <A_DECLARATION pedigree="asis" startLine="1" endLine="6" startCol="1" endCol="9">
         <A_PACKAGE_DECLARATION pedigree="asis" startLine="1" endLine="6" startCol="1" endCol="9">
         </A_PACKAGE_DECLARATION>
         <A_DEFINING_NAME pedigree="asis" startLine="1" endLine="1" startCol="9" endCol="12">
            <A_DEFINING_IDENTIFIER pedigree="asis" name="test" startLine="1" endLine="1" startCol="9" endCol="12"/>
         </A_DEFINING_NAME>
         <A_DECLARATION pedigree="asis" startLine="2" endLine="5" startCol="4" endCol="14">
            <AN_ORDINARY_TYPE_DECLARATION pedigree="asis" startLine="2" endLine="5" startCol="4" endCol="14">
            </AN_ORDINARY_TYPE_DECLARATION>
            <A_DEFINING_NAME pedigree="asis" startLine="2" endLine="2" startCol="9" endCol="9">
               <A_DEFINING_IDENTIFIER pedigree="asis" name="t" startLine="2" endLine="2" startCol="9" endCol="9"/>
            </A_DEFINING_NAME>
            <A_DEFINITION pedigree="asis" startLine="2" endLine="5" startCol="14" endCol="13">
               <A_TYPE_DEFINITION pedigree="asis" startLine="2" endLine="5" startCol="14" endCol="13">
                  <A_RECORD_TYPE_DEFINITION pedigree="asis" startLine="2" endLine="5" startCol="14" endCol="13">
                     <AN_ORDINARY_TRAIT pedigree="asis" pedigree="asis" startLine="2" endLine="5" startCol="14" endCol="13"/>
                  </A_RECORD_TYPE_DEFINITION>
               </A_TYPE_DEFINITION>
               <A_DEFINITION pedigree="asis" startLine="2" endLine="5" startCol="14" endCol="13">
                  <A_RECORD_DEFINITION pedigree="asis" startLine="2" endLine="5" startCol="14" endCol="13">
                  </A_RECORD_DEFINITION>
                  <A_DECLARATION pedigree="asis" startLine="3" endLine="3" startCol="7" endCol="18">
                     <A_COMPONENT_DECLARATION pedigree="asis" startLine="3" endLine="3" startCol="7" endCol="18">
                     </A_COMPONENT_DECLARATION>
                     <A_DEFINING_NAME pedigree="asis" startLine="3" endLine="3" startCol="7" endCol="7">
                        <A_DEFINING_IDENTIFIER pedigree="asis" name="a" startLine="3" endLine="3" startCol="7" endCol="7"/>
                     </A_DEFINING_NAME>
                     <A_DEFINITION pedigree="asis" startLine="3" endLine="3" startCol="11" endCol="17">
                        <A_COMPONENT_DEFINITION pedigree="asis" startLine="3" endLine="3" startCol="11" endCol="17">
                           <AN_ORDINARY_TRAIT pedigree="asis" startLine="3" endLine="3" startCol="11" endCol="17"/>
                        </A_COMPONENT_DEFINITION>
                        <A_DEFINITION pedigree="asis" startLine="3" endLine="3" startCol="11" endCol="17">
                           <A_SUBTYPE_INDICATION pedigree="asis" startLine="3" endLine="3" startCol="11" endCol="17">
                           </A_SUBTYPE_INDICATION>
                           <AN_EXPRESSION pedigree="asis" startLine="3" endLine="3" startCol="11" endCol="17">
                              <AN_IDENTIFIER pedigree="asis" ident="integer" startLine="3" endLine="3" startCol="11" endCol="17"/>
                           </AN_EXPRESSION>
                        </A_DEFINITION>
                     </A_DEFINITION>
                  </A_DECLARATION>
                  <A_DECLARATION pedigree="asis" startLine="4" endLine="4" startCol="7" endCol="24">
                     <A_COMPONENT_DECLARATION pedigree="asis" startLine="4" endLine="4" startCol="7" endCol="24">
                     </A_COMPONENT_DECLARATION>
                     <A_DEFINING_NAME pedigree="asis" startLine="4" endLine="4" startCol="7" endCol="7">
                        <A_DEFINING_IDENTIFIER pedigree="asis" name="b" startLine="4" endLine="4" startCol="7" endCol="7"/>
                     </A_DEFINING_NAME>
                     <A_DEFINITION pedigree="asis" startLine="4" endLine="4" startCol="11" endCol="17">
                        <A_COMPONENT_DEFINITION pedigree="asis" startLine="4" endLine="4" startCol="11" endCol="17">
                           <AN_ORDINARY_TRAIT pedigree="asis" startLine="4" endLine="4" startCol="11" endCol="17"/>
                        </A_COMPONENT_DEFINITION>
                        <A_DEFINITION pedigree="asis" startLine="4" endLine="4" startCol="11" endCol="17">
                           <A_SUBTYPE_INDICATION pedigree="asis" startLine="4" endLine="4" startCol="11" endCol="17">
                           </A_SUBTYPE_INDICATION>
                           <AN_EXPRESSION pedigree="asis" startLine="4" endLine="4" startCol="11" endCol="17">
                              <AN_IDENTIFIER pedigree="asis" ident="integer" startLine="4" endLine="4" startCol="11" endCol="17"/>
                           </AN_EXPRESSION>
                        </A_DEFINITION>
                     </A_DEFINITION>
                     <AN_EXPRESSION pedigree="asis" startLine="4" endLine="4" startCol="22" endCol="23">
                        <AN_INTEGER_LITERAL pedigree="asis" literal="10" startLine="4" endLine="4" startCol="22" endCol="23"/>
                     </AN_EXPRESSION>
                  </A_DECLARATION>
               </A_DEFINITION>
            </A_DEFINITION>
         </A_DECLARATION>
      </A_DECLARATION>
   </A_PACKAGE>
</codeRepresentation>

……ASIS入れ子深過ぎる。それ以上にXML冗長過ぎる。