Files
BlitzNext/compiler/lib/decl.cpp
T

45 lines
801 B
C++
Raw Normal View History

2019-01-18 15:55:51 +01:00
#include "decl.hpp"
#include "type.hpp"
2014-01-31 08:23:00 +13:00
2019-01-19 18:28:07 +01:00
Decl::Decl(const std::string& s, Type* t, int k, ConstType* d) : name(s), type(t), kind(k), defType(d) {}
2019-01-18 17:04:57 +01:00
Decl::~Decl() {}
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
DeclSeq::DeclSeq() {}
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
void Decl::getName(char* buff)
{
int sz = name.size();
memcpy(buff, name.data(), sz);
buff[sz] = 0;
2014-01-31 08:23:00 +13:00
}
2019-01-18 17:04:57 +01:00
DeclSeq::~DeclSeq()
{
for (; decls.size(); decls.pop_back())
delete decls.back();
2014-01-31 08:23:00 +13:00
}
2019-01-19 18:28:07 +01:00
Decl* DeclSeq::findDecl(const std::string& s)
2019-01-18 17:04:57 +01:00
{
2019-01-19 18:28:07 +01:00
std::vector<Decl*>::iterator it;
2019-01-18 17:04:57 +01:00
for (it = decls.begin(); it != decls.end(); ++it) {
if ((*it)->name == s)
return *it;
2014-01-31 08:23:00 +13:00
}
return 0;
}
2019-01-19 18:28:07 +01:00
Decl* DeclSeq::insertDecl(const std::string& s, Type* t, int kind, ConstType* d)
2019-01-18 17:04:57 +01:00
{
if (findDecl(s))
return 0;
decls.push_back(new Decl(s, t, kind, d));
2014-01-31 08:23:00 +13:00
return decls.back();
}
2019-01-19 18:28:07 +01:00
int DeclSeq::size()
{
return decls.size();
}