The main parsing function is the Ocarina.Parser.Parse
function. This function selects automatically the right parser
depending on the file suffix: If the file suffix is “.aadl”, then
the parsing function used is Ocarina.AADL.Parser.Process
and if
the file suffix is “.dia”, then the parsing function used is
Ocarina.Dia.Parser.Process
. Therefore, the input files given to
the Parse function must have valid suffixes.
The return value of the Ocarina.Parser.Parse
function is the node
corresponding to the root of the tree. If something went wrong during
the parsing, the return value is No_Node
. The first parameter
given to the Ocarina.Parser.Parse
function is the name of the file
to parse. The second parameter corresponds to the tree root, this way,
it's possible to parse many files by calling the function several
times and by giving to it the same root as second parameter. After
each call, the returned value is the old tree to which are added the
AADL entities of the last parsed file. Hence Ocarina supports multiple
file AADL descriptions.
Unlike the parsing facility, the printing facility cannot be selected automatically. The user must precise which printer he wants to use.
The data structure Ocarina.Printer.Output_Options
contains a field
named Printer_Name
which allows to select a registered
printer. There are other fields in this structure, they allow to
configure some printing options (output file, output directory...).
The user should not directly use the parsing and printing subprogram
supplied by each module. To parse a file, the function that should be
used is Ocarina.Parser.Parse
. To print a file, the user must
specify the printer options in a variable of type
Ocarina.Printer.Output_Options
, then call the
Ocarina.Printer.Print
function with the Root of the AADL tree
and the options variable as parameters. Here is a sample code that
shows how to initialize Ocarina, parse and print a set of AADL
files. The example describes a classical way to use the Ocarina
libraries to build a basic program that loops indefinitely and parses
at each iteration all the AADL files given to its command line. If the
parsing has been successful, the program prints the AADL sources
corresponding to the built AADL syntax tree. The example illustrates
also the Reset capabilities of Ocarina allowing to reinitialize
all the Ocarina engines at the end of an iteration in order to use
them in the incoming iteration.
------------------------------------------------------------------------------ -- -- -- OCARINA COMPONENTS -- -- -- -- P A R S E _ A N D _ P R I N T _ A A D L -- -- -- -- B o d y -- -- -- -- Copyright (C) 2007, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina is distributed in the hope that it will be -- -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -- -- Public License for more details. You should have received a copy of the -- -- GNU General Public License distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Ada.Command_Line; with GNAT.OS_Lib; with Types; with Namet; with Ocarina.Configuration; with Ocarina.Parser; with Ocarina.Printer; with Ocarina.Analyzer; procedure Parse_And_Print_AADL is use Types; use Namet; Root : Node_Id; Printer_Options : Ocarina.Printer.Output_Options := Ocarina.Printer.Default_Output_Options; Analysis_Options : constant Ocarina.Analyzer.Analyzer_Options := Ocarina.Analyzer.Default_Analyzer_Options; Success : Boolean; begin loop -- Initialization step Ocarina.Initialize; Ocarina.Configuration.Init_Modules; -- Parse the aadl source file, the right parser is selected -- automatically depending on the file suffix. It is important -- that the root node is set to No_Node at the very beginning -- or parsing. Root := No_Node; for J in 1 .. Ada.Command_Line.Argument_Count loop -- Parse the file corresponding to the Jth argument opf the -- commant line and enrich the global AADL tree. Root := Ocarina.Parser.Parse (Ada.Command_Line.Argument (J), Root); end loop; -- If something went wrong, Root = No_Node if Root /= No_Node then -- Analyze the tree Success := Ocarina.Analyzer.Analyze_Tree (Root, Analysis_Options); if Success then -- Select the printer Set_Str_To_Name_Buffer ("aadl"); Printer_Options.Printer_Name := Name_Find; -- Print to an AADL File Success := Ocarina.Printer.Print (Root => Root, Options => Printer_Options); else GNAT.OS_Lib.OS_Exit (1); end if; else GNAT.OS_Lib.OS_Exit (1); end if; -- Pause for 1 second delay 1.0; -- Reset step Ocarina.Configuration.Reset_Modules; Ocarina.Reset; end loop; end Parse_And_Print_AADL;