Skip to content

Commit

Permalink
Declaration Definition
Browse files Browse the repository at this point in the history
* fixed ctor to directly initialize the kind type
* renamed in grammar to 'Declaration' for readability reasons
* related to sealangdotorg/sea#35
  • Loading branch information
ppaulweber committed Jun 10, 2021
1 parent 81f702f commit 355d79c
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 534 deletions.
18 changes: 8 additions & 10 deletions src/GrammarParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ END 0 "end of file"
%type <ImplementationDefinition::Ptr> ImplementationDefinition
%type <Definition::Ptr> ImplementationDefinitionDefinition
%type <Definitions::Ptr> ImplementationDefinitionDefinitions
%type <DeclarationDefinition::Ptr> DeclarationDefinition
%type <DeclarationDefinition::Ptr> Declaration

// literals
%type <Literal::Ptr> Literal
Expand Down Expand Up @@ -623,13 +623,13 @@ FeatureDefinition


FeatureDefinitionElement
: LSQPAREN Attributes RSQPAREN DeclarationDefinition
: LSQPAREN Attributes RSQPAREN Declaration
{
auto definition = $4;
definition->setAttributes( $2 );
$$ = definition;
}
| DeclarationDefinition
| Declaration
{
$$ = $1;
}
Expand Down Expand Up @@ -722,20 +722,18 @@ ImplementationDefinitionDefinitions
// DeclarationDefinition
//

DeclarationDefinition
Declaration
: DERIVED Identifier COLON MaybeFunctionParameters MAPS Type
{
// TODO: FIXME: @ppaulweber: handle AST keyword tokens $1, $3, and $5
auto declaration = Ast::make< DeclarationDefinition >( @$, $2, $4, $6 );
declaration->setKind( DeclarationDefinition::Kind::DERIVED );
$$ = declaration;
$$ = Ast::make< DeclarationDefinition >
( @$, $2, $4, $6, DeclarationDefinition::Kind::DERIVED );
}
| RULE Identifier COLON MaybeFunctionParameters MAPS Type
{
// TODO: FIXME: @ppaulweber: handle AST keyword tokens $1, $3, and $5
auto declaration = Ast::make< DeclarationDefinition >( @$, $2, $4, $6 );
declaration->setKind( DeclarationDefinition::Kind::RULE );
$$ = declaration;
$$ = Ast::make< DeclarationDefinition >
( @$, $2, $4, $6, DeclarationDefinition::Kind::RULE );
}
;

Expand Down
9 changes: 3 additions & 6 deletions src/ast/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,12 @@ void ImplementationDefinition::accept( Visitor& visitor )
DeclarationDefinition::DeclarationDefinition(
const Identifier::Ptr& identifier,
const Types::Ptr& argumentTypes,
const Type::Ptr& returnType )
const Type::Ptr& returnType,
const DeclarationDefinition::Kind kind )
: Definition( Node::ID::DECLARATION_DEFINITION, identifier )
, m_argumentTypes( argumentTypes )
, m_returnType( returnType )
, m_kind( kind )
{
}

Expand All @@ -789,11 +791,6 @@ const Type::Ptr& DeclarationDefinition::returnType( void ) const
return m_returnType;
}

void DeclarationDefinition::setKind( const Kind kind )
{
m_kind = kind;
}

DeclarationDefinition::Kind DeclarationDefinition::kind( void ) const
{
return m_kind;
Expand Down
9 changes: 4 additions & 5 deletions src/ast/Definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,21 +491,20 @@ namespace libcasm_fe

enum class Kind
{
DERIVED = 1,
DERIVED,
RULE
};

DeclarationDefinition(
const Identifier::Ptr& identifier,
const Types::Ptr& argumentTypes,
const Type::Ptr& returnType );
const Type::Ptr& returnType,
const Kind kind );

const Types::Ptr& argumentTypes( void ) const;

const Type::Ptr& returnType( void ) const;

void setKind( const Kind kind );

Kind kind( void ) const;

std::string kindName( void ) const;
Expand All @@ -515,7 +514,7 @@ namespace libcasm_fe
private:
const Types::Ptr m_argumentTypes;
const Type::Ptr m_returnType;
Kind m_kind;
const Kind m_kind;
};

using DeclarationDefinitions = NodeList< DeclarationDefinition >;
Expand Down
12 changes: 6 additions & 6 deletions src/various/Grammar.org
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ FeatureDefinition ::= "feature" Identifier "=" "{" FeatureDefinitionList "}"
** FeatureDefinitionElement

#+begin_src
FeatureDefinitionElement ::= "[" Attributes "]" DeclarationDefinition
| DeclarationDefinition
FeatureDefinitionElement ::= "[" Attributes "]" Declaration
| Declaration
| "[" Attributes "]" DerivedDefinition
| DerivedDefinition
| "[" Attributes "]" RuleDefinition
Expand Down Expand Up @@ -264,14 +264,14 @@ ImplementationDefinitionDefinitions ::= ImplementationDefinitionDefinition Imple
#+html: {{page>.:grammar:ImplementationDefinitionDefinitions&noheader&nofooter}}


** DeclarationDefinition
** Declaration

#+begin_src
DeclarationDefinition ::= "derived" Identifier ":" MaybeFunctionParameters "->" Type
| "rule" Identifier ":" MaybeFunctionParameters "->" Type
Declaration ::= "derived" Identifier ":" MaybeFunctionParameters "->" Type
| "rule" Identifier ":" MaybeFunctionParameters "->" Type
#+end_src

#+html: {{page>.:grammar:DeclarationDefinition&noheader&nofooter}}
#+html: {{page>.:grammar:Declaration&noheader&nofooter}}


** Rules
Expand Down
Loading

0 comments on commit 355d79c

Please sign in to comment.