MCPcopy Create free account
hub / github.com/devosoft/avida / VisitVariableDefinition

Method VisitVariableDefinition

avida-core/source/script/cSemanticASTVisitor.cc:319–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

317
318
319void 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
360void cSemanticASTVisitor::VisitVariableDefinitionList(cASTVariableDefinitionList& node)

Callers

nothing calls this directly

Calls 10

AddVariableMethod · 0.80
GetDimensionsMethod · 0.80
AcceptMethod · 0.80
GetNameMethod · 0.45
GetTypeMethod · 0.45
SetVarMethod · 0.45
IteratorMethod · 0.45
NextMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected