Skip to content

Commit

Permalink
Structure Definition
Browse files Browse the repository at this point in the history
* added new AST structure definition and its syntax
  - related to ref #35
* updated visitors etc.
  • Loading branch information
ppaulweber committed Jul 29, 2017
1 parent 41c349d commit 6997e6d
Show file tree
Hide file tree
Showing 19 changed files with 8,946 additions and 8,573 deletions.
32 changes: 31 additions & 1 deletion src/GrammarParser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ END 0 "end of file"
%type <Definitions::Ptr> Definitions
%type <VariableDefinition::Ptr> Variable AttributedVariable
%type <FunctionDefinition::Ptr> FunctionDefinition
%type <FunctionDefinitions::Ptr> FunctionDefinitions
%type <DerivedDefinition::Ptr> DerivedDefinition
%type <RuleDefinition::Ptr> RuleDefinition
%type <EnumerationDefinition::Ptr> EnumerationDefinition
%type <StructureDefinition::Ptr> StructureDefinition

// expressions
%type <Expression::Ptr> Expression Term Atom
Expand Down Expand Up @@ -210,7 +212,7 @@ END 0 "end of file"
%type <RelationType::Ptr> RelationType
%type <FixedSizedType::Ptr> FixedSizedType

// types
// attribute
%type <Attribute::Ptr> Attribute
%type <Attributes::Ptr> Attributes
%type <BasicAttribute::Ptr> BasicAttribute
Expand Down Expand Up @@ -297,6 +299,10 @@ Definition
{
$$ = $1;
}
| StructureDefinition
{
$$ = $1;
}
| error // error recovery
{
$$ = nullptr;
Expand Down Expand Up @@ -358,6 +364,22 @@ FunctionDefinition
;


FunctionDefinitions
: FunctionDefinitions COMMA FunctionDefinition

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

I think the COMMA should be removed (btw. the AstDumpSourceVisitor dumps it without commas)

{
auto functions = $1;
functions->add( $3 );
$$ = functions;
}
| FunctionDefinition
{
auto functions = Ast::make< FunctionDefinitions >( @$ );
functions->add( $1 );
$$ = functions;
}
;


MaybeInitially
: INITIALLY LCURPAREN MaybeInitializers RCURPAREN
{
Expand Down Expand Up @@ -524,6 +546,14 @@ EnumerationDefinition
;


StructureDefinition
: STRUCTURE Identifier EQUAL LCURPAREN FunctionDefinitions RCURPAREN

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

It should also be possible to add attributes to the function definitions. (see grammar rule AttributedDefinition)

{
$$ = Ast::make< StructureDefinition >( @$, $2, $5 );
}
;


Identifier
: IDENTIFIER
{
Expand Down
2 changes: 2 additions & 0 deletions src/GrammarToken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ FUNCTION "function" { return Parser::make_FUNCTION(loc); }
INITIALLY "initially" { return Parser::make_INITIALLY(loc); }
DEFINED "defined" { return Parser::make_DEFINED(loc); }

STRUCTURE "structure" { return Parser::make_STRUCTURE(loc); }

SEQ "seq" { return Parser::make_SEQ(loc); }
ENDSEQ "endseq" { return Parser::make_ENDSEQ(loc); }
PAR "par" { return Parser::make_PAR(loc); }
Expand Down
10 changes: 10 additions & 0 deletions src/Namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,13 @@ Namespace::Symbol Namespace::find( const IdentifierPath& node,
return result->second.front();
}
}

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

unrelated change ... (info for future changes) ;)

//
// Local variables:
// mode: c++
// indent-tabs-mode: nil
// c-basic-offset: 4
// tab-width: 4
// End:
// vim:noexpandtab:sw=4:ts=4:
//
33 changes: 33 additions & 0 deletions src/ast/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,36 @@ void EnumerationDefinition::accept( Visitor& visitor )
{
visitor.visit( *this );
}

//
//
// StructureDefinition
//

StructureDefinition::StructureDefinition( const Identifier::Ptr& identifier,
const NodeList< FunctionDefinition >::Ptr& functions )

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

Please use FunctionDefinitions instead of NodeList< FunctionDefinition >

: Definition( Node::ID::STRUCTURE_DEFINITION, identifier )
, m_functions( functions )
{
}

const NodeList< FunctionDefinition >::Ptr& StructureDefinition::functions(

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

Please use FunctionDefinitions instead of NodeList< FunctionDefinition >

void ) const
{
return m_functions;
}

void StructureDefinition::accept( Visitor& visitor )
{
visitor.visit( *this );
}

//
// Local variables:
// mode: c++
// indent-tabs-mode: nil
// c-basic-offset: 4
// tab-width: 4
// End:
// vim:noexpandtab:sw=4:ts=4:
//
18 changes: 18 additions & 0 deletions src/ast/Definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ namespace libcasm_fe
UID m_uid;
};

