Пример #1
0
bool CAstStatIf::TypeCheck(CToken *t, string *msg) const
{
  CAstExpression *cond = GetCondition();
  bool result = true;
  
  if (!cond->TypeCheck(t, msg)) return false;
  if (cond->GetType() != CTypeManager::Get()->GetBool()) {
    if (t != NULL) *t = cond->GetToken();
    if (msg != NULL) *msg = "boolean expression expected.";
    return false;
  }

  try {
    CAstStatement *ifBody = GetIfBody();
    CAstStatement *elseBody = GetElseBody();
    
    while (result && (ifBody != NULL)) {
      result = ifBody->TypeCheck(t, msg);
      ifBody = ifBody->GetNext();
    }
    
    while (result && (elseBody != NULL)) {
      result = elseBody->TypeCheck(t, msg);
      elseBody = elseBody->GetNext();
    }
  } catch (...) {
    result = false;
  }
  
  return result;
}
Пример #2
0
bool CAstStatIf::TypeCheck(CToken *t, string *msg) const
{
  if(!_cond->TypeCheck(t, msg)) return false; // Do TypeCheck on condition expression
  if(!_cond->GetType()->IsBoolean()) {
    if(t != NULL) *t = _cond->GetToken();
    if(msg != NULL) *msg = "boolean expression expected.";
    return false;
  }
  bool result = true;
  CAstStatement *s = _ifBody;
  while(result && (s != NULL)) { // Do TypeCheck on all ifBody-statements
    result = s->TypeCheck(t, msg);
    s = s->GetNext();
  }

  s = _elseBody;
  while(result && (s != NULL)) { // Do TypeCheck on all elseBody-statements
    result = s->TypeCheck(t, msg);
    s = s->GetNext();
  }

  return result;
}
Пример #3
0
bool CAstScope::TypeCheck(CToken *t, string *msg) const
{
  bool result = true;

  try {
    CAstStatement *s = _statseq;
    while(result && (s != NULL)) { // do TypeCheck for all statements under this scope
      result = s->TypeCheck(t, msg);
      s = s->GetNext();
    }

    vector<CAstScope*>::const_iterator it = _children.begin();
    while(result && (it != _children.end())) { // do TypeCheck for all scopes under this scope
      result = (*it)->TypeCheck(t, msg);
      it++;
    }
  } catch(...) {
    result = false;
  }

  return result;
}