| 317 | |
| 318 | |
| 319 | void cSemanticASTVisitor::VisitVariableDefinition(cASTVariableDefinition& node) |
| 320 | { |
| 321 | int var_id = -1; |
| 322 | if (m_cur_symtbl->AddVariable(node.GetName(), node.GetType(), var_id)) node.SetVar(var_id); |
| 323 | else SEMANTIC_ERROR(VARIABLE_REDEFINITION, (const char*)node.GetName()); |
| 324 | |
| 325 | // Process matrix/array dimensions |
| 326 | cASTArgumentList* al = node.GetDimensions(); |
| 327 | if (al) { |
| 328 | if (node.GetType().type == TYPE(MATRIX) || node.GetType().type == TYPE(ARRAY)) { |
| 329 | // Check individual arguments for validity |
| 330 | tListIterator<cASTNode> it = al->Iterator(); |
| 331 | cASTNode* alnode = NULL; |
| 332 | while ((alnode = it.Next())) { |
| 333 | alnode->Accept(*this); |
| 334 | checkCast(alnode->GetType(), TYPEINFO(INT)); |
| 335 | } |
| 336 | |
| 337 | // If empty, warn... |
| 338 | if (al->GetSize() == 0) SEMANTIC_WARNING(NO_DIMENSIONS); |
| 339 | |
| 340 | // If dimensions exceed type limits |
| 341 | if ((node.GetType().type == TYPE(ARRAY) && al->GetSize() > 1) || |
| 342 | (node.GetType().type == TYPE(MATRIX) && al->GetSize() > 2)) { |
| 343 | SEMANTIC_ERROR(TOO_MANY_ARGUMENTS); |
| 344 | SEMANTIC_ERROR(VARIABLE_DIMENSIONS_INVALID, (const char*)node.GetName(), mapType(node.GetType())); |
| 345 | } |
| 346 | } else { |
| 347 | SEMANTIC_ERROR(VARIABLE_DIMENSIONS_INVALID, (const char*)node.GetName(), mapType(node.GetType())); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // Process assignment |
| 352 | cASTNode* ae = node.GetAssignmentExpression(); |
| 353 | if (ae) { |
| 354 | ae->Accept(*this); |
| 355 | checkCast(ae->GetType(), node.GetType()); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | |
| 360 | void cSemanticASTVisitor::VisitVariableDefinitionList(cASTVariableDefinitionList& node) |
nothing calls this directly
no test coverage detected