using FunctionDefinitions = NodeList< FunctionDefinition >;

class DerivedDefinition final : public Definition
{
public:
Expand Down Expand Up @@ -216,6 +218,22 @@ namespace libcasm_fe
private:
const Identifiers::Ptr m_enumerators;
};

class StructureDefinition final : public Definition
{
public:
using Ptr = std::shared_ptr< StructureDefinition >;

StructureDefinition( const Identifier::Ptr& identifier,
const NodeList< FunctionDefinition >::Ptr& functions );

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

Please use FunctionDefinitions instead of NodeList< FunctionDefinition >


const NodeList< FunctionDefinition >::Ptr& functions( void ) const;

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

Please use FunctionDefinitions instead of NodeList< FunctionDefinition >


void accept( Visitor& visitor ) override final;

private:
const NodeList< FunctionDefinition >::Ptr m_functions;

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

Please use FunctionDefinitions instead of NodeList< FunctionDefinition >

};
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/ast/EmptyVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void EmptyVisitor::visit( EnumerationDefinition& )
{
}

void EmptyVisitor::visit( StructureDefinition& )
{
}

void EmptyVisitor::visit( ValueAtom& )
{
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/EmptyVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace libcasm_fe
void visit( DerivedDefinition& node ) override;
void visit( RuleDefinition& node ) override;
void visit( EnumerationDefinition& node ) override;
void visit( StructureDefinition& node ) override;

void visit( ValueAtom& node ) override;
void visit( ReferenceAtom& node ) override;
Expand Down
4 changes: 4 additions & 0 deletions src/ast/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ std::string Node::description( void ) const
{
return "enumeration";
}
case ID::STRUCTURE_DEFINITION:
{
return "structure";
}
case ID::VALUE_ATOM:
{
return "value";
Expand Down
1 change: 1 addition & 0 deletions src/ast/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace libcasm_fe
DERIVED_DEFINITION,
RULE_DEFINITION,
ENUMERATION_DEFINITION,
STRUCTURE_DEFINITION,

// expressions
VALUE_ATOM,
Expand Down
6 changes: 6 additions & 0 deletions src/ast/RecursiveVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ void RecursiveVisitor::visit( EnumerationDefinition& node )
node.attributes()->accept( *this );
}

void RecursiveVisitor::visit( StructureDefinition& node )
{
node.identifier()->accept( *this );
node.functions()->accept( *this );
}

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

node.attributes()->accept( *this ); is missing (every definition has attributes)


void RecursiveVisitor::visit( ValueAtom& node )
{
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/RecursiveVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace libcasm_fe
void visit( DerivedDefinition& node ) override;
void visit( RuleDefinition& node ) override;
void visit( EnumerationDefinition& node ) override;
void visit( StructureDefinition& node ) override;

void visit( ValueAtom& node ) override;
void visit( ReferenceAtom& node ) override;
Expand Down
2 changes: 2 additions & 0 deletions src/ast/Visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace libcasm_fe
class DerivedDefinition;
class RuleDefinition;
class EnumerationDefinition;
class StructureDefinition;

class ValueAtom;
class ReferenceAtom;
Expand Down Expand Up @@ -94,6 +95,7 @@ namespace libcasm_fe
virtual void visit( DerivedDefinition& node ) = 0;
virtual void visit( RuleDefinition& node ) = 0;
virtual void visit( EnumerationDefinition& node ) = 0;
virtual void visit( StructureDefinition& node ) = 0;

virtual void visit( ValueAtom& node ) = 0;
virtual void visit( ReferenceAtom& node ) = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/execute/NumericExecutionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class ExecutionVisitor final : public EmptyVisitor
void visit( DerivedDefinition& node ) override;
void visit( RuleDefinition& node ) override;
void visit( EnumerationDefinition& node ) override;
void visit( StructureDefinition& node ) override;

void visit( ValueAtom& node ) override;
void visit( ReferenceAtom& node ) override;
Expand Down Expand Up @@ -481,6 +482,11 @@ void ExecutionVisitor::visit( EnumerationDefinition& node )
m_evaluationStack.push( ir::EnumerationConstant( enumType ) );
}

void ExecutionVisitor::visit( StructureDefinition& node )
{
// TODO: PPA: CONT'D #35
}

void ExecutionVisitor::visit( ValueAtom& node )
{
m_evaluationStack.push( *node.value() );
Expand Down
14 changes: 14 additions & 0 deletions src/transform/AstDumpSourcePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class AstDumpSourceVisitor final : public Visitor
void visit( DerivedDefinition& node ) override;
void visit( RuleDefinition& node ) override;
void visit( EnumerationDefinition& node ) override;
void visit( StructureDefinition& node ) override;

void visit( ValueAtom& node ) override;
void visit( ReferenceAtom& node ) override;
Expand Down Expand Up @@ -323,6 +324,19 @@ void AstDumpSourceVisitor::visit( EnumerationDefinition& node )
m_stream << "}";
}

void AstDumpSourceVisitor::visit( StructureDefinition& node )
{
m_stream << "structure ";
node.identifier()->accept( *this );
m_stream << " =\n{";
for( auto& e : *node.functions() )
{
m_stream << "\n ";

This comment has been minimized.

Copy link
@emmanuel099

emmanuel099 Jul 30, 2017

Member

please use the Indentation feature instead.

e->accept( *this );
}
m_stream << "}";
}

void AstDumpSourceVisitor::visit( ValueAtom& node )
{
m_stream << node.value()->name();
Expand Down
8 changes: 8 additions & 0 deletions src/various/Grammar.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Definition
| DerivedDefinition
| RuleDefinition
| EnumerationDefinition
| StructureDefinition
| error // error recovery

AttributedDefinition
Expand All @@ -21,6 +22,10 @@ FunctionDefinition
: FUNCTION Identifier COLON MaybeFunctionParameters MAPS Type MaybeDefined MaybeInitially
| ProgramFunctionDefinition

FunctionDefinitions
: FunctionDefinitions COMMA FunctionDefinition
| FunctionDefinition

MaybeInitially
: INITIALLY LCURPAREN MaybeInitializers RCURPAREN
| %empty
Expand Down Expand Up @@ -60,6 +65,9 @@ DerivedDefinition
EnumerationDefinition
: ENUM Identifier EQUAL LCURPAREN Identifiers RCURPAREN

StructureDefinition
: STRUCTURE Identifier EQUAL LCURPAREN FunctionDefinitions RCURPAREN

Identifier
: IDENTIFIER
| IN // allow in keyword as identifier
Expand Down
Loading

2 comments on commit 6997e6d

@emmanuel099
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AstDumpDotVisitor implementation is missing

@ppaulweber
Copy link
Member Author

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

Please sign in to comment.