int main( int argc, char ** argv )
{
// 1. Angle brackets handling bug
// As of now a2, a3 and a4 will be skipped
int a1 = i < 7 ? i : 7;
int a2 = 8;
int a3 = 9;
int a4 = p->data;
int a5 = 8;
// 2. Function pointer decl bug
// As of now a6 will be skipped
int ( *a6 )( int, char ** ) = &main;
// 3. Wrong prototype will be written
// As of now prototype will be ( SomeType ( p )( int ) )
int a7( short ( *p )( int ) );
// 4. DECL_IGNORE bug
// As of now a8 will be skipped
if ( argc > 0 )
return 0;
short a8 = i;
// 5. Local variables support
// As of now all the identifiers below are either reported as prototypes,
// or not recognized at all
// The comments on the right specify which kind of tag should be generated
const char *b1( "uuu" ); //variable
int b2( int ooo, const char* o ); //prototype
int b3( int( 7 ) ); //variable
int c1( a >> ooo ); //variable
int c2( int * h ); //prototype
int c3( std::map<int>( 9 ) ); //variable
int c4( std::map<int> a ); //prototype
int c5( map<int> & a ); //prototype
int c6( ooo & a ); //prototype
int c7( int & a ); //prototype
int c8( map<int> a ); //prototype
int c9( int a ); //prototype
ind d1( a * 2 ); //variable
ind d2( "a" * 2 ); //variable
int d3( *j ); //variable
int f1( SomeType (*p)( int ) ); //prototype
SomeType (*f2)( int o ); //variable
int f3( std::map<int> & a ); //prototype
int g1( SomeType a ); //prototype
// As of now, the signature of h1 will be "( int a = R )",
// 'R' is to be replaced by something clearer to denote a
// string literal
char h1( const char *a = "a" ); //prototype
int h2(); //prototype
char h3( double ); //prototype
int h4( h u ); //prototype
int (*p1)( int o ); //variable
int v4( iii( 'o' ) ); //variable
int v5( iii( o ) ); //variable
int v6( int (*p)( int ) ); //prototype
int v7( 89 ); //variable
int v8( ooo ); //variable
// __ARGS(x) is a compatibility macro which optionally
// expands to x when prototypes are supported, so
// w1 should be parsed as a prototype
int w1 __ARGS (( int a )); //prototype
int w2 (( a - 5 ) / 6 ); //variable
int x1( a.b ); //variable
int x2( a->b ); //variable
int x3( NS::a b ); //prototype
int x4( a ^ b ); //variable
int x5( a ^ 6 ); //variable
int x6( a | b ); //variable
// As of now, x7 is not recognized at all; it should
// give a variable tag but it's tricky to get it
// right because of '&' which suggests a prototype,
// so for now let's just ignore it
//int x7( a & b & c ); //variable
int x8( a & b & 2 ); //variable
int x9( a && b ); //variable
}
开发者ID:Monits,项目名称:ctags,代码行数:89,代码来源:input.cpp
示例8: main
int main()
{
// test if two ints are equal or not
cout << "*** Integers Tests ***" << endl;
int leftInts[4] = { 1, 2, -1, -1 }; // lhs integers used for testing equality
int rightInts[4] = { 1, 4, 1, -1 }; // rhs integers used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "Integers: " << leftInts[a] << " and " << rightInts[a] << " are "
<< (isEqualTo(leftInts[a], rightInts[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
// test if two chars are equal or not
cout << "\n\n*** Chars Tests ***" << endl;
char leftChars[4] = { 'a', 'a', 'c', 'c' }; // lhs chars used for testing equality
char rightChars[4] = { 'a', 'c', 'a', 'c' }; // rhs chars used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "Characters: " << leftChars[a] << " and " << rightChars[a] << " are "
<< (isEqualTo(leftChars[a], rightChars[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
// test if two doubles are equal or not
cout << "\n\n*** Double Tests ***" << endl;
double leftDoubles[4] = { 2.2, 2.2, -2.2, -2.2 }; // lhs integers used for testing equality
double rightDoubles[4] = { 2.2, 2.3, 2.2, -2.2 }; // rhs integers used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "Double numbers: " << leftDoubles[a] << " and " << rightDoubles[a] << " are "
<< (isEqualTo(leftDoubles[a], rightDoubles[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
// test if two Complex objects are equal
cout << "\n\n*** Complex Tests ***" << endl;
Complex a(10, 5); // Complex objects used
Complex a1(10, 5); // for testing equality
cout << "Class objects: " << a << " and " << a1 << " are "
<< (isEqualTo(a, a1) ? "equal" : "\"NOT\" equal");
Complex b(10, 5); // Complex objects used
Complex b1(10, 54); // for testing equality
cout << "\nClass objects: " << b << " and " << b1 << " are "
<< (isEqualTo(b, b1) ? "equal" : "\"NOT\" equal");
Complex c(10, -5); // Complex objects used
Complex c1(10, 5); // for testing equality
cout << "\nClass objects: " << c << " and " << c1 << " are "
<< (isEqualTo(c, c1) ? "equal" : "\"NOT\" equal");
Complex d(-10, -5); // Complex objects used
Complex d1(-10, -5); // for testing equality
cout << "\nClass objects: " << d << " and " << d1 << " are "
<< (isEqualTo(d, d1) ? "equal" : "\"NOT\" equal");
//test if two strings are equal or not
cout << "\n\n\n*** String Tests ***" << endl;
string leftStrings[4] = { "abcdefg", "abcdefg", "-abcdefg", "-abcdefg" }; // lhs chars used for testing equality
string rightStrings[4] = { "abcdefg", "abcdefh", "abcdefg", "-abcdefg" }; // rhs chars used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "String objects: " << leftStrings[a] << " and " << rightStrings[a] << " are "
<< (isEqualTo(leftStrings[a], rightStrings[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
//test if two dates are equal or not
cout << "\n\n*** Date Tests ***";
Date dayA(2, 31, 2016); // create date object
Date dayB(2, 31, 2016); // create date object
cout << "\nDate objects: " << dayA << " and " << dayB << " are "
<< (isEqualTo(dayA, dayB) ? "equal" : "\"NOT\" equal");
Date dayC(-2, 13, 2016); // create date object
Date dayD(2, 14, 2016); // create date object
cout << "\nDate objects: " << dayC << " and " << dayD << " are "
<< (isEqualTo(dayC, dayD) ? "equal" : "\"NOT\" equal");
Date dayE(-2, 13, 2016); // create date object
Date dayF(2, 13, 2016); // create date object
cout << "\nDate objects: " << dayE << " and " << dayF << " are "
<< (isEqualTo(dayE, dayF) ? "equal" : "\"NOT\" equal");
Date dayG(-2, 13, 2016); // create date object
Date dayH(2, 31, 2016); // create date object
cout << "\nDate objects: " << dayG << " and " << dayH << " are "
<< (isEqualTo(dayG, dayH) ? "equal" : "\"NOT\" equal") << '\n';
cout << endl << endl;
return 0;
} // end main
/// The top three entries on the stack are two digits to add and their
/// proported sum mod 10. Transmit Y/N to indicate whether or not the
/// sum is correct. If the sum is not correct, transmit the correct
/// sum. Update the weights to bias future random number selection.
void gradeSum(MorseToken) {
if (2 < symbolStackSize()) {
uint8_t s1(s(1).m2i());
uint8_t s2(s(2).m2i());
uint8_t s0(s(0).toChar());
uint8_t sum((s1 + s2) % 10);
Serial.print(s2);
Serial.print(" ");
Serial.print(s1);
Serial.print(" ");
Serial.print(s0);
Serial.print(" sum: ");
Serial.println(sum);
bool correct(s(0).m2i() == sum);
if (correct) {
txString("Y");
// Decrease the error counts associated with the digits the user
// just added incorrectly, taking care not to underflow.
uint8_t d1(!!digitErr[s1]);
uint8_t d2(!!digitErr[s2]);
digitErr[s1] -= d1;
digitErr[s2] -= d2;
digitErrCount -= (d1 + d2);
Serial.print("Decrementing ");
Serial.print(s1);
Serial.print(". New weight is: ");
Serial.println(digitErr[s1]);
Serial.print("Decrementing ");
Serial.print(s2);
Serial.print(". New weight is: ");
Serial.println(digitErr[s2]);
} else {
// 012345678901
char buffer[] = "N a + b = c";
buffer[3] = s2 + '0';
buffer[7] = s1 + '0';
buffer[11] = sum + '0';
txString(buffer);
// Increase the error counts associated with the digits the user
// just added incorrectly, taking care not to overflow.
uint8_t d1(3 * (digitErr[s1] - 3 < 255));
uint8_t d2(3 * (digitErr[s2] - 3 < 255));
digitErr[s1] += d1;
digitErr[s2] += d2;
digitErrCount += d1 + d2;
Serial.print("Incrementing ");
Serial.print(s1);
Serial.print(". New weight is: ");
Serial.println(digitErr[s1]);
Serial.print("Incrementing ");
Serial.print(s2);
Serial.print(". New weight is: ");
Serial.println(digitErr[s2]);
}
// If the user plays long enough without a reset to saturate two
// of the digits chosen at random, divide all the error counts
// by 2.
if (digitErr[s1] == 255 && digitErr[s2] == 255) {
for (uint8_t i(0); i < 10; ++i) {
digitErr[i] <<= 1;
}
digitErrCount <<= 1;
Serial.println("Halving all weights.");
}
Serial.print("Digit error count is: ");
Serial.println(digitErrCount);
popN(3);
} else {
txError();
}
}
/* Function that returns the ID of the most dangerous neighboring plane and its ZEM */
AU_UAV_ROS::threatContainer AU_UAV_ROS::findGreatestThreat(PlaneObject &plane1, std::map<int, PlaneObject> &planes){
/* Set reference for origin (Northwest corner of the course)*/
AU_UAV_ROS::coordinate origin;
origin.latitude = 32.606573;
origin.longitude = -85.490356;
origin.altitude = 400;
/* Set preliminary plane to avoid as non-existent and most dangerous
ZEM as negative*/
int planeToAvoid = -1;
double mostDangerousZEM = -1;
/* Set the preliminary time-to-go to infinity*/
double minimumTimeToGo = std::numeric_limits<double>::infinity();
/* Declare second plane and ID variable */
PlaneObject plane2;
int ID;
/* Make a position vector representation of the current plane*/
double magnitude2, direction2;
double magnitude = findDistance(origin.latitude, origin.longitude,
plane1.getCurrentLoc().latitude, plane1.getCurrentLoc().longitude);
double direction = findAngle(origin.latitude, origin.longitude,
plane1.getCurrentLoc().latitude, plane1.getCurrentLoc().longitude);
AU_UAV_ROS::mathVector p1(magnitude,direction);
/* Make a heading vector representation of the current plane*/
AU_UAV_ROS::mathVector d1(1.0,toCartesian(plane1.getCurrentBearing()));
/* Declare variables needed for this loop*/
AU_UAV_ROS::mathVector pDiff;
AU_UAV_ROS::mathVector dDiff;
double timeToGo, zeroEffortMiss, distanceBetween, timeToDest;
std::map<int,AU_UAV_ROS::PlaneObject>::iterator it;
for ( it=planes.begin() ; it!= planes.end(); it++ ){
/* Unpacking plane to check*/
ID = (*it).first;
plane2 = (*it).second;
/* If it's not in the Check Zone, check the other plane*/
distanceBetween = plane1.findDistance(plane2);
if (distanceBetween > CHECK_ZONE || plane1.getID() == ID) continue;
else if (distanceBetween < MPS_SPEED) {
planeToAvoid = ID;
mostDangerousZEM = 0;
minimumTimeToGo = 0.1;
break;
}
/* Making a position vector representation of plane2*/
magnitude2 = findDistance(origin.latitude, origin.longitude,
plane2.getCurrentLoc().latitude, plane2.getCurrentLoc().longitude);
direction2 = findAngle(origin.latitude, origin.longitude,
plane2.getCurrentLoc().latitude, plane2.getCurrentLoc().longitude);
AU_UAV_ROS::mathVector p2(magnitude2,direction2);
/* Make a heading vector representation of the current plane*/
AU_UAV_ROS::mathVector d2(1.0,toCartesian(plane2.getCurrentBearing()));
/* Compute Time To Go*/
pDiff = p1-p2;
dDiff = d1-d2;
timeToGo = -1*pDiff.dotProduct(dDiff)/(MPS_SPEED*dDiff.dotProduct(dDiff));
/* Compute Zero Effort Miss*/
zeroEffortMiss = sqrt(pDiff.dotProduct(pDiff) +
2*(MPS_SPEED*timeToGo)*pDiff.dotProduct(dDiff) +
pow(MPS_SPEED*timeToGo,2)*dDiff.dotProduct(dDiff));
/* If the Zero Effort Miss is less than the minimum required
separation, and the time to go is the least so far, then avoid this plane*/
if(zeroEffortMiss <= DANGER_ZEM && timeToGo < minimumTimeToGo && timeToGo > 0){
// If the plane is behind you, don't avoid it
if ( fabs(plane2.findAngle(plane1)*180/PI - toCartesian(plane1.getCurrentBearing())) > 35.0) {
timeToDest = plane1.findDistance(plane1.getDestination().latitude,
plane1.getDestination().longitude) / MPS_SPEED;
/* If you're close to your destination and the other plane isn't
much of a threat, then don't avoid it */
if ( timeToDest < 5.0 && zeroEffortMiss > 3.0*MPS_SPEED ) continue;
planeToAvoid = ID;
mostDangerousZEM = zeroEffortMiss;
minimumTimeToGo = timeToGo;
}
}
}
AU_UAV_ROS::threatContainer greatestThreat;
greatestThreat.planeID = planeToAvoid;
greatestThreat.ZEM = mostDangerousZEM;
greatestThreat.timeToGo = minimumTimeToGo;
return greatestThreat;
}
请发表评论