void FindBadConstructsConsumer::CountType(const Type* type,
                                          int* trivial_member,
                                          int* non_trivial_member,
                                          int* templated_non_trivial_member) {
  switch (type->getTypeClass()) {
    case Type::Record: {
      // Simplifying; the whole class isn't trivial if the dtor is, but
      // we use this as a signal about complexity.
      if (TypeHasNonTrivialDtor(type))
        (*trivial_member)++;
      else
        (*non_trivial_member)++;
      break;
    }
    case Type::TemplateSpecialization: {
      TemplateName name =
          dyn_cast<TemplateSpecializationType>(type)->getTemplateName();
      bool whitelisted_template = false;

      // HACK: I'm at a loss about how to get the syntax checker to get
      // whether a template is exterened or not. For the first pass here,
      // just do retarded string comparisons.
      if (TemplateDecl* decl = name.getAsTemplateDecl()) {
        std::string base_name = decl->getNameAsString();
        if (base_name == "basic_string")
          whitelisted_template = true;
      }

      if (whitelisted_template)
        (*non_trivial_member)++;
      else
        (*templated_non_trivial_member)++;
      break;
    }
    case Type::Elaborated: {
      CountType(dyn_cast<ElaboratedType>(type)->getNamedType().getTypePtr(),
                trivial_member,
                non_trivial_member,
                templated_non_trivial_member);
      break;
    }
    case Type::Typedef: {
      while (const TypedefType* TT = dyn_cast<TypedefType>(type)) {
        type = TT->getDecl()->getUnderlyingType().getTypePtr();
      }
      CountType(type,
                trivial_member,
                non_trivial_member,
                templated_non_trivial_member);
      break;
    }
    default: {
      // Stupid assumption: anything we see that isn't the above is one of
      // the 20 integer types.
      (*trivial_member)++;
      break;
    }
  }
}
u32 NandTitle::SetType(u32 upper)
{
	currentType = upper;
	currentIndex = 0;

	return CountType(upper);
}
void FindBadConstructsConsumer::CheckCtorDtorWeight(
    SourceLocation record_location,
    CXXRecordDecl* record) {
  // We don't handle anonymous structs. If this record doesn't have a
  // name, it's of the form:
  //
  // struct {
  //   ...
  // } name_;
  if (record->getIdentifier() == NULL)
    return;

  // Count the number of templated base classes as a feature of whether the
  // destructor can be inlined.
  int templated_base_classes = 0;
  for (CXXRecordDecl::base_class_const_iterator it = record->bases_begin();
       it != record->bases_end();
       ++it) {
    if (it->getTypeSourceInfo()->getTypeLoc().getTypeLocClass() ==
        TypeLoc::TemplateSpecialization) {
      ++templated_base_classes;
    }
  }

  // Count the number of trivial and non-trivial member variables.
  int trivial_member = 0;
  int non_trivial_member = 0;
  int templated_non_trivial_member = 0;
  for (RecordDecl::field_iterator it = record->field_begin();
       it != record->field_end();
       ++it) {
    CountType(it->getType().getTypePtr(),
              &trivial_member,
              &non_trivial_member,
              &templated_non_trivial_member);
  }

  // Check to see if we need to ban inlined/synthesized constructors. Note
  // that the cutoffs here are kind of arbitrary. Scores over 10 break.
  int dtor_score = 0;
  // Deriving from a templated base class shouldn't be enough to trigger
  // the ctor warning, but if you do *anything* else, it should.
  //
  // TODO(erg): This is motivated by templated base classes that don't have
  // any data members. Somehow detect when templated base classes have data
  // members and treat them differently.
  dtor_score += templated_base_classes * 9;
  // Instantiating a template is an insta-hit.
  dtor_score += templated_non_trivial_member * 10;
  // The fourth normal class member should trigger the warning.
  dtor_score += non_trivial_member * 3;

  int ctor_score = dtor_score;
  // You should be able to have 9 ints before we warn you.
  ctor_score += trivial_member;

  if (ctor_score >= 10) {
    if (!record->hasUserDeclaredConstructor()) {
      emitWarning(record_location,
                  "Complex class/struct needs an explicit out-of-line "
                  "constructor.");
    } else {
      // Iterate across all the constructors in this file and yell if we
      // find one that tries to be inline.
      for (CXXRecordDecl::ctor_iterator it = record->ctor_begin();
           it != record->ctor_end();
           ++it) {
        if (it->hasInlineBody()) {
          if (it->isCopyConstructor() &&
              !record->hasUserDeclaredCopyConstructor()) {
            emitWarning(record_location,
                        "Complex class/struct needs an explicit out-of-line "
                        "copy constructor.");
          } else {
            emitWarning(it->getInnerLocStart(),
                        "Complex constructor has an inlined body.");
          }
        }
      }
    }
  }

  // The destructor side is equivalent except that we don't check for
  // trivial members; 20 ints don't need a destructor.
  if (dtor_score >= 10 && !record->hasTrivialDestructor()) {
    if (!record->hasUserDeclaredDestructor()) {
      emitWarning(record_location,
                  "Complex class/struct needs an explicit out-of-line "
                  "destructor.");
    } else if (CXXDestructorDecl* dtor = record->getDestructor()) {
      if (dtor->hasInlineBody()) {
        emitWarning(dtor->getInnerLocStart(),
                    "Complex destructor has an inline body.");
      }
    }
  }
}
Esempio n. 4
0
BOOL MacroAnyLoadCommands(LPLIST lpPacketList)
/***********************************************************************/
{
return(CountType(lpPacketList, CT_LOAD) > 0);
}
Esempio n. 5
0
BOOL MacroAnyLoadCommands(LPTSTR lpFileName)
/***********************************************************************/
{
return(CountType(lpFileName, CT_LOAD) > 0);
}
Esempio n. 6
0
BOOL PlayMacro(LPCMDLIST lpCmdList, LPTSTR lpFileName, int nRepeat,
				BOOL fSequenceAll, LPLIST lpMacroList, HWND hParent,
				int PhotoCDResOverride, LPTSTR lpMacroName)
