コード例 #1
0
ファイル: check_scope.cpp プロジェクト: Arctem/bake
/**
 * Check for scoping issues in classes
 */
void typecheck::CheckScope::visit(typecheck::ClassNode* cls) {
  checkClass(cls);

  /* Forward visitor to children */
  for(auto method_kv : cls->getMethods()) {
    method_kv.second->accept(this);
  }
}
コード例 #2
0
/***************************************************************************//*
* @par Description:
* This function is called by the readRecords function and is used as a hub
* for all the error checking that will take place. It calls individual 
* functions for checking the Name, Address, City, State, ZipCode, Birth Date, 
* License Date, Expiration Date, Class, and Call Sign.
*
*
* @param[in] record - a structure that holds a record and its contents.
* @param[in] errors - a boolean array that holds what errors have been found.
*
*
******************************************************************************/
void checkRecord ( Record *record, bool errors[] )
{
    checkName ( record, errors );           //Working
    checkAddress ( record, errors );        //Working
    checkCity ( record, errors );           //Working
    checkState ( record, errors );          //Working
    checkZipCode ( record, errors );        //Working
    checkBirthDate ( record, errors );      //Working
    checkLicenseDate ( record, errors );    //Working
    checkExpirationDate ( record, errors ); //Working
    checkClass ( record, errors );          //Working
    checkCallSign ( record, errors );       //Working
}
コード例 #3
0
    void check(const char code[], Settings::PlatformType platform = Settings::Unspecified) {
        // Clear the error buffer..
        errout.str("");

        settings.platform(platform);

        // Tokenize..
        Tokenizer tokenizer(&settings, this);
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.simplifyTokenList2();

        // Check for unused private functions..
        CheckClass checkClass(&tokenizer, &settings, this);
        checkClass.privateFunctions();
    }
コード例 #4
0
    void check(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.simplifyTokenList();

        // Clear the error buffer..
        errout.str("");

        // Check for unused private functions..
        Settings settings;
        settings._checkCodingStyle = true;
        CheckClass checkClass(&tokenizer, &settings, this);
        checkClass.privateFunctions();
    }
コード例 #5
0
    void check(const char code[]) {
        // Clear the error buffer..
        errout.str("");

        Settings settings;
        settings.addEnabled("style");

        // Tokenize..
        Tokenizer tokenizer(&settings, this);
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.simplifyTokenList2();

        // Check for unused private functions..
        CheckClass checkClass(&tokenizer, &settings, this);
        checkClass.privateFunctions();
    }
