Skip to content

Commit

Permalink
Identifier Path
Browse files Browse the repository at this point in the history
* integrated new identifier path
  - related to sealangdotorg/sea#19
  - related to sealangdotorg/sea#22
  • Loading branch information
ppaulweber committed Apr 7, 2017
1 parent 611a667 commit c8ca54f
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 353 deletions.
15 changes: 8 additions & 7 deletions src/GrammarParser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@
return Ast::make< FunctionDefinition >( sourceLocation, program, argTypes, ruleRefType );
}

static DirectCallExpression::Ptr createSelfBuiltinCall( Location& sourceLocation )
{
const auto self = libcasm_fe::Ast::make< IdentifierNode >( sourceLocation, "self" );
const auto arguments = libcasm_fe::Ast::make< Expressions >( sourceLocation );
return libcasm_fe::Ast::make< DirectCallExpression >( sourceLocation, self, arguments );
}

static IdentifierPath::Ptr asIdentifierPath( const Identifier::Ptr& identifier )
{
const auto& location = identifier->sourceLocation();
Expand All @@ -128,6 +121,14 @@
IdentifierPath::Type::ABSOLUTE );
}

static DirectCallExpression::Ptr createSelfBuiltinCall( Location& sourceLocation )
{
const auto self = libcasm_fe::Ast::make< Identifier >( sourceLocation, "self" );
const auto arguments = libcasm_fe::Ast::make< Expressions >( sourceLocation );
return libcasm_fe::Ast::make< DirectCallExpression >(
sourceLocation, asIdentifierPath( self ), arguments );
}

static Rule::Ptr wrapInBlockRule( const Rule::Ptr& rule )
{
if( (rule->id() == Node::ID::BLOCK_RULE )
Expand Down
10 changes: 5 additions & 5 deletions src/Namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
using namespace libcasm_fe;
using namespace Ast;

static std::string key( const IdentifierNode& node, const std::size_t arity );
static std::string key( const Identifier& node, const std::size_t arity );

Namespace::Namespace( void )
{
}

u64 Namespace::registerSymbol( Logger& log, const IdentifierNode& node,
u64 Namespace::registerSymbol( Logger& log, const Identifier& node,
const CallExpression::TargetType targetType, const std::size_t arity )
{
const auto _key = key( node, arity );
const auto _key = key( node.identifier(), arity );

auto result = m_symboltable.emplace( _key, targetType );

Expand Down Expand Up @@ -109,7 +109,7 @@ CallExpression::TargetType Namespace::find(
const DirectCallExpression& node ) const
{
const auto arity = node.arguments()->size();
const auto _key = key( *node.identifier(), arity );
const auto _key = key( *node.identifier()->identifiers()->back(), arity );

auto result = m_symboltable.find( _key );
if( result != m_symboltable.end() )
Expand Down Expand Up @@ -150,7 +150,7 @@ std::string Namespace::dump( const std::string& indention ) const
return s.str();
}

static std::string key( const IdentifierNode& node, const std::size_t arity )
static std::string key( const Identifier& node, const std::size_t arity )
{
const auto identifier = node.identifier();
return std::to_string( arity ) + "@" + identifier;
Expand Down
2 changes: 1 addition & 1 deletion src/Namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace libcasm_fe

Namespace( void );

u64 registerSymbol( Logger& log, const Ast::IdentifierNode& node,
u64 registerSymbol( Logger& log, const Ast::Identifier& node,
const Ast::CallExpression::TargetType targetType,
const std::size_t arity = 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/analyze/AttributionPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef _LIB_CASMFE_ATTRIBUTION_PASS_H_
#define _LIB_CASMFE_ATTRIBUTION_PASS_H_

#include "../pass/src/Pass.h"
#include "../transform/SourceToAstPass.h"

namespace libcasm_fe
{
Expand Down
8 changes: 6 additions & 2 deletions src/analyze/SymbolResolverPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

#include "SymbolResolverPass.h"

#include "../pass/src/analyze/LoadFilePass.h"

#include "../Logger.h"
#include "../analyze/AttributionPass.h"
#include "../ast/RecursiveVisitor.h"

#include "../casm-ir/src/Builtin.h"
Expand Down Expand Up @@ -153,7 +156,7 @@ void SymbolResolveVisitor::visit( DirectCallExpression& node )
{
const auto targetType = m_symboltable.find( node );

const auto name = node.identifier()->identifier();
const auto name = node.identifier()->identifiers()->back()->identifier();

if( targetType != CallExpression::TargetType::UNKNOWN )
{
Expand All @@ -165,7 +168,8 @@ void SymbolResolveVisitor::visit( DirectCallExpression& node )

if( libcasm_ir::Builtin::available( name, arity ) )
{
m_err += m_symboltable.registerSymbol( m_log, *node.identifier(),
m_err += m_symboltable.registerSymbol( m_log,
*node.identifier()->identifiers()->back(),
CallExpression::TargetType::BUILTIN, arity );

node.setTargetType( CallExpression::TargetType::BUILTIN );
Expand Down
8 changes: 5 additions & 3 deletions src/analyze/SymbolResolverPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#ifndef _LIB_CASMFE_SYMBOL_RESOLVER_PASS_H_
#define _LIB_CASMFE_SYMBOL_RESOLVER_PASS_H_

#include "../analyze/AttributionPass.h"
#include "../pass/src/Pass.h"
#include "../pass/src/PassData.h"

#include "../Namespace.h"
#include "../ast/Specification.h"
Expand All @@ -45,14 +46,14 @@ namespace libcasm_fe

bool run( libpass::PassResult& pr ) override;

class Data : public AttributionPass::Data
class Data : public libpass::PassData
{
public:
using Ptr = std::shared_ptr< Data >;

Data( const Ast::Specification::Ptr& specification,
const Namespace::Ptr& symboltable )
: AttributionPass::Data( specification )
: m_specification( specification )
, m_symboltable( symboltable )
{
}
Expand All @@ -63,6 +64,7 @@ namespace libcasm_fe
}

private:
Ast::Specification::Ptr m_specification;
Namespace::Ptr m_symboltable;
};
};
Expand Down
Loading

0 comments on commit c8ca54f

Please sign in to comment.