trusted components
play

Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand - PowerPoint PPT Presentation

1 Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand Meyer Till G. Bay Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21 2 Lecture 21: Eiffel AST Chair of Softw are Engineering


  1. 1 Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand Meyer Till G. Bay Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  2. 2 Lecture 21: Eiffel AST Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  3. Closing in on the AST 3 � Use Gobo from $eiffelstudio\ free_add_ons\ gobo\ � You start from an ACE-file that you parse with Gobo’s LACE parser $GOBO\ library\ tools\ lace\ parser\ et_lace_parser.e � Doing this will get you a universe $GOBO\ library\ tools\ eiffel\ ast\ misc\ et_universe.e � The universe gives you access to the list of clusters in the project -> you don’t have the list of classes yet Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  4. Building the AST 4 � To get the list of classes call parse_all of class ET_UNIVERSE � Now we can start adding class members to the AST NOTE: The AST is built using lists that match exactly the size of the parsed classes therefore if you want to add a new inheritance clause for example you will have to create a new parents list, fill it with the existing parents, add the new ones and then replace the old parent list with this new one. Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  5. Writing the AST to a File 5 � Create an ET_DECORATED_AST_FACTORY to write the AST to a file using the ET_AST_PRINTER. This makes sure that the formatting of the class text will be preserved, whereas with ET_AST_FACTORY it wouldn’t. Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  6. ( f )AST Example 6 � Take a look at class GELINT ($GOBO\ src\ gelint\ gelint.e) � The feature execute is intresting: create a_file.make (a_filename) a_filename: STRING a_file.open_read a_file: KL_TEXT_INPUT_FILE if a_file.is_open_read then a_lace_parser: ET_LACE_PARSER create a_lace_error_handler.make_standard a_lace_error_handler: ET_LACE_E… create a_lace_parser.make (a_lace_error_handler) a_universe: ET_UNIVERSE a_lace_parser.parse_file (a_file) a_file.close if not a_lace_parser.syntax_error then a_universe := a_lace_parser.last_universe end if a_universe /= Void then process_universe (a_universe) end else std.error.put_string ("gelint: cannot read %'") std.error.put_string (a_filename) std.error.put_line ("%'") end Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  7. ( f )AST Example: Parsing Comments too 7 � Take a look at process_universe: an_ast_factory: ET_DECORATED_AST_FACTORY create an_ast_factory.make an_ast_factory.set_keep_all_breaks (True) a_universe.set_ast_factory (an_ast_factory) � This makes sure we get a ET_DECORATED_AST_FACTORY instead of a ET_AST_FACTORY. Do this before calling parse_all on the universe. Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  8. ( f )AST Example: Setting up a Universe 8 � Still before parsing the universe, we have to set some options. a_universe.error_handler.set_ise a_universe.error_handler.set_info_null a_universe.set_use_assign_keyword (False) a_universe.set_use_attribute_keyword (False) a_universe.set_use_convert_keyword (True) a_universe.set_use_recast_keyword (False) a_universe.set_use_reference_keyword (True) a_universe.set_use_void_keyword (True) � If you use EiffelStudio 5.5 -> Void is a keyword with EiffelStudio 5.4 it isn’t. Do set the options correctly. Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  9. ( f )AST Example: Processing a universe 9 � Go back to process_universe, instead of calling compile, call a_universe.activate_processors a_universe.parse_all � Now you can access the AST using the lists. Don’t forget that the lists need to be replaced wherever you change something $GOBO\ library\ tools\ eiffel\ ast Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  10. ( p )AST Example: Printing to a File 10 out_file: KL_TEXT_OUTPUT_FILE create out_file.make (out_filename) out_file.recursive_open_write if out_file.is_open_write then create a_printer.make (out_file, a_universe) else create a_printer.make_null (a_universe) report_cannot_write_error (out_filename) Exceptions.die (1) end � Where a_printer is an ET_AST_PRINTER Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  11. ( p )AST Example: Printing to a File 11 a_cursor: DS_HASH_TABLE_CURSOR [ET_CLASS, ET_CLASS_NAME] a_class: ET_CLASS a_file: KL_TEXT_INPUT_FILE a_cursor := a_universe.classes.new_cursor from a_cursor.start until a_cursor.after loop a_class := a_cursor.item if a_class.is_preparsed then create a_file.make (a_class.filename) a_file.open_write if a_file.is_open_write then a_printer.set_file (a_file) a_class.process (a_printer) a_printer.set_null_file a_file.close else -- Report error. end end a_cursor.forth end Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  12. Exam 12 � Nature: Oral or Written � Date: 2. February 2004 Times to be announced Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  13. Examined Topics 13 � Software Quality � Software Components � Software Reliability � Reuse, Trusted Components � Design Patterns � Formal Methods � Design by Contract � Contract Based Testing � Axiomatic Semantics Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  14. Topics not Examined 14 � Eclipse Component Model (Erich Gamma’s lecture) � Abstract State Machines (Egon Börger’s lectures) Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  15. Mailinglist 15 � dahls@student.ethz.ch � gag@kdlabs.com � Gisele.Douta@memcenter.unibe.ch � jianboxue@gmail.com � Keith@tice.ch � kistlerd@student.ethz.ch � kuennema@student.ethz.ch � lenggenc@student.ethz.ch � maireb@student.ethz.ch � muellren@student.ethz.ch � naegelis@student.ethz.ch � ramagumar@icontel.com � urmuelle@student.ethz.ch � costanzg@student.ethz.ch � baerm@student.ethz.ch Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

  16. 16 End of lecture 21 Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 21

Recommend


More recommend