Exemple #1
0
void TypeDeduction::Visit(MemberExpression* node)
{
    //TODO: Finish it.
    node->GetContainer()->Accept(this);
    StructType *structType = dynamic_cast<StructType *>(node->GetContainer()->GetTag<Type>("Type"));
    if (structType == NULL)
    {
        
        CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "Member expression requires struct type.");        
    }
    
    
    std::vector<Declaration *> * fileds = structType->GetFieldList();
    for (std::vector<Declaration *>::iterator it = fileds->begin(); it != fileds->end(); ++it)
    {
        Declaration *decl = *it;
        if (decl->GetName() == node->GetFieldName())
        {
            Type *fieldType = decl->GetType();
            node->SetTag<Type>("Type", fieldType);
            return;
        }
    }
    
    
    CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "%s is not a member of type %s", node->GetFieldName().c_str(), structType->ToString().c_str());        

    
    abort();
}
Exemple #2
0
void
Logger::GUIStartLogger(const NMEAInfo& gps_info,
                    const ComputerSettings& settings,
                       const ProtectedTaskManager *protected_task_manager,
                    bool noAsk)
{
  if (IsLoggerActive() || gps_info.gps.replay)
    return;

  OrderedTask* task = protected_task_manager != nullptr
    ? protected_task_manager->TaskClone()
    : nullptr;
  const Declaration decl(settings.logger, settings.plane, task);

  if (task) {
    delete task;

    if (!noAsk) {
      TCHAR TaskMessage[1024];
      _tcscpy(TaskMessage, _T("Start Logger With Declaration\r\n"));
      
      if (decl.Size()) {
        for (unsigned i = 0; i< decl.Size(); ++i) {
          _tcscat(TaskMessage, decl.GetName(i));
          _tcscat(TaskMessage, _T("\r\n"));
        }
      } else {
        _tcscat(TaskMessage, _T("None"));
      }
      
      if (ShowMessageBox(TaskMessage, _("Start Logger"),
                      MB_YESNO | MB_ICONQUESTION) != IDYES)
        return;
    }
  }

  if (!LoggerClearFreeSpace(gps_info.date_time_utc.year)) {
    ShowMessageBox(_("Logger inactive, insufficient storage!"),
                _("Logger Error"), MB_OK| MB_ICONERROR);
    LogFormat("Logger not started: Insufficient Storage");
    return;
  }

  const ScopeExclusiveLock protect(lock);
  logger.StartLogger(gps_info, settings.logger, asset_number, decl);
}
Exemple #3
0
// TODO: fix scope so only gui things can start it
void
LoggerImpl::StartLogger(const NMEAInfo &gps_info,
                        const LoggerSettings &settings,
                        const TCHAR *asset_number, const Declaration &decl)
{
  if (!settings.logger_id.empty())
    asset_number = settings.logger_id.c_str();

  // chars must be legal in file names
  char logger_id[4];
  unsigned asset_length = _tcslen(asset_number);
  for (unsigned i = 0; i < 3; i++)
    logger_id[i] = i < asset_length && IsAlphaNumericASCII(asset_number[i]) ?
                   asset_number[i] : _T('A');
  logger_id[3] = _T('\0');

  if (!StartLogger(gps_info, settings, logger_id))
    return;

  simulator = gps_info.location_available && !gps_info.gps.real;
  writer->WriteHeader(gps_info.date_time_utc, decl.pilot_name,
                      decl.aircraft_type, decl.aircraft_registration,
                      decl.competition_id,
                      logger_id, GetGPSDeviceName(), simulator);

  if (decl.Size()) {
    BrokenDateTime FirstDateTime = !pre_takeoff_buffer.empty()
      ? pre_takeoff_buffer.peek().date_time_utc
      : gps_info.date_time_utc;
    writer->StartDeclaration(FirstDateTime, decl.Size());

    for (unsigned i = 0; i< decl.Size(); ++i)
      writer->AddDeclaration(decl.GetLocation(i), decl.GetName(i));

    writer->EndDeclaration();
  }
}
Exemple #4
0
/**
 * Loads LX task structure from XCSoar task structure
 * @param decl  The declaration
 */
static bool
LoadTask(LX::Declaration &lxDevice_Declaration, const Declaration &declaration)
{
    if (declaration.Size() > 10)
        return false;

    if (declaration.Size() < 2)
        return false;

    memset((void*)lxDevice_Declaration.unknown1, 0,
           sizeof(lxDevice_Declaration.unknown1));

    BrokenDate DeclDate;
    DeclDate.day = 1;
    DeclDate.month = 1;
    DeclDate.year = 2010;

    if (DeclDate.day > 0 && DeclDate.day < 32
            && DeclDate.month > 0 && DeclDate.month < 13) {
        lxDevice_Declaration.dayinput = (unsigned char)DeclDate.day;
        lxDevice_Declaration.monthinput = (unsigned char)DeclDate.month;
        int iCentury = DeclDate.year / 100; // Todo: if no gps fix, use system time
        iCentury *= 100;
        lxDevice_Declaration.yearinput = (unsigned char)(DeclDate.year - iCentury);
    }
    else {
        lxDevice_Declaration.dayinput = (unsigned char)1;
        lxDevice_Declaration.monthinput = (unsigned char)1;
        lxDevice_Declaration.yearinput = (unsigned char)10;
    }
    lxDevice_Declaration.dayuser = lxDevice_Declaration.dayinput;
    lxDevice_Declaration.monthuser = lxDevice_Declaration.monthinput;
    lxDevice_Declaration.yearuser = lxDevice_Declaration.yearinput;
    lxDevice_Declaration.taskid = 0;
    lxDevice_Declaration.numtps = declaration.Size();

    for (unsigned i = 0; i < LX::NUMTPS; i++) {
        if (i == 0) { // takeoff
            lxDevice_Declaration.tptypes[i] = 3;
            lxDevice_Declaration.Latitudes[i] = 0;
            lxDevice_Declaration.Longitudes[i] = 0;
            copy_space_padded(lxDevice_Declaration.WaypointNames[i], _T("TAKEOFF"),
                              sizeof(lxDevice_Declaration.WaypointNames[i]));


        } else if (i <= declaration.Size()) {
            lxDevice_Declaration.tptypes[i] = 1;
            lxDevice_Declaration.Longitudes[i] =
                AngleToLX(declaration.GetLocation(i - 1).longitude);
            lxDevice_Declaration.Latitudes[i] =
                AngleToLX(declaration.GetLocation(i - 1).latitude);
            copy_space_padded(lxDevice_Declaration.WaypointNames[i],
                              declaration.GetName(i - 1),
                              sizeof(lxDevice_Declaration.WaypointNames[i]));

        } else if (i == declaration.Size() + 1) { // landing
            lxDevice_Declaration.tptypes[i] = 2;
            lxDevice_Declaration.Longitudes[i] = 0;
            lxDevice_Declaration.Latitudes[i] = 0;
            copy_space_padded(lxDevice_Declaration.WaypointNames[i], _T("LANDING"),
                              sizeof(lxDevice_Declaration.WaypointNames[i]));

        } else { // unused
            lxDevice_Declaration.tptypes[i] = 0;
            lxDevice_Declaration.Longitudes[i] = 0;
            lxDevice_Declaration.Latitudes[i] = 0;
            memset((void*)lxDevice_Declaration.WaypointNames[i], 0, 9);
        }
    }

    return true;
}