Skip to content

Register, represent and implement semantic domain objects (A01.T01) #1262

@mayanje

Description

@mayanje

Purpose:

Semantic objects are the objects of the domain of definitions of a semantic analyzer, they are the symbols, the types, the tables of symbols. A symbol is the semantic representation of an entity, in a program to which we can give a name, a semantic meaning. The uniqueness of symbols is ensured by their presence in a table of symbols.

  • In the current TypeCobol infrastructure, reference is made to a symbol in terms of grouping information (attributes) on a symbol (SymbolInformation): Symbol type (FileName, MethodName, IndexName, ..), role (Reference, Definition , ExternalName, ..),

  • SymbolInformation are weakly typed (in fact not at all), the type here is only information on the symbol category and not the Semantic Type in the sense of a Type System.

  • SymbolInformation instances are only local information on a supposed symbol, in the sense that there is no associated symbol table, in addition there is no possible parent hierarchy, that is, say we can not determine if the symbol is contained in another symbol. For example we could not represent a symbol that would be a namespace.

    • Instances of type QualifiedSymbolReference are only a representation of a qualified name based on instances of SymbolReferences.
  • For these reasons it is important to be able to create classes of instances for the different types of symbols that can contain child symbols (eg the symbols symbols) and also allow these symbols to be stored in real symbol tables; what does the TypeCobol infrastructure do not do

The task : Implement real Symbol Tables #1278 could reuse all the implemention done here.

Semantic Symbols

The class diagram preview below shows the primary semantic symbols represented. This is a simplified class diagram, refer to the source code for members descriptions.

class_type_cobol_1_1_compiler_1_1_symbols_1_1_symbol__inherit__graph

Class Description
ISemanticData An interface that specifies the Kind of Semantic Data (Type or Symbol).
Symbol The abstract base class of all kind of symbols.
AbstractScope The abstract base class of all symbol that can a scope.
NamespaceSymbol The class of objet that represents a namespace. Right now TypeCobol does not support namespace. For the moment this symbol is used to represent the Global namespace.
ProgramSymbol The class of objet that represents a program.
FunctionSymbol The class of objet that represents an Function.
ParagraphSymbol The class of objet that represents a paragraph.
SectionSymbol The class of objet that represents a section.
VariableSymbol The class of objet that represents any variable.
IndexSymbol The class of objet that represents an Index.
RedefinesSymbol The class of objet that represents a REDEFINES Symbol.
RenamesSymbol The class of objet that represents a RENAMES Symbol.
VariableTypeSymbol The class of objet that represents a Type Symbol like the Symbol for a TYPEDEF. For instance, in the following sample the variable MyInt is associated to a symbol instance of the class VariableTypeSymbol because its type Int comes from a TYPEDEF declaration.
01 Int TYPEDEF PIC 9(4)
01 MyInt TYPE Int.

|

Semantic Types

The class diagram preview below shows the primary semantic types represented for the Type System. This is a simplified class diagram, refer to the source code for members descriptions.

class_type_cobol_1_1_compiler_1_1_types_1_1_type__inherit__graph

Class Description
ISemanticData An interface that specify the Kind of Semantic Data (Type or Symbol), thus here a Type.
Type The abstract base class of all kind of types.
ArrayType The class of objet that represents an array type.
PictureType The class of objet that represents a PICTURE type.
PointerType The class of objet that represents a POINTER type.
ProgramType The class of objet that represents a Program type.
FunctionType The class of objet that represents a Function type.
GroupType The class of objet that represents a Group type.
TypedefType The class of objet that represents a TYPEDEF type.
RenamesType The class of objet that represents a RENAMES type.

Scopes

The class diagram preview below shows the primary scopes. A scope is in fact the basic representation of a Symbol table with entries of symbols. This is a simplified class diagram, refer to the source code for members descriptions.

class_type_cobol_1_1_compiler_1_1_scopes_1_1_scope__coll__graph
class_type_cobol_1_1_compiler_1_1_scopes_1_1_root_symbol_table__inherit__graph

Class Description
IScope Interface that describes a scope.
Scope Generic class for representing a Scope that contains symbols of the same generic type T.
Entry Generic class for representing an entry in a generic Scope.
RootSymbolTable The class of objet that represents a Root Symbol Table.

Visitor pattern and related objects

There to kinds of visitor patterns:

  1. A Visitor for types
  2. A Visitor For symbols.

Types visitor

A Visitor for types is used to implements operations (or relations) on types. Most common operations are binary relations of the form: Type * TS -> TR.
With TS a type variable for an argument and TR a type variable for the returned value.

The class diagram preview below shows the primary visitor patterns over types representation. This is a simplified class diagram, refer to the source code for members descriptions.

class_type_cobol_1_1_compiler_1_1_types_1_1_type_1_1_abstract_type_visitor__inherit__graph

Class Description
IVisitor The interface for a Types visitor.
AbstractTypeVisitor The abstract class for a Types visitor.
TypeValidator Visitor on types for checking if types are well formed.
CyclicTypeChecker Visitor on types for detecting Cyclic TYPEDEF definitions.
TypedefExpander Visitor on types to expand TYPEDEF definitions to their Cobol85 representation.
TypeLevelRenumber Visitor on types for renumbering Level numbers.

Symbols visitor

A Visitor for symbols is used to implements operations (or relations) on symbols. Most common operations on symbols are binary relations of the form : Symbol * TP -> TR.
Where TP is a type variable for an argument and TR a type variable for a resulting value.

class_type_cobol_1_1_compiler_1_1_symbols_1_1_symbol_1_1_abstract_symbol_visitor__inh!erit__graph

The following are the Visitor over symbols implemented.

Class Description
IVisitor The interface for a Symbol visitor.
AbstractSymbolVisitor The abstract class for a Symbol visitor.
SymbolValidator Visitor on symbols for checking if symbols are well formed, that is to say if they are typed.
SymbolExpander Visitor on symbols to expand variables having a type that comes froma TypeDef.
LevelRenumber Visitor on symbols for for renumbering Level numbers.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions