Skip to content

Commit

Permalink
table: replaced instance function with static instance
Browse files Browse the repository at this point in the history
removed static instance member and access function
made constructor public for new static table instance (temporary)
removed table references from other classes (not being used)
- in translator, recreator, and program model classes
removed table access function from translator and recreator classes
  • Loading branch information
thunder422 committed Jan 14, 2015
1 parent 240f967 commit 2c22674
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 50 deletions.
3 changes: 1 addition & 2 deletions programmodel.cpp
Expand Up @@ -2,7 +2,7 @@
//
// Interactive BASIC Compiler Project
// File: programmodel.h - program model class source file
// Copyright (C) 2013-2014 Thunder422
// Copyright (C) 2013-2015 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -75,7 +75,6 @@ std::ostream &operator<<(std::ostream &os, ProgramWord word)

ProgramModel::ProgramModel(QObject *parent) :
QAbstractListModel(parent),
m_table(Table::instance()),

m_remDictionary {new Dictionary(CaseSensitive::Yes)},
m_constNumDictionary {new ConstNumDictionary},
Expand Down
4 changes: 1 addition & 3 deletions programmodel.h
Expand Up @@ -2,7 +2,7 @@
//
// Interactive BASIC Compiler Project
// File: programmodel.h - program model class header file
// Copyright (C) 2013-2014 Thunder422
// Copyright (C) 2013-2015 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -205,8 +205,6 @@ class ProgramModel : public QAbstractListModel
void dereference(const LineInfo &lineInfo);
RpnList decode(const LineInfo &lineInfo);

Table &m_table; // reference to the table object

// program code variables
LineInfoList m_lineInfo; // program line information list
ProgramCode m_code; // code for program unit lines
Expand Down
3 changes: 1 addition & 2 deletions recreator.cpp
Expand Up @@ -2,7 +2,7 @@

// Interactive BASIC Compiler Project
// File: recreator.cpp - recreator class source file
// Copyright (C) 2013 Thunder422
// Copyright (C) 2013-2015 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +30,6 @@


Recreator::Recreator() :
m_table(Table::instance()),
m_separator {}
{

Expand Down
9 changes: 1 addition & 8 deletions recreator.h
Expand Up @@ -2,7 +2,7 @@
//
// Interactive BASIC Compiler Project
// File: recreator.h - recreator class header file
// Copyright (C) 2013 Thunder422
// Copyright (C) 2013-2015 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -127,14 +127,7 @@ class Recreator
m_separator = separator;
}

// table instance access function
const Table &table() const
{
return m_table;
}

private:
Table &m_table; // reference to table instance
std::stack<StackItem> m_stack; // holding string stack
char m_separator; // current separator character
std::string m_output; // output string
Expand Down
23 changes: 2 additions & 21 deletions table.cpp
Expand Up @@ -89,7 +89,6 @@ static ExprInfo None_Int_ExprInfo(DataType::None, Operands_Int);
static ExprInfo None_Str_ExprInfo(DataType::None, Operands_Str);


Table *Table::s_instance; // pointer to single table instance
Table::NameMap Table::s_nameToEntry; // name to code table map
std::unordered_map<TableEntry *, Table::EntryVectorArray> Table::s_alternate;
std::unordered_map<TableEntry *, DataType> Table::s_expectedDataType;
Expand Down Expand Up @@ -1287,26 +1286,8 @@ static TableEntry tableEntries[] =
};


// static function to return a refernce to the single table instance
//
// - creates the single table instance with the table entries
// - constructor fails (abort application) if there are table errors

Table &Table::instance(void)
{
if (!s_instance)
try
{
s_instance = new Table(tableEntries, sizeof(tableEntries)
/ sizeof(TableEntry));
}
catch (std::string &error)
{
std::cerr << "Table Bug: " << error << std::endl;
abort();
}
return *s_instance;
}
// TODO temporary table instance
static Table table(tableEntries, sizeof(tableEntries) / sizeof(TableEntry));


// constructor function that initializes the table instance variables
Expand Down
6 changes: 1 addition & 5 deletions table.h
Expand Up @@ -226,8 +226,7 @@ class TableEntry
class Table
{
public:
// function to return a reference to the single table instance
static Table &instance(void);
Table(TableEntry *entry, int entryCount);

// TABLE SPECIFIC FUNCTIONS
static TableEntry *entry(int index);
Expand All @@ -243,16 +242,13 @@ class Table
private:
// these functions private to prevent multiple instances
Table(void) {}
Table(TableEntry *entry, int entryCount);
Table(Table const &) {}
Table &operator=(Table const &) {return *this;}

static void addExpectedDataType(TableEntry *entry, DataType dataType);

void add(TableEntry &entry);

static Table *s_instance; // single instance of table

TableEntry *m_entry; // pointer to table entries

// case insensitive unordered map alias
Expand Down
1 change: 0 additions & 1 deletion translator.cpp
Expand Up @@ -29,7 +29,6 @@


Translator::Translator(const std::string &input) :
m_table(Table::instance()),
m_parse {new Parser {input}}
{

Expand Down
9 changes: 1 addition & 8 deletions translator.h
Expand Up @@ -2,7 +2,7 @@
//
// Interactive BASIC Compiler Project
// File: translator.h - translator class header file
// Copyright (C) 2012-2013 Thunder422
// Copyright (C) 2012-2015 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -65,12 +65,6 @@ class Translator
static Status expectedErrorStatus(DataType dataType,
Reference reference = Reference::None) noexcept;

// Table Access Function
Table &table() const
{
return m_table;
}

// Current Token Access Functions
const TokenPtr &token() const
{
Expand Down Expand Up @@ -167,7 +161,6 @@ class Translator
};
using DoneStack = std::stack<DoneItem>;

Table &m_table; // reference to the table instance
std::unique_ptr<Parser> m_parse; // pointer to parser instance
RpnList m_output; // pointer to RPN list output
HoldStack m_holdStack; // operator/function holding stack
Expand Down

0 comments on commit 2c22674

Please sign in to comment.