You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
15 years ago
|
|
||
|
#include "locals.hpp"
|
||
|
|
||
|
#include <cassert>
|
||
|
#include <stdexcept>
|
||
|
#include <algorithm>
|
||
|
|
||
|
namespace Compiler
|
||
|
{
|
||
|
const std::vector<std::string>& Locals::get (char type) const
|
||
|
{
|
||
|
switch (type)
|
||
|
{
|
||
|
case 's': return mShorts;
|
||
|
case 'l': return mLongs;
|
||
|
case 'f': return mFloats;
|
||
|
}
|
||
|
|
||
|
throw std::logic_error ("unknown variable type");
|
||
|
}
|
||
|
|
||
|
bool Locals::search (char type, const std::string& name) const
|
||
|
{
|
||
|
const std::vector<std::string>& collection = get (type);
|
||
|
|
||
|
return std::find (collection.begin(), collection.end(), name)!=collection.end();
|
||
|
}
|
||
|
|
||
|
std::vector<std::string>& Locals::get (char type)
|
||
|
{
|
||
|
switch (type)
|
||
|
{
|
||
|
case 's': return mShorts;
|
||
|
case 'l': return mLongs;
|
||
|
case 'f': return mFloats;
|
||
|
}
|
||
|
|
||
|
throw std::logic_error ("unknown variable type");
|
||
|
}
|
||
|
|
||
|
char Locals::getType (const std::string& name) const
|
||
|
{
|
||
|
if (search ('s', name))
|
||
|
return 's';
|
||
|
|
||
|
if (search ('l', name))
|
||
|
return 'l';
|
||
|
|
||
|
if (search ('f', name))
|
||
|
return 'f';
|
||
|
|
||
|
return ' ';
|
||
|
}
|
||
|
|
||
|
void Locals::declare (char type, const std::string& name)
|
||
|
{
|
||
|
get (type).push_back (name);
|
||
|
}
|
||
|
|
||
|
void Locals::clear()
|
||
|
{
|
||
|
get ('s').clear();
|
||
|
get ('l').clear();
|
||
|
get ('f').clear();
|
||
|
}
|
||
|
}
|
||
|
|