Skip to content

Commit

Permalink
Bit to Binary: renamed all type occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
ppaulweber committed Nov 30, 2017
1 parent ec1dabb commit f27c0c0
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 230 deletions.
4 changes: 2 additions & 2 deletions src/Codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ namespace libcasm_fe
OperatorInvalidOperands = 0x8001

// --------------------------------------------------------- b*** ...
// bit type errors
// binary type errors
,
TypeBitSyntaxError = 0xb000,
TypeBitSizeIsInvalid = 0xb001,
TypeBinarySizeIsInvalid = 0xb001,
TypeBitSizeInvalidExpression = 0xb002

,
Expand Down
10 changes: 5 additions & 5 deletions src/GrammarParser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ END 0 "end of file"
%type <Expression::Ptr> Expression Term Literal
%type <Expressions::Ptr> Terms
%type <TypeCastingExpression::Ptr> TypeCastingExpression
%type <ValueAtom::Ptr> BooleanLiteral StringLiteral BitLiteral IntegerLiteral DecimalLiteral RationalLiteral
%type <ValueAtom::Ptr> BooleanLiteral StringLiteral BinaryLiteral IntegerLiteral DecimalLiteral RationalLiteral
%type <ReferenceAtom::Ptr> ReferenceLiteral
%type <UndefAtom::Ptr> UndefinedLiteral
%type <RangeExpression::Ptr> Range
Expand Down Expand Up @@ -1031,7 +1031,7 @@ Literal
{
$$ = $1;
}
| BitLiteral
| BinaryLiteral
{
$$ = $1;
}
Expand Down Expand Up @@ -1116,12 +1116,12 @@ DecimalLiteral
;


