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

trusted components
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

1

Chair of Softw are Engineering

Trusted Components

Reuse, Contracts and Patterns

  • Prof. Dr. Bertrand Meyer

Till G. Bay

slide-2
SLIDE 2

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

2

Chair of Softw are Engineering

Lecture 21: Eiffel AST

slide-3
SLIDE 3

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

3

Chair of Softw are Engineering

Closing in on the AST

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

slide-4
SLIDE 4

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

4

Chair of Softw are Engineering

Building the AST

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

  • ne.
slide-5
SLIDE 5

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

5

Chair of Softw are Engineering

Writing the AST to a File

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.

slide-6
SLIDE 6

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

6

Chair of Softw are Engineering

(f)AST Example

Take a look at class GELINT ($GOBO\ src\ gelint\ gelint.e) The feature execute is intresting:

a_filename: STRING a_file: KL_TEXT_INPUT_FILE a_lace_parser: ET_LACE_PARSER a_lace_error_handler: ET_LACE_E… a_universe: ET_UNIVERSE create a_file.make (a_filename) a_file.open_read if a_file.is_open_read then create a_lace_error_handler.make_standard create a_lace_parser.make (a_lace_error_handler) 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

slide-7
SLIDE 7

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

7

Chair of Softw are Engineering

(f)AST Example: Parsing Comments too

Take a look at process_universe: This makes sure we get a ET_DECORATED_AST_FACTORY instead of a ET_AST_FACTORY. Do this before calling parse_all

  • n the 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)

slide-8
SLIDE 8

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

8

Chair of Softw are Engineering

(f)AST Example: Setting up a Universe

Still before parsing the universe, we have to set some options. If you use EiffelStudio 5.5 -> Void is a keyword with EiffelStudio 5.4 it isn’t. Do set the options correctly.

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)

slide-9
SLIDE 9

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

9

Chair of Softw are Engineering

(f)AST Example: Processing a universe

Go back to process_universe, instead of calling compile, call 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

a_universe.activate_processors a_universe.parse_all

slide-10
SLIDE 10

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

10

Chair of Softw are Engineering

(p)AST Example: Printing to a File

Where a_printer is an ET_AST_PRINTER

  • ut_file: KL_TEXT_OUTPUT_FILE

create out_file.make (out_filename)

  • ut_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

slide-11
SLIDE 11

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

11

Chair of Softw are Engineering

(p)AST Example: Printing to a File

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

slide-12
SLIDE 12

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

12

Chair of Softw are Engineering

Exam

Nature: Oral or Written Date:

  • 2. February 2004 Times to be announced
slide-13
SLIDE 13

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

13

Chair of Softw are Engineering

Examined Topics

Software Quality Software Components Software Reliability Reuse, Trusted Components Design Patterns Formal Methods Design by Contract Contract Based Testing Axiomatic Semantics

slide-14
SLIDE 14

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

14

Chair of Softw are Engineering

Topics not Examined

Eclipse Component Model (Erich Gamma’s lecture) Abstract State Machines (Egon Börger’s lectures)

slide-15
SLIDE 15

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

15

Chair of Softw are Engineering

Mailinglist

  • 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
slide-16
SLIDE 16

Trusted Components: Reuse, Contracts and Patterns - Lecture 21

16

Chair of Softw are Engineering

End of lecture 21