32 #ifndef _QORE_QOREPARSEHASHNODE_H
34 #define _QORE_QOREPARSEHASHNODE_H
44 class QoreParseHashNode :
public ParseNode {
46 typedef std::vector<QoreValue> nvec_t;
47 typedef std::vector<const QoreTypeInfo*> tvec_t;
49 DLLLOCAL QoreParseHashNode(
const QoreProgramLocation* loc,
bool curly =
false) : ParseNode(loc,
NT_PARSE_HASH, true), curly(curly) {
53 DLLLOCAL QoreParseHashNode(
const QoreParseHashNode& old,
ExceptionSink* xsink) :
58 typeInfo(old.typeInfo),
60 keys.reserve(old.keys.size());
61 values.reserve(old.values.size());
62 for (
auto& i : old.keys) {
63 keys.push_back(copy_value_and_resolve_lvar_refs(i, xsink));
67 for (
auto& i : old.values) {
68 values.push_back(copy_value_and_resolve_lvar_refs(i, xsink));
74 DLLLOCAL ~QoreParseHashNode() {
75 assert(keys.size() == values.size());
76 for (
size_t i = 0; i < keys.size(); ++i) {
77 keys[i].discard(
nullptr);
78 values[i].discard(
nullptr);
89 if (!n || n.isValue()) {
91 checkDup(loc, key->c_str());
95 DLLLOCAL
size_t size() {
101 assert(keys.size() == 1);
109 assert(values.size() == 1);
115 DLLLOCAL
void setCurly() {
120 DLLLOCAL
bool isCurly()
const {
124 DLLLOCAL
void finalizeBlock(
int start_line,
int end_line);
126 DLLLOCAL
const nvec_t& getKeys()
const{
130 DLLLOCAL
const nvec_t& getValues()
const {
134 DLLLOCAL
const tvec_t& getValueTypes()
const {
142 DLLLOCAL
virtual const char* getTypeName()
const;
144 DLLLOCAL
virtual void parseInitImpl(
QoreValue& val, LocalVar *oflag,
int pflag,
int &lvids,
const QoreTypeInfo *&returnTypeInfo);
147 typedef std::map<std::string, bool> kmap_t;
148 typedef std::vector<const QoreProgramLocation*> lvec_t;
155 const QoreTypeInfo* vtype =
nullptr;
157 const QoreTypeInfo* typeInfo =
nullptr;
161 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
165 DLLLOCAL
static void doDuplicateWarning(
const QoreProgramLocation* newoc1,
const char* key);
167 DLLLOCAL
void checkDup(
const QoreProgramLocation* loc,
const char* key) {
168 std::string kstr(key);
169 kmap_t::iterator i = kmap.lower_bound(kstr);
170 if (i == kmap.end() || i->first != kstr)
171 kmap.insert(i, kmap_t::value_type(kstr,
false));
172 else if (!i->second) {
173 doDuplicateWarning(loc, key);