-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCQEnum_Constant.cpp
90 lines (77 loc) · 2.63 KB
/
CQEnum_Constant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "CQEnum_Pch.hpp"
#include "CQEnum.hpp"
namespace CQSL { namespace CQEnum {
void ConstInfoList::ParseFrom(InputSrc& srcFile)
{
static const char* const pszExpectedErr = "Expected constant definition or end of constants";
//
// We are looking for const, constexpr, or external const lines, or the end
// of the constants block.
//
std::string strType;
std::vector<std::string> vTokens;
while (true)
{
srcFile.GetIdToken(pszExpectedErr, strType);
if (strType == "EndConstants")
{
break;
}
ConstInfo cinfoNew;
if ((strType == "Const") || (strType == "ConstExpr") || (strType == "ExtConst"))
{
if (strType == "Const")
{
cinfoNew.m_eType = EConstTypes::Const;
}
else if (strType == "ConstExpr")
{
cinfoNew.m_eType = EConstTypes::ConstExpr;
}
else if (strType == "ExtConst")
{
cinfoNew.m_eType = EConstTypes::ExtConst;
}
else
{
strType = "'";
strType.append(strType );
strType.append("' is not a valid constant type");
srcFile.ThrowParseErr(strType);
}
// Have to see an equal sign next
srcFile.CheckEqualSign();
//
// Then we have a set of three comma separated tokens, which are name, type,
// and value.
//
srcFile.GetCommaSepValues(vTokens);
if (vTokens.size() != 3)
{
srcFile.ThrowParseErr("A constant definition is a comma separated name, type and value");
}
// Make sure the name is unique
if (m_sNameDupCheck.find(vTokens.at(0)) == m_sNameDupCheck.end())
{
cinfoNew.m_strName = std::move(vTokens.at(0));
cinfoNew.m_strType = std::move(vTokens.at(1));
cinfoNew.m_strValue = std::move(vTokens.at(2));
// Add this guy's name to the dup check list and then add to the const list
m_sNameDupCheck.insert(cinfoNew.m_strName);
m_vConstList.push_back(std::move(cinfoNew));
}
else
{
std::string strErrMsg("Constant name '");
strErrMsg.append(vTokens.at(0));
strErrMsg.append("' is already used");
srcFile.ThrowParseErr(strErrMsg);
}
}
else
{
srcFile.ThrowParseErr(pszExpectedErr);
}
}
}
}};