/***********************************************************************/
{
LPIMAGE lpImage;
LPCMDLIST lpNewList;
int nActivates, iCount;
ITEMID idCommand;
STRING szString, szAppName;
BOOL fError;
BOOL fSequence, fCmdSequence, fCopyPackets;
LIST MacroList;
LPCMDPKT lpCmdPkt, lpNextPkt;
MACROSETUP Setup;
COMMAND_TYPE CommandType;
HWND hDlg = NULL;

lpAbortProc = NULL;
if (!hParent)
	hParent = PictPubApp.Get_hWndAstral();

// see if we need to copy our packets
fCopyPackets = nRepeat > 1;

if (!lpMacroList)
	{
	// read in the entire macro file for faster processing
	if (!ReadMacro(lpFileName, &MacroList))
		return(FALSE);
	lpMacroList = &MacroList;
	}

// count the number of activates in the macro file
// because it affects sequencing
nActivates = CountType(lpMacroList, CT_ACTIVATE);

// turn of macro play mode and tell the world
MacroMode = MM_PLAY;
if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) )
	{
	if ( AstralStrEx( IDS_MACROPLAY, szString, sizeof(szString) ) )
		{
		lstrcat( szAppName, szString );
		SetWindowText( PictPubApp.Get_hWndAstral(), szAppName );
		}
	}

// reset untitled number so that if a macro is played it
// can deal with untitled images the same
Control.UntitledNo = 0;

// If no command list passed in to work on (Macro Batch Mode)
// then get command list for active image
if (!lpCmdList)
	{
	if (lpImage = GetActiveImage())
		lpCmdList = lpImage->lpCmdList;
	else
		lpCmdList = NULL;
	}

