-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
* added new AST feature definition node and the new syntax to define a named feature - related to ref #35 * added new AST declaration definition node (needed by feature etc.)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,10 @@ END 0 "end of file" | |
%type <RuleDefinition::Ptr> RuleDefinition | ||
%type <EnumerationDefinition::Ptr> EnumerationDefinition | ||
%type <StructureDefinition::Ptr> StructureDefinition | ||
%type <FeatureDefinition::Ptr> FeatureDefinition | ||
%type <Definition::Ptr> FeatureDeclarationOrDefinition | ||
%type <Definitions::Ptr> FeatureDeclarationsAndDefinitions | ||
%type <DeclarationDefinition::Ptr> DeclarationDefinition | ||
|
||
// expressions | ||
%type <Expression::Ptr> Expression Term Atom | ||
|
@@ -303,6 +307,10 @@ Definition | |
{ | ||
$$ = $1; | ||
} | ||
| FeatureDefinition | ||
{ | ||
$$ = $1; | ||
} | ||
| error // error recovery | ||
{ | ||
$$ = nullptr; | ||
|
@@ -554,6 +562,62 @@ StructureDefinition | |
; | ||
|
||
|
||
FeatureDefinition | ||
: FEATURE Identifier EQUAL LCURPAREN FeatureDeclarationsAndDefinitions RCURPAREN | ||
{ | ||
$$ = Ast::make< FeatureDefinition >( @$, $2, $5 ); | ||
} | ||
; | ||
|
||
|
||
FeatureDeclarationOrDefinition | ||
This comment has been minimized.
Sorry, something went wrong. |
||
: DeclarationDefinition | ||
{ | ||
$$ = $1; | ||
} | ||
| DerivedDefinition | ||
{ | ||
$$ = $1; | ||
} | ||
| RuleDefinition | ||
{ | ||
$$ = $1; | ||
} | ||
; | ||
|
||
|
||
FeatureDeclarationsAndDefinitions | ||
: FeatureDeclarationsAndDefinitions COMMA FeatureDeclarationOrDefinition | ||
This comment has been minimized.
Sorry, something went wrong.
emmanuel099
Member
|
||
{ | ||
auto definitions = $1; | ||
definitions->add( $3 ); | ||
$$ = definitions; | ||
} | ||
| FeatureDeclarationOrDefinition | ||
{ | ||
auto definitions = Ast::make< Definitions >( @$ ); | ||
definitions->add( $1 ); | ||
$$ = definitions; | ||
} | ||
; | ||
|
||
|
||
DeclarationDefinition | ||
This comment has been minimized.
Sorry, something went wrong.
emmanuel099
Member
|
||
: DERIVED Identifier COLON MaybeFunctionParameters MAPS Type | ||
{ | ||
auto declaration = Ast::make< DeclarationDefinition >( @$, $2, $4, $6 ); | ||
declaration->setKind( DeclarationDefinition::Kind::DERIVED ); | ||
$$ = declaration; | ||
} | ||
| RULE Identifier COLON MaybeFunctionParameters MAPS Type | ||
{ | ||
auto declaration = Ast::make< DeclarationDefinition >( @$, $2, $4, $6 ); | ||
declaration->setKind( DeclarationDefinition::Kind::RULE ); | ||
$$ = declaration; | ||
} | ||
; | ||
|
||
|
||
Identifier | ||
: IDENTIFIER | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,57 @@ namespace libcasm_fe | |
private: | ||
const NodeList< FunctionDefinition >::Ptr m_functions; | ||
}; | ||
|
||
class FeatureDefinition final : public Definition | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr< FeatureDefinition >; | ||
|
||
FeatureDefinition( const Identifier::Ptr& identifier, | ||
const Definitions::Ptr& definitions ); | ||
|
||
const Definitions::Ptr& definitions( void ) const; | ||
|
||
void accept( Visitor& visitor ) override final; | ||
|
||
private: | ||
const Definitions::Ptr m_definitions; | ||
}; | ||
|
||
class DeclarationDefinition final : public Definition | ||
{ | ||
public: | ||
using Ptr = std::shared_ptr< DeclarationDefinition >; | ||
|
||
enum class Kind | ||
{ | ||
DERIVED = 1, | ||
This comment has been minimized.
Sorry, something went wrong.
emmanuel099
Member
|
||
RULE | ||
}; | ||
|
||
DeclarationDefinition( const Identifier::Ptr& identifier, | ||
const Types::Ptr& argumentTypes, | ||
const Type::Ptr& returnType ); | ||
|
||
const Types::Ptr& argumentTypes( void ) const; | ||
|
||
const Type::Ptr& returnType( void ) const; | ||
|
||
void setKind( const Kind kind ); | ||
This comment has been minimized.
Sorry, something went wrong.
emmanuel099
Member
|
||
|
||
Kind kind( void ) const; | ||
|
||
std::string kindName( void ) const; | ||
|
||
void accept( Visitor& visitor ) override final; | ||
|
||
private: | ||
const Types::Ptr m_argumentTypes; | ||
const Type::Ptr m_returnType; | ||
Kind m_kind; | ||
}; | ||
|
||
using DeclarationDefinitions = NodeList< DeclarationDefinition >; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,19 @@ void RecursiveVisitor::visit( StructureDefinition& node ) | |
node.functions()->accept( *this ); | ||
} | ||
|
||
void RecursiveVisitor::visit( FeatureDefinition& node ) | ||
{ | ||
node.identifier()->accept( *this ); | ||
node.definitions()->accept( *this ); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
emmanuel099
Member
|
||
|
||
void RecursiveVisitor::visit( DeclarationDefinition& node ) | ||
{ | ||
node.identifier()->accept( *this ); | ||
node.argumentTypes()->accept( *this ); | ||
node.returnType()->accept( *this ); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
emmanuel099
Member
|
||
|
||
void RecursiveVisitor::visit( ValueAtom& node ) | ||
{ | ||
} | ||
|
2 comments
on commit fce06e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AstDumpDotVisitor
implementation is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed all issues and comments in 452957a...cc64255
It should also be possible to add attributes to them. (see grammar rule
AttributedDefinition
)