Skip to content

Commit

Permalink
removed number of enumerator from data type enumeration
Browse files Browse the repository at this point in the history
to eliminate the need for the number of enumerator changed the bit mask
data type array to an unordered map in table constructor, and removed
the equivalent data type function from the table class (was only
returning the input value), removed the call to equivalent data type
function in LET translate function, and added an enum class hash for
converting enum class values to integers (needed for unordered maps
using enum class enumerators)
  • Loading branch information
thunder422 committed Aug 16, 2014
1 parent 2a8e389 commit 8f56e11
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions basic/let.cpp
Expand Up @@ -142,8 +142,8 @@ TokenStatus letTranslate(Translator &translator, Token *commandToken,
while (!done);

// get expression for value to assign
if ((status = translator.getExpression(token,
translator.equivalentDataType(dataType))) != Done_TokenStatus)
if ((status = translator.getExpression(token, dataType))
!= Done_TokenStatus)
{
if (status == Parser_TokenStatus && token->isDataType(None_DataType))
{
Expand Down
15 changes: 13 additions & 2 deletions ibcp.h
Expand Up @@ -25,6 +25,8 @@
#ifndef IBCP_H
#define IBCP_H

#include <cstddef>

// include auto-generated enumerations
#include "autoenums.h"

Expand Down Expand Up @@ -72,8 +74,6 @@ enum DataType
// end of the actual execution data types
// the following data types are used internally for other uses
None_DataType, // indicates none of the above data types
// number of actual execution data types
numberof_DataType = None_DataType,
Number_DataType, // either Double or Integer
Any_DataType, // any type (Double, Integer or String)
sizeof_DataType
Expand All @@ -99,4 +99,15 @@ enum SubCode
};


// provide generic hash for enum class with std::unordered_map
struct EnumClassHash
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
}
};


#endif // IBCP_H
10 changes: 6 additions & 4 deletions table.cpp
Expand Up @@ -22,6 +22,8 @@
//
// 2010-02-18 initial version

#include <unordered_map>

#include <QChar>
#include <QString>

Expand Down Expand Up @@ -1618,10 +1620,10 @@ Table::Table(TableEntry *entry, int entryCount) :
Num_BitMask = Dbl_BitMask | Int_BitMask,
Any_BitMask = Num_BitMask | Str_BitMask
};
int bitMaskDataType[numberof_DataType] = {
Dbl_BitMask, // Double
Int_BitMask, // Integer
Str_BitMask // String
std::unordered_map<DataType, int, EnumClassHash> bitMaskDataType {
{Double_DataType, Dbl_BitMask},
{Integer_DataType, Int_BitMask},
{String_DataType, Str_BitMask}
};

// set expected data type (start with data type of last operand)
Expand Down
14 changes: 0 additions & 14 deletions translator.cpp
Expand Up @@ -1232,20 +1232,6 @@ Token *Translator::doneStackPopErrorToken(void)
}


// function to return equivalent data type for data type
// (really to convert the various string data types to String_DataType)
DataType Translator::equivalentDataType(DataType dataType)
{
static DataType equivalent[numberof_DataType] = {
Double_DataType, // Double
Integer_DataType, // Integer
String_DataType // String
};

return equivalent[dataType];
}


// function to return the token error status for an expected data type
// and reference type
TokenStatus Translator::expectedErrStatus(DataType dataType,
Expand Down
1 change: 0 additions & 1 deletion translator.h
Expand Up @@ -73,7 +73,6 @@ class Translator
Token **first = NULL, Token **last = NULL);

// Public Support Functions
static DataType equivalentDataType(DataType dataType);
static TokenStatus expectedErrStatus(DataType dataType,
Reference reference = None_Reference);

Expand Down

0 comments on commit 8f56e11

Please sign in to comment.