// See if the macro contains any low res loads and
// if so ask to user if he'd like to convert them
// to hi res loads and if so do the convert
if (FindCommand(lpMacroList, IDS_CMD_LOWRESLOAD))
	if (AstralAffirm(IDS_CONVERTLOWRES))
		if (!ConvertLowResLoad(lpMacroList))
			{
			DestroyPacketList(lpMacroList);
			return(FALSE);
			}

// disable all mouse and keyboard input during macro play
EnableWindow(hParent, FALSE);

// if not in a threading environment and caller wants us
// to display a progress dialog, then set it up and do it
if (!Control.UseThreading)
	{
	iCount = ListGetCount(lpMacroList) - nActivates;
	iCount *= nRepeat;
	Setup.iTotal = iCount;
	Setup.idDialog = IDD_MACRO_STATUS;
	Setup.lpFileName = NULL;
    hDlg = AstralDlgParam( YES, PictPubApp.GetResourceHandle(), hParent, IDD_MACRO_STATUS,
						DlgMacroStatusProc,
						(LPARAM)(LPVOID)&Setup );
	if (hDlg)
		{
		if (lpMacroName)
			{
			STRING szString;

			GetWindowText(hDlg, szString, sizeof(szString));
			lstrcat(szString, _T(" - "));
			lstrcat(szString, lpMacroName);
			SetWindowText(hDlg, szString);
			}

		UpdateWindow(hDlg);
		}
	}

