| 126 | */ |
| 127 | |
| 128 | AST::Node* getArrayElement(ParserState* pp, string id, int offset, |
| 129 | bool annotation) { |
| 130 | if (offset > 0) { |
| 131 | SymbolEntry e; |
| 132 | if (pp->symbols.get(id,e)) { |
| 133 | switch (e.t) { |
| 134 | case ST_INTVARARRAY: |
| 135 | if (offset > pp->arrays[e.i]) |
| 136 | goto error; |
| 137 | { |
| 138 | std::string n; |
| 139 | if (annotation) { |
| 140 | std::ostringstream oss; |
| 141 | oss << id << "[" << offset << "]"; |
| 142 | n = oss.str(); |
| 143 | } |
| 144 | return new AST::IntVar(pp->arrays[e.i+offset],n); |
| 145 | } |
| 146 | case ST_BOOLVARARRAY: |
| 147 | if (offset > pp->arrays[e.i]) |
| 148 | goto error; |
| 149 | { |
| 150 | std::string n; |
| 151 | if (annotation) { |
| 152 | std::ostringstream oss; |
| 153 | oss << id << "[" << offset << "]"; |
| 154 | n = oss.str(); |
| 155 | } |
| 156 | return new AST::BoolVar(pp->arrays[e.i+offset],n); |
| 157 | } |
| 158 | case ST_SETVARARRAY: |
| 159 | if (offset > pp->arrays[e.i]) |
| 160 | goto error; |
| 161 | { |
| 162 | std::string n; |
| 163 | if (annotation) { |
| 164 | std::ostringstream oss; |
| 165 | oss << id << "[" << offset << "]"; |
| 166 | n = oss.str(); |
| 167 | } |
| 168 | return new AST::SetVar(pp->arrays[e.i+offset],n); |
| 169 | } |
| 170 | case ST_FLOATVARARRAY: |
| 171 | if (offset > pp->arrays[e.i]) |
| 172 | goto error; |
| 173 | { |
| 174 | std::string n; |
| 175 | if (annotation) { |
| 176 | std::ostringstream oss; |
| 177 | oss << id << "[" << offset << "]"; |
| 178 | n = oss.str(); |
| 179 | } |
| 180 | return new AST::FloatVar(pp->arrays[e.i+offset],n); |
| 181 | } |
| 182 | case ST_INTVALARRAY: |
| 183 | if (offset > pp->arrays[e.i]) |
| 184 | goto error; |
| 185 | return new AST::IntLit(pp->arrays[e.i+offset]); |
no test coverage detected