BitLiteral
BinaryLiteral
: BINARY
{
try
{
const auto value = libstdhl::Memory::get< libcasm_ir::BitConstant >( $1, libstdhl::Type::BINARY );
const auto value = libstdhl::Memory::get< libcasm_ir::BinaryConstant >( $1, libstdhl::Type::BINARY );
$$ = Ast::make< ValueAtom >( @$, value );
}
catch( const std::domain_error& e )
Expand All @@ -1133,7 +1133,7 @@ BitLiteral
{
try
{
const auto value = libstdhl::Memory::get< libcasm_ir::BitConstant >( $1, libstdhl::Type::HEXADECIMAL );
const auto value = libstdhl::Memory::get< libcasm_ir::BinaryConstant >( $1, libstdhl::Type::HEXADECIMAL );
$$ = Ast::make< ValueAtom >( @$, value );
}
catch( const std::domain_error& e )
Expand Down
15 changes: 8 additions & 7 deletions src/analyze/TypeCheckPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TypeCheckVisitor::TypeCheckVisitor( libcasm_fe::Logger& log, Namespace& symbolta

static const std::string TYPE_STRING_VOID = "Void";
static const std::string TYPE_STRING_BOOLEAN = "Boolean";
static const std::string TYPE_STRING_BIT = "Bit";
static const std::string TYPE_STRING_BINARY = "Binary";
static const std::string TYPE_STRING_INTEGER = "Integer";
static const std::string TYPE_STRING_STRING = "String";
static const std::string TYPE_STRING_DECIMAL = "Decimal";
Expand Down Expand Up @@ -122,9 +122,9 @@ void TypeCheckVisitor::visit( BasicType& node )
{
node.setType( libstdhl::Memory::get< libcasm_ir::BooleanType >() );
}
else if( name == TYPE_STRING_BIT )
else if( name == TYPE_STRING_BINARY ) // PPA: REMOVE: drop this basic type support, use alias!
{
node.setType( libstdhl::Memory::get< libcasm_ir::BitType >( 1 ) );
node.setType( libstdhl::Memory::get< libcasm_ir::BinaryType >( 1 ) );
}
else if( name == TYPE_STRING_INTEGER )
{
Expand Down Expand Up @@ -306,7 +306,7 @@ void TypeCheckVisitor::visit( FixedSizedType& node )
const auto& name = node.name()->baseName();
auto& expr = *node.size();

if( name == TYPE_STRING_BIT )
if( name == TYPE_STRING_BINARY )
{
if( expr.id() == Node::ID::VALUE_ATOM and expr.type()->isInteger() )
{
Expand All @@ -317,19 +317,20 @@ void TypeCheckVisitor::visit( FixedSizedType& node )

try
{
auto type = libstdhl::Memory::get< libcasm_ir::BitType >( value );
auto type = libstdhl::Memory::get< libcasm_ir::BinaryType >( value );
node.setType( type );
}
catch( const std::domain_error& e )
{
m_log.error( { expr.sourceLocation() }, e.what(), Code::TypeBitSizeIsInvalid );
m_log.error(
{ expr.sourceLocation() }, e.what(), Code::TypeBinarySizeIsInvalid );
}
}
else
{
m_log.error(
{ expr.sourceLocation() },
"unsupported expr for 'Bit' type, constant Integer value "
"unsupported expr for 'Binary' type, constant Integer value "
"expected" );
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/analyze/TypeInferencePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ void TypeInferenceVisitor::visit( TypeCastingExpression& node )
node.setTargetBuiltinId( libcasm_ir::Value::AS_RATIONAL_BUILTIN );
break;
}
case libcasm_ir::Type::Kind::BIT:
case libcasm_ir::Type::Kind::BINARY:
{
node.setTargetBuiltinId( libcasm_ir::Value::AS_BIT_BUILTIN );
node.setTargetBuiltinId( libcasm_ir::Value::AS_BINARY_BUILTIN );
break;
}
case libcasm_ir::Type::Kind::DECIMAL:
Expand Down Expand Up @@ -1227,16 +1227,16 @@ void TypeInferenceVisitor::assignment(
// at run-time
}
else if(
tyLhs.isBit() and tyRhs.isBit() and
static_cast< const libcasm_ir::BitType& >( tyLhs ).bitsize() >=
static_cast< const libcasm_ir::BitType& >( tyRhs ).bitsize() )
tyLhs.isBinary() and tyRhs.isBinary() and
static_cast< const libcasm_ir::BinaryType& >( tyLhs ).bitsize() >=
static_cast< const libcasm_ir::BinaryType& >( tyRhs ).bitsize() )
{
// relaxation: mixed bit types are OK as long as
// relaxation: mixed binary types are OK as long as
// bitsize(lhs) >= bitsize(rhs)
}
else if( tyLhs.isBit() and tyRhs.isInteger() and rhs.id() == Node::ID::VALUE_ATOM )
else if( tyLhs.isBinary() and tyRhs.isInteger() and rhs.id() == Node::ID::VALUE_ATOM )
{
// relaxation: lhs bit and rhs integer are OK as long as rhs is a
// relaxation: lhs binary and rhs integer are OK as long as rhs is a
// integer constant with bitsize(lhs) >= bitsize(rhs)

try
Expand All @@ -1246,7 +1246,7 @@ void TypeInferenceVisitor::assignment(
auto constant =
std::static_pointer_cast< libcasm_ir::IntegerConstant >( valueAtom.value() );

const auto value = libstdhl::Memory::get< libcasm_ir::BitConstant >(
const auto value = libstdhl::Memory::get< libcasm_ir::BinaryConstant >(
lhs.type()->ptr_result(),
static_cast< const libstdhl::Type::Natural& >( constant->value() ) );

Expand Down
10 changes: 5 additions & 5 deletions src/various/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Literal ::= UndefinedLiteral
| IntegerLiteral
| RationalLiteral
| DecimalLiteral
| BitLiteral
| BinaryLiteral
| StringLiteral
| ReferenceLiteral
</code>
Expand Down Expand Up @@ -490,14 +490,14 @@ DecimalLiteral ::= "0[xX][0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]*"
{{page>:grammar:DecimalLiteral&noheader&nofooter}}


===== BitLiteral =====
===== BinaryLiteral =====

<code>
BitLiteral ::= "0[bB][01][01']*[01]*"
| "0[xX][0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]*"
BinaryLiteral ::= "0[bB][01][01']*[01]*"
| "0[xX][0-9a-fA-F][0-9a-fA-F']*[0-9a-fA-F]*"
</code>

{{page>:grammar:BitLiteral&noheader&nofooter}}
{{page>:grammar:BinaryLiteral&noheader&nofooter}}


===== StringLiteral =====
Expand Down
22 changes: 12 additions & 10 deletions src/various/GrammarParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ namespace libcasm_fe
case 126: // IntegerLiteral
case 127: // RationalLiteral
case 128: // DecimalLiteral
case 129: // BitLiteral
case 129: // BinaryLiteral
case 130: // StringLiteral
value.move< ValueAtom::Ptr >( that.value );
break;
Expand Down Expand Up @@ -819,7 +819,7 @@ namespace libcasm_fe
case 126: // IntegerLiteral
case 127: // RationalLiteral
case 128: // DecimalLiteral
case 129: // BitLiteral
case 129: // BinaryLiteral
case 130: // StringLiteral
value.copy< ValueAtom::Ptr >( that.value );
break;
Expand Down Expand Up @@ -1280,7 +1280,7 @@ namespace libcasm_fe
case 126: // IntegerLiteral
case 127: // RationalLiteral
case 128: // DecimalLiteral
case 129: // BitLiteral
case 129: // BinaryLiteral
case 130: // StringLiteral
yylhs.value.build< ValueAtom::Ptr >();
break;
Expand Down Expand Up @@ -2743,9 +2743,10 @@ namespace libcasm_fe
{
try
{
const auto value = libstdhl::Memory::get< libcasm_ir::BitConstant >(
yystack_[ 0 ].value.as< std::string >(),
libstdhl::Type::BINARY );
const auto value =
libstdhl::Memory::get< libcasm_ir::BinaryConstant >(
yystack_[ 0 ].value.as< std::string >(),
libstdhl::Type::BINARY );
yylhs.value.as< ValueAtom::Ptr >() =
Ast::make< ValueAtom >( yylhs.location, value );
}
Expand All @@ -2762,9 +2763,10 @@ namespace libcasm_fe
{
try
{
const auto value = libstdhl::Memory::get< libcasm_ir::BitConstant >(
yystack_[ 0 ].value.as< std::string >(),
libstdhl::Type::HEXADECIMAL );
const auto value =
libstdhl::Memory::get< libcasm_ir::BinaryConstant >(
yystack_[ 0 ].value.as< std::string >(),
libstdhl::Type::HEXADECIMAL );
yylhs.value.as< ValueAtom::Ptr >() =
Ast::make< ValueAtom >( yylhs.location, value );
}
Expand Down Expand Up @@ -4073,7 +4075,7 @@ namespace libcasm_fe
"IntegerLiteral",
"RationalLiteral",
"DecimalLiteral",
"BitLiteral",
"BinaryLiteral",
"StringLiteral",
"ReferenceLiteral",
"Types",
Expand Down
Loading

0 comments on commit f27c0c0

Please sign in to comment.