// Repeat macro nRepeat number of times
fError = FALSE;
while (--nRepeat >= 0 && !fError)
	{
	if (lpAbortProc && (*lpAbortProc)())
		break;
	// back to beginning of macro file
	lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList);

	// initialize sequencing
	fSequence = fSequenceAll;

	while (!fError && lpNextPkt)
		{
		if (lpAbortProc && (*lpAbortProc)())
			{
			fError = TRUE;
			break;
			}
		// get the packet to work on
		if (fCopyPackets)
			{
			lpCmdPkt = CopyPacket(lpNextPkt);
			if (!lpCmdPkt)
				{
				fError = TRUE;
				break;
				}
			}
		else
			{
			ListUnlink(lpMacroList, lpNextPkt);
			lpCmdPkt = lpNextPkt;
			}

		// get command id and parms for this command
		idCommand = lpCmdPkt->idCommand;

		// Find out whether this command requires sequencing
		// set it here, so command can change it if needed before
		// we actually set fSequence
		fCmdSequence = GetCommandSequence(idCommand);
		CommandType = GetCommandType(idCommand);

		// Handle the different types of commands
		switch (CommandType)
			{
			case CT_LOAD:
				// create new command list for load
				lpNewList = CreateCommandList();
				if (lpNewList)
					{
					ListAddTail(&lpNewList->PacketList, lpCmdPkt);

					// if we already have a command list containing commands,
					// kick off the execution of those commands before we
					// switch to the new command list
					if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList))
						{
						PlaybackCommands(lpCmdList);
						// if some command in the command list affects
						// sequencing force the whole command list to
						// be processed
						if (fSequence)
							{
							FlushCommands(lpCmdList);
							fSequence = fSequenceAll;
							}
						}
					// setup new command list for us to work with
					lpCmdList = lpNewList;
					lpCmdList->PhotoCDResOverride = PhotoCDResOverride;

					// If there are any activates in this macro make sure a
					// command that creates an image processes immediately
					if (nActivates)
						{
						PlaybackCommands(lpCmdList);
						FlushCommands(lpCmdList);
						fSequence = fSequenceAll;
						fCmdSequence = NO; // already sequenced
						}
					}
				break;

			case CT_COPY:
				// Make sure we have a command list to work with
				if (!lpCmdList)
					{
				 	Message(IDS_NOIMAGETOWORKON);
					fError = TRUE;
					break;
					}
				// Just add this command to the command list
				ListAddTail(&lpCmdList->PacketList, lpCmdPkt);

				// If there are any activates in this macro make sure a
				// command that creates an image processes immediately
				if (nActivates)
					{
					PlaybackCommands(lpCmdList);
					FlushCommands(lpCmdList);
					fSequence = fSequenceAll;
					fCmdSequence = NO; // already sequenced
					}
				break;

			case CT_SAVE:
			case CT_EDIT:
			case CT_MASK:
			case CT_MODE:
			case CT_EDITUNDO:
			case CT_MASKUNDO:
			case CT_EDITOBJ:
			case CT_CLOSE:
				// Make sure we have a command list to work with
				if (!lpCmdList)
					{
				 	Message(IDS_NOIMAGETOWORKON);
					fError = TRUE;
					break;
					}
				if (CommandType == CT_SAVE)
					{
					PlaybackCommands(lpCmdList);
					if (!lpCmdList->ThreadData.lpImage)
						{
				 		Message(IDS_NOIMAGETOWORKON);
						fError = TRUE;
						break;
						}
					}

				// Just add this command to the command list
				ListAddTail(&lpCmdList->PacketList, lpCmdPkt);
				if (CommandType != CT_CLOSE)
					break;

			case CT_ACTIVATE:
				// Program or commands that affect window activation
				// are processed here
				switch (idCommand)
					{
					case IDS_CMD_CLOSE:
					case IDS_CMD_ACTIVATEWINDOW:
						{
						// if we already have a command list containing commands,
						// kick of the execution of those commands before we
						// switch to the new command list
						if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList))
							{
							PlaybackCommands(lpCmdList);
							// if some command in the command list affects
							// sequencing force the whole command list to
							// be processed
							if (fSequence)
								{
								FlushCommands(lpCmdList);
								fSequence = fSequenceAll;
								}
							}
						// if this was a close command, then wack the command list pointer
						if (idCommand == IDS_CMD_CLOSE)
							lpCmdList = NULL;
						else
							{
							// now process the activate and get a new command list
							lpNewList = ProgActivateWindow(
									(LPACTIVATEWINDOW_PARMS)lpCmdPkt->lpParms);
							// setup the new command list if we got one
							if (lpNewList)
								lpCmdList = lpNewList;
							else
								{
								CommandError(idCommand);
								fError = TRUE;
								}
							// activate don't go through command processing
							// so we have to free it up here
							FreeUpPacket(lpCmdPkt);
							}
						}
					break;

					default:
					break;
					}
				break;

			default:
				break;
			}
		// if command just handled requires sequencing
		// set sequencing flag
		if (fCmdSequence)
			fSequence = YES;
		if (fCopyPackets)
			// get next command packet in macro list
			lpNextPkt = (LPCMDPKT)ListGetNext(lpNextPkt);
		else
			// head of list will be next one if we're not copying
			lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList);
		}
	}
// get rid of macro list
DestroyPacketList(lpMacroList);

// if we already have a command list containing commands,
// kick off the execution of those commands
if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList))
	{
	PlaybackCommands(lpCmdList);
	if (fSequenceAll)
		FlushCommands(lpCmdList);
	}

// turn off the macro mode
EnableWindow(hParent, TRUE);
if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) )
	SetWindowText( PictPubApp.Get_hWndAstral(), szAppName );
// if we have a progress dialog, nuke it
if (hDlg)
	AstralDlgEnd(hDlg, TRUE);
// if we are display the macro status for another modal dialog 
// make sure the main app stuff is still disabled
if (hParent != PictPubApp.Get_hWndAstral())
	{
	EnableOverlappedWindow( PictPubApp.Get_hWndAstral(), FALSE );
	EnableWindow(PictPubApp.Get_hWndAstral(), FALSE);
	}
MacroMode = MM_NONE;
return(TRUE);
}