Page MenuHomePhorge

type_token.cpp
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

type_token.cpp

/******************************************************************************
*
* File: type_token.cpp
*
* Contents: Runtime part of type token handling.
*
* Copyright 2017
*
* Author: David Juhasz (david.juhasz@tuwien.ac.at)
*
******************************************************************************/
#include "rosa/support/type_token.hpp"
// FIXME: Automatically generate a proper number of cases for the functions
// with a big number of mechanical cases in them below.
namespace rosa {
using namespace token;
bool validToken(const Token T) {
Token T_ = T; // NOLINT
bool Valid = true;
while (Valid && !emptyToken(T_)) {
Valid &= validTypeNumber(typeNumberOfHeadOfToken(T_));
dropHeadOfToken(T_);
}
return Valid;
}
bool emptyToken(const Token T) { return static_cast<token_t>(T) == 0; }
size_t lengthOfToken(const Token T) {
Token T_ = T; // NOLINT
size_t N = 0;
while (!emptyToken(T_)) {
++N;
dropHeadOfToken(T_);
}
return N;
}
size_t sizeOfValuesOfToken(const Token T) {
ASSERT(validToken(T));
Token T_ = T; // NOLINT
size_t S = 0;
while (!emptyToken(T_)) {
S += sizeOfHeadOfToken(T_);
dropHeadOfToken(T_);
}
return S;
}
#define SIZECASE(N) \
{ \
case N: \
return TypeForNumber<static_cast<TypeNumber>(N)>::Size; \
}
size_t sizeOfHeadOfToken(const Token T) {
ASSERT(!emptyToken(T) && validToken(T));
switch (static_cast<type_nr_t>(typeNumberOfHeadOfToken(T))) {
default: {
// Should never come here when T is valid and the case-list below covers
// BuiltinTypes.
ROSA_CRITICAL("unknown type number");
}
SIZECASE(1);
SIZECASE(2);
SIZECASE(3);
SIZECASE(4);
SIZECASE(5);
SIZECASE(6);
SIZECASE(7);
SIZECASE(8);
SIZECASE(9);
SIZECASE(10);
SIZECASE(11);
SIZECASE(12);
SIZECASE(13);
SIZECASE(14);
SIZECASE(15);
}
}
#define NAMECASE(N) \
{ \
case N: \
return TypeForNumber<static_cast<TypeNumber>(N)>::Name; \
}
const char *nameOfHeadOfToken(const Token T) {
ASSERT(!emptyToken(T) && validToken(T));
switch (static_cast<type_nr_t>(typeNumberOfHeadOfToken(T))) {
default: {
// Should never come here when T is valid and the case-list below covers
// BuiltinTypes.
ROSA_CRITICAL("unknown type number");
}
NAMECASE(1);
NAMECASE(2);
NAMECASE(3);
NAMECASE(4);
NAMECASE(5);
NAMECASE(6);
NAMECASE(7);
NAMECASE(8);
NAMECASE(9);
NAMECASE(10);
NAMECASE(11);
NAMECASE(12);
NAMECASE(13);
NAMECASE(14);
NAMECASE(15);
}
}
void dropHeadOfToken(Token &T) {
T = static_cast<Token>(static_cast<token_t>(T) >> RepresentationBits);
}
void dropNOfToken(Token &T, const size_t N) {
T = static_cast<Token>(static_cast<token_t>(T) >> (N * RepresentationBits));
}
} // End namespace rosa

File Metadata

Mime Type
text/x-c++
Expires
Sun, Mar 1, 6:03 PM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
287609
Default Alt Text
type_token.cpp (3 KB)

Event Timeline