コード例 #6
0
ファイル: stMath.c プロジェクト: cran/splusTimeDate
/**********************************************************************
 * C Code Documentation ************************************************
 **********************************************************************
   NAME time_sum

   DESCRIPTION  Sum a time span or time object.
   To be called from R as 
   \\
   {\tt 
   .Call("time_sum", time_vec, na_rm, cum)
   }
   where TIMECLASS is replaced by the name of the time or time
   span class.  Normally only time spans are summed, but a time
   object can be summed to calculate mean.

   ARGUMENTS
      IARG  time_vec    The R time or time span vector object
      IARG  na_rm       T to remove NAs
      IARG  cum         T to do a cumulative sum vector, F for sum

   RETURN If cum is T, na_rm is ignored and this function returns a 
   vector of the same type as the input whose elements are the 
   cumulative sum of the inputs through the corresponding input element.  
   If the jth element is NA, then all subsequent elements of the return
   will be NA and a warning will be generated. If cum is F, this
   function returns a length 1 vector of the same type as the input, 
   containing the sum of all the elements.  If na_rm is False, any
   NA in the input will generate an NA return value.

   ALGORITHM  The sums are calculated through addition, along with
   the adjust_time or adjust_span function. 
   No special time zones or formats are put on the returned object.

   EXCEPTIONR 

   NOTE 

**********************************************************************/
SEXP time_sum( SEXP time_vec, SEXP na_rm, SEXP cum )
{

  SEXP ret;
  Sint *in_days, *in_ms, *out_days, *out_ms, *rm_na, *in_cum;
  Sint i, lng, is_span, tmplng, tmp;

  /* get the desired parts of the time object */

  if( !time_get_pieces( time_vec, NULL, &in_days, &in_ms, &lng, NULL, 
			NULL, NULL ))
    error( "Invalid time argument in C function time_sum" );

  /* get na_rm and cum */
  PROTECT(na_rm = AS_LOGICAL(na_rm));
  if( length(na_rm) < 1L){
    UNPROTECT(3);
    error( "Problem extracting data from second argument in C function time_sum" );
  }
  rm_na = (Sint *) LOGICAL(na_rm);

  PROTECT(cum = AS_LOGICAL(cum));
  if( length(cum) < 1L){
    UNPROTECT(4);
    error( "Problem extracting data from third argument in C function time_sum" );
  }
  in_cum = (Sint *) LOGICAL(cum);

  /* create output time or time span object */

  is_span = 0;
  if( checkClass( time_vec, IS_TIME_CLASS, 1L ))
    PROTECT(ret = time_create_new( *in_cum ? lng : 1, &out_days, &out_ms ));
  else if( checkClass( time_vec, IS_TSPAN_CLASS, 1L ))
  {
    is_span = 1;
    PROTECT(ret = tspan_create_new( *in_cum ? lng : 1, &out_days, &out_ms ));
  }
  else{
    UNPROTECT(4);
    error( "Unknown class on first argument in C function time_sum" );
  }

  if( !out_days || !out_ms || !ret ){
    UNPROTECT(5);
    error( "Could not create return object in C function time_sum" );
  }	

  out_days[0] = out_ms[0] = 0;

  /* go through input and find sum */

  for( i = 0; i < lng; i++ )
  {
    /* check for NA */
    if(	 in_days[i] ==NA_INTEGER || 
	 in_ms[i] ==NA_INTEGER)
    {
      if( !*in_cum && *rm_na ) /* ignore NA */
	continue;
      else /* NA causes output to be NA */
      {
	if( *in_cum ) {
	  for( ; i < lng; i++ ) /* fill in all the rest */
	  {
	    out_days[i] = NA_INTEGER;
	    out_ms[i] = NA_INTEGER;
	  }
	  warning( "Found NA value in cumsum" );
	}
	else /* make the sum NA */
	{
	  out_days[0] = NA_INTEGER;
	  out_ms[0] = NA_INTEGER;
	}

	UNPROTECT(5);
	return( ret );
      }
    }

    /* add this value in */

    if( *in_cum && ( i >= 1 ))
    {
      out_days[i] = out_days[i-1] + in_days[i];
      out_ms[i] = out_ms[i-1] + in_ms[i];
      if( is_span )
	tmp = adjust_span( &(out_days[i]), &(out_ms[i] ));
      else
	tmp = adjust_time( &(out_days[i]), &(out_ms[i] ));
    } else {
      out_days[0] += in_days[i];
      out_ms[0] += in_ms[i];
      if( is_span )
	tmp = adjust_span( &(out_days[0]), &(out_ms[0] ));
      else
	tmp = adjust_time( &(out_days[0]), &(out_ms[0] ));
    }

    if( !tmp )
    {
	  out_days[0] = NA_INTEGER;
	  out_ms[0] = NA_INTEGER;
    }
  }

  UNPROTECT(5); //3+2 from time_get_pieces
  return ret;
}
コード例 #7
0
ファイル: stMath.c プロジェクト: cran/splusTimeDate
/**********************************************************************
 * C Code Documentation ************************************************
 **********************************************************************
   NAME time_range

   DESCRIPTION  Find the range of a time or time span.
   To be called from R as 
   \\
   {\tt 
   .Call("time_range", time_vec, na_rm)
   }
   where TIMECLASS is replaced by the name of the time or time
   span class.

   ARGUMENTS
      IARG  time_vec    The R time or time span vector object
      IARG  na_rm       T to remove NAs

   RETURN Returns a length 2 time or time span vector (same as passed 
   in class) containing the minimum and maximum times or time spans.

   ALGORITHM  If na_rm is False and there are NAs, this function will
   return NA for the min and max.  Otherwise, it will find the minimum
   and maximum time or time span in the passed in vector, and return
   them in a newly created time object.
   No special time zones or formats are put on the returned object.


   EXCEPTIONS 

   NOTE 

**********************************************************************/
SEXP time_range( SEXP time_vec, SEXP na_rm )
{

  SEXP ret;
  Sint *in_days, *in_ms, *out_days, *out_ms, *rm_na;
  Sint i, lng, initialized, tmplng;

  /* get the desired parts of the time object */

  if( !time_get_pieces( time_vec, NULL, &in_days, &in_ms, &lng, NULL, 
			NULL, NULL ))
    error( "Invalid time argument in C function time_range" );

  /* get na_rm */
  PROTECT(na_rm = AS_LOGICAL(na_rm));
  if( length(na_rm) < 1L){
    UNPROTECT(3);
    error( "Problem extracting data from second argument in C function time_range" );
  }
  rm_na = (Sint *) LOGICAL(na_rm);

  /* create output time or time span object */
  
  if( checkClass( time_vec, IS_TIME_CLASS, 1L ))
    PROTECT(ret = time_create_new( 2, &out_days, &out_ms ));
  else if( checkClass( time_vec, IS_TSPAN_CLASS, 1L ))
    PROTECT(ret = tspan_create_new( 2, &out_days, &out_ms ));
    else {
      UNPROTECT(3);
      error( "Unknown class on first argument in C function time_range" );
    }

  if( !out_days || !out_ms || !ret ){
    UNPROTECT(4);
    error( "Could not create return object in C function time_range" );
  }

  /* go through input and find_range */
  initialized = 0;

  for( i = 0; i < lng; i++ )
  {
    /* check for NA */
    if(	 in_days[i] ==NA_INTEGER || 
	 in_ms[i] ==NA_INTEGER)
    {
      if( *rm_na ) /* ignore NA */
	continue;
      else /* NA causes output to be NA */
      {
	out_days[0] = NA_INTEGER;
	out_ms[0] = NA_INTEGER;
	out_days[1] = NA_INTEGER;
	out_ms[1] = NA_INTEGER;

	return( ret );
      }
    }

    /* if we haven't put anything into return vector yet, put this value in */
    if( !initialized )
    {
      out_days[0] = out_days[1] = in_days[i];
      out_ms[0] = out_ms[1] = in_ms[i];
      initialized = 1;
      continue;
    }

    /* check to see if we're bigger or smaller than current max/min */
    if(( in_days[i] > out_days[1] ) || 
       (( in_days[i] == out_days[1] ) && ( in_ms[i] > out_ms[1] )))
    {
      out_days[1] = in_days[i];
      out_ms[1] = in_ms[i];
    }

    if(( in_days[i] < out_days[0] ) || 
       (( in_days[i] == out_days[0] ) && ( in_ms[i] < out_ms[0] )))
    {
      out_days[0] = in_days[i];
      out_ms[0] = in_ms[i];
    }
  }

  if( !initialized ) /* didn't find anything in the vector */
  {
    out_days[0] = NA_INTEGER;
    out_ms[0] = NA_INTEGER;
    out_days[1] = NA_INTEGER;
    out_ms[1] = NA_INTEGER;
  }

  UNPROTECT(4); //2+2 from time_get_pieces
  return ret;
}
コード例 #8
0
ファイル: stMath.c プロジェクト: cran/splusTimeDate
/**********************************************************************
 * C Code Documentation ************************************************
 **********************************************************************
   NAME time_num_op

   DESCRIPTION  Perform an arithmetic operation between a time or
   time span and a numeric.  Supported operations are "+", "-", 
   "*", and "/".    To be called from R as 
   \\
   {\tt 
   .Call("time_num_op", time_vec, num_vec, op)
   }
   where TIMECLASS is replaced by the name of the time or time
   span class.

   ARGUMENTS
      IARG  time_vec    The R time or time span vector object
      IARG  num_vec     The numeric vector object
      IARG  op          Character string giving the operation

   RETURN Returns a time or time span vector (same as passed in class)
   that is the result of time_vec op num_vec.

   ALGORITHM  Addition and subtraction are performed by combining the integer 
   part of the numeric with the julian days of the time and the fractional 
   part of the numeric (converted from fraction of a day to milliseconds)
   to the milliseconds of the time object.  Multiplication and division
   are performed by converting the time object to a numeric with its
   integer part the number of days and fractional part the fraction of
   the day (found by the ms_to_fraction function), multiplying or dividing, 
   and then converting back. 
   No special time zones or formats are put on the returned object.
   If one of the two vectors has a length that is a multiple of the other,
   the shorter one is repeated.

   EXCEPTIONS 

   NOTE See also: time_time_add, time_rel_add

**********************************************************************/
SEXP time_num_op( SEXP time_vec, SEXP num_vec, SEXP op )
{

  SEXP ret;
  double *in_nums, tmpdbl;
  Sint *in_days, *in_ms, *out_days, *out_ms, add_sign;
  Sint i, lng1, lng2, lng, ind1, ind2, is_span, is_ok, tmp;
  const char *in_op;

  /* get the desired parts of the time object */

  if( !time_get_pieces( time_vec, NULL, &in_days, &in_ms, &lng1, NULL, 
			NULL, NULL ))
    error( "Invalid time argument in C function time_num_op" );

  /* extract other input data */
  PROTECT( num_vec = (SEXP) AS_NUMERIC(num_vec) );
  if( (lng2 = length(num_vec)) < 1L){
    UNPROTECT(3);
    error( "Problem extracting numeric argument in C function time_num_op" );
  }
  in_nums = REAL(num_vec);

  if(lng1 && lng2 && ( lng1 % lng2 ) && ( lng2 % lng1 )){
    UNPROTECT(3);
    error( "Length of longer operand is not a multiple of length of shorter in C function time_num_op" );
  }

  if( !isString(op) || length(op) < 1L){
    UNPROTECT(3);
    error( "Problem extracting operation argument in C function time_num_op" ); 
  }
  if( length(op) > 1L )
    warning( "Using only the first string in operation argument in C function time_num_op" );
  in_op = CHAR(STRING_ELT(op, 0));

  if(( *in_op != '*' ) && ( *in_op != '+' ) && ( *in_op != '-' ) && 
     ( *in_op != '/' )){
    UNPROTECT(3);
    error( "Unknown operator in C function time_num_op" );    
  }

  /* create output time or time span object */
  if( !lng1 || !lng2 )
    lng = 0;
  else if( lng2 > lng1 )
    lng = lng2;
  else
    lng = lng1;
  
  is_span = 1;
  if( checkClass( time_vec, IS_TIME_CLASS, 1L ))
  {
    is_span = 0;
    PROTECT(ret = time_create_new( lng, &out_days, &out_ms ));
  }
  else if( checkClass( time_vec, IS_TSPAN_CLASS, 1L )){
    PROTECT(ret = tspan_create_new( lng, &out_days, &out_ms ));
  } else {
    UNPROTECT(3);
    error( "Unknown class on first argument in C function time_num_op" );
  }

  if( !out_days || !out_ms || !ret ){
    UNPROTECT(4);
    error( "Could not create return object in C function time_num_op" );
  }

  /* go through input and perform operation */
  for( i = 0; i < lng; i++ )
  {
    ind1 = i % lng1;
    ind2 = i % lng2;

    /* check for NA */
    if(	 in_days[ind1] == NA_INTEGER || 
	 in_ms[ind1] == NA_INTEGER ||
	ISNA( in_nums[ind2]))
    {
      out_days[i] = NA_INTEGER;
      out_ms[i] = NA_INTEGER;
      continue;
    }

    /* operate and adjust output */
    add_sign = 1;
    is_ok = 1;
    switch( *in_op )
    {
    case '-':
      add_sign = -1;
    /*LINTED: Meant to fall through here */
    case '+':
      /* add/subtract integer part to days and fractional part to ms */
      out_days[i] = in_days[ind1] + add_sign * (Sint) floor( in_nums[ind2] );
      is_ok = ms_from_fraction( in_nums[ ind2 ] - floor( in_nums[ind2] ), 
			&(out_ms[i]));
      out_ms[i] = in_ms[ind1] + add_sign * out_ms[i];
      break;

    case '*':
      /* convert time to numeric, multiply, convert back */
      if( in_ms[ind1] > 0 )
	is_ok = ms_to_fraction( in_ms[ind1], &tmpdbl );
      else
      {
	is_ok = ms_to_fraction( - in_ms[ind1], &tmpdbl );
	tmpdbl = -tmpdbl;
      }
      tmpdbl = ( tmpdbl + in_days[ind1] ) * in_nums[ind2];
      out_days[i] = (Sint) floor( tmpdbl );
      is_ok = is_ok && ms_from_fraction( tmpdbl - out_days[i], &out_ms[i] );
      break;

    case '/':
      /* convert time to numeric, divide, convert back */
      if( in_ms[ind1] > 0 )
	is_ok = ms_to_fraction( in_ms[ind1], &tmpdbl );
      else
      {
	is_ok = ms_to_fraction( - in_ms[ind1], &tmpdbl );
	tmpdbl = -tmpdbl;
      }
      if( in_nums[ind2] == 0 )
	is_ok = 0;
      else
	tmpdbl = ( tmpdbl + in_days[ind1] ) / in_nums[ind2];
      out_days[i] = (Sint) floor( tmpdbl );
      is_ok = is_ok && ms_from_fraction( tmpdbl - out_days[i], &out_ms[i] );
      break;

    default:
      is_ok = 0;
    }

    if( !is_ok )
    {
      out_days[i] = NA_INTEGER;
      out_ms[i] = NA_INTEGER;
      continue;
    }

    if( is_span )
      tmp = adjust_span( &(out_days[i]), &(out_ms[i] ));
    else
      tmp = adjust_time( &(out_days[i]), &(out_ms[i] ));

    if( !tmp )
    {
      out_days[i] = NA_INTEGER;
      out_ms[i] = NA_INTEGER;
      continue;
    }

  }

  UNPROTECT(4); //2+2 from time_get_pieces
  return ret;
}