Common use of PARSER Clause in Contracts

PARSER. As already mentioned there are two parsers: one for parsing a .NET assembly and one for reading an XML representation of the contracts. The .NET parser (CW_DOTNET_PARSER) produces the AST by retrieving information from the .NET assembly using the reflection mechanism of .NET. It parses the following information required to generate Eiffel proxy classes: • public types • public .NET constructors • public .NET methods • public .NET fields For every inspected information a specific type node of the AST is instantiated and appended to it (see Figure 2: Internal representation of proxy classes): • CW_TYPE for each public type • CW_ATTRIBUTE for every inspected public field • CW_PROCEDURE respectively CW_FUNCTION for each method • CW_CREATION_PROCEDURE for every parsed constructor To generate the Eiffel proxy classes correctly, the generator has to know more than just the name of an AST node. Important information can be: is a type deferred or expanded, is a feature static or deferred, what is the return type of a function? To satisfy these needs every node type holds some specific attributes that the parser sets. For each type (CW_TYPE) the parser sets the following queries: • is_deferred (is type deferred?) • is_expanded (is type expanded?) • is_array (is type an array?) • is_enum (is it an enumeration type?; an enumeration type is a distinct type with named constants) • is_interface (does type represent a .NET interface?) Moreover, the parser attaches to a type all interfaces (CW_INTERFACE) which it implements. An attribute is enriched with the following information: • is_static (is it a static field?) • is_constant (does the field represent a constant value?) • value (if the parsed field is a constant, a constant value is assigned) For each procedure and function, the parser sets the following attributes: • is_static (is method static?; static method are accessed through the class) • is_deferred (is method deferred?; deferred methods are methods declared in a .NET interface type) Additionally a function has the attributes: • return_type (the function’s return type) • is_property (a property is a member that provides access to a characteristic of an object or a class, attribute is set to true if the function is a get accessor) A helper class CW_NAME_FORMATTER translates the .NET names into Eiffel names. The .NET naming style is “CamelCase” and Eiffel’s convention is to use lower case and to separate names with an underscore. For example “toString” becomes “to_string”. This class CW_NAME_FORMATTER also handles the translation of: .NET primitive types, .NET class names that conflict with the EiffelBase library and, .NET names that conflict with keywords of the Eiffel language. The XML parser (CW_XML_PARSER) reads the XML representation of the Eiffel proxy classes – that may contain contracts – and builds the corresponding AST. It uses the Eiffel parser (XM_EIFFEL_PARSER) that is part of the Gobo library [3]. The structure of the XML file is defined through a document type definition (DTD). It can be used to validate an XML file. (A listing of the DTD can be found in section 4.2.5: Abstract syntax tree.)

Appears in 3 contracts

Sources: Master Thesis, Master Thesis, Master Thesis