7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-20 18:31:43 +00:00

Introduce new KI_FALLTHROUGH macro

Annotate purposeful fallthroughs in switch statements with the
KI_FALLTHROUGH macro.
This commit is contained in:
Ian McInerney 2020-04-25 00:44:09 +01:00
parent ff67d6300d
commit 99dcadf7e6
37 changed files with 145 additions and 39 deletions

View File

@ -68,6 +68,8 @@
#include "cbvh_pbrt.h"
#include "../../../3d_fastmath.h"
#include <macros.h>
#include <boost/range/algorithm/nth_element.hpp>
#include <boost/range/algorithm/partition.hpp>
#include <cstdlib>
@ -560,6 +562,7 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
// Intentionally fall through to SPLITMETHOD::EQUAL_COUNTS since prims
// with large overlapping bounding boxes may fail to partition
KI_FALLTHROUGH;
case SPLITMETHOD::EQUALCOUNTS:
{

View File

@ -147,10 +147,12 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils, E
case EDA_DATA_TYPE::VOLUME:
value = To_User_Unit( aUnits, value, aUseMils );
// Fall through to continue computation
KI_FALLTHROUGH;
case EDA_DATA_TYPE::AREA:
value = To_User_Unit( aUnits, value, aUseMils );
// Fall through to continue computation
KI_FALLTHROUGH;
case EDA_DATA_TYPE::DISTANCE:
value = To_User_Unit( aUnits, value, aUseMils );

View File

@ -28,6 +28,7 @@
#include <project.h>
#include <common.h>
#include <reporter.h>
#include <macros.h>
#include <mutex>
#include <wx/process.h>
#include <wx/config.h>
@ -548,7 +549,7 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject )
break;
}
// else fall through
KI_FALLTHROUGH;
default:
strResult += str_n;

View File

@ -27,6 +27,7 @@
#include <confirm.h>
#include <eda_draw_frame.h>
#include <kiface_i.h>
#include <macros.h>
#include <settings/app_settings.h>
#include <class_draw_panel_gal.h>
@ -386,6 +387,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
default:
wxASSERT( false );
KI_FALLTHROUGH;
// warn about unhandled GAL canvas type, but continue with the fallback option
case GAL_TYPE_NONE:

View File

@ -177,6 +177,7 @@ wxString convertLegacyVariableRefs( const wxString& aTextbase )
case '8': msg += wxT( "${COMMENT8}" ); break;
case '9': msg += wxT( "${COMMENT9}" ); break;
}
break;
default:
break;

View File

@ -819,7 +819,8 @@ void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
case 900:
case 2700: // rotation of 90 degrees or 270 swaps sizes
std::swap( size.x, size.y );
// Intentionally fall through
KI_FALLTHROUGH;
case 0:
case 1800:
if( trace_mode == SKETCH )

View File

@ -324,8 +324,8 @@ void PSLIKE_PLOTTER::fputsPostscriptString(FILE *fout, const wxString& txt)
case ')':
case '\\':
putc( '\\', fout );
KI_FALLTHROUGH;
// FALLTHRU
default:
putc( ch, fout );
break;

View File

@ -23,6 +23,7 @@
*/
#include "lib_tree.h"
#include <macros.h>
#include <wxdataviewctrl_helpers.h>
#include <wx/artprov.h>
#include <wx/sizer.h>
@ -365,6 +366,7 @@ void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
break;
}
// Intentionally fall through, so the selected component will be treated as the selected one
KI_FALLTHROUGH;
default:
aKeyStroke.Skip(); // Any other key: pass on to search box directly.

View File

@ -28,6 +28,7 @@
#include <common.h>
#include <erc.h>
#include <macros.h>
#include <sch_bus_entry.h>
#include <sch_component.h>
#include <sch_edit_frame.h>
@ -207,7 +208,10 @@ std::vector<SCH_ITEM*> CONNECTION_SUBGRAPH::GetBusLabels() const
// Only consider bus vectors
if( label_conn->Type() == CONNECTION_TYPE::BUS )
labels.push_back( item );
break;
}
default: break;
}
}

View File

@ -25,6 +25,7 @@
#include <netlist_object.h>
#include <class_library.h>
#include <macros.h>
#include <sch_junction.h>
#include <sch_component.h>
#include <sch_line.h>
@ -115,6 +116,7 @@ bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets )
break;
// Intentionally fall through if there is no net assigned
KI_FALLTHROUGH;
case NETLIST_ITEM::SEGMENT:
// Test connections point to point type without bus.
@ -165,6 +167,7 @@ bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets )
break;
// Intentionally fall through if there is no bus assigned
KI_FALLTHROUGH;
case NETLIST_ITEM::BUS:
// Control type connections point to point mode bus

View File

@ -44,6 +44,7 @@
#include <lib_polyline.h>
#include <lib_rectangle.h>
#include <lib_text.h>
#include <macros.h>
#include <project.h>
#include <sch_bus_entry.h>
#include <sch_component.h>
@ -229,6 +230,7 @@ static COMPONENT_ORIENTATION_T kiCadComponentRotation( float eagleDegrees )
{
default:
wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
KI_FALLTHROUGH;
case 0:
return CMP_ORIENT_0;
@ -1701,8 +1703,8 @@ LIB_PIN* SCH_EAGLE_PLUGIN::loadPin(
{
default:
wxASSERT_MSG( false, wxString::Format( "Unhandled orientation (%d degrees)", roti ) );
KI_FALLTHROUGH;
// fall through
case 0:
pin->SetOrientation( 'R' );
break;

View File

@ -836,6 +836,8 @@ SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy )
if( item->HitTest( aPosition, aAccuracy ) )
return (SCH_TEXT*) item;
break;
default:
;
}

View File

@ -40,6 +40,7 @@
#include <msgpanel.h>
#include <gal/stroke_font.h>
#include <bitmaps.h>
#include <macros.h>
#include <math/util.h> // for KiROUND
#include <kiway.h>
#include <sch_text.h>
@ -357,7 +358,7 @@ bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
case BUS_START_END:
m_connectionType = CONNECTION_TYPE::BUS;
// fall through
KI_FALLTHROUGH;
case WIRE_START_END:
{

View File

@ -29,6 +29,7 @@
#include <am_param.h>
#include <am_primitive.h>
#include <macros.h>
extern int ReadInt( char*& text, bool aSkipSeparator = true );
extern double ReadDouble( char*& text, bool aSkipSeparator = true );
@ -184,7 +185,9 @@ bool AM_PARAM::ReadParam( char*& aText )
if( !found ) // happens when a string starts by ',' before any param
break; // just skip this separator
// fall through
KI_FALLTHROUGH;
case '\n':
case '\r':
case 0: // EOL

View File

@ -234,7 +234,7 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int aCommand, char* aBuff,
msg.Printf( _("GERBER file \"%s\" may not display as intended." ),
m_FileName.ToAscii() );
AddMessageToList( msg );
// Fallthrough
KI_FALLTHROUGH;
case 'L': // No Leading 0
m_NoTrailingZeros = false;

View File

@ -1,8 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
* Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see CHANGELOG.TXT for contributors.
* Copyright (C) 1992-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -37,6 +38,57 @@
#include <set>
#include <memory> // std::shared_ptr
#if defined( __has_attribute )
#define KI_HAS_ATTRIBUTE( x ) __has_attribute( x )
#else
#define KI_HAS_ATTRIBUTE( x ) 0
#endif
// Based on the declaration inside the LLVM source code
#if defined( __cplusplus ) && defined( __has_cpp_attribute )
#define KI_HAS_CPP_ATTRIBUTE( x ) __has_cpp_attribute( x )
#else
#define KI_HAS_CPP_ATTRIBUTE( x ) 0
#endif
/**
* The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely
* fallthrough from one to the next. It must be followed by a ";".
*
* Sample code:
* switch( a )
* {
* case 1:
* // Some code
* KI_FALLTHROUGH;
*
* case 2:
* // More code
* break;
* }
*/
#if __cplusplus >= 201703L
// C++ 17 includes this macro on all compilers
#define KI_FALLTHROUGH [[fallthrough]]
#elif KI_HAS_CPP_ATTRIBUTE( clang::fallthrough )
// Clang provides this attribute to silence the "-Wimplicit-fallthrough" warning
#define KI_FALLTHROUGH [[clang::fallthrough]]
#elif KI_HAS_CPP_ATTRIBUTE( gnu::fallthrough )
// GNU-specific C++ attribute to sliencing the warning
#define KI_FALLTHROUGH [[gnu::fallthrough]]
#elif defined( __GNUC__ ) && __GNUC__ >= 7
// GCC 7+ includes the "-Wimplicit-fallthrough" warning, and this attribute to silence it
#define KI_FALLTHROUGH __attribute__ ((fallthrough))
#else
// In every other case, don't do anything
#define KI_FALLTHROUGH ( ( void ) 0 )
#endif
/**
* Macro TO_UTF8
* converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.

View File

@ -125,7 +125,8 @@ void DIALOG_NEW_DATAITEM::initDlg()
case WS_DATA_ITEM::WS_BITMAP:
case WS_DATA_ITEM::WS_POLYPOLYGON:
m_textCtrlText->Enable( false );
// fall through
KI_FALLTHROUGH;
case WS_DATA_ITEM::WS_TEXT:
m_textCtrlEndX->Enable( false );
m_textCtrlEndY->Enable( false );

View File

@ -172,7 +172,8 @@ void EDGE_MODULE::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
{
case S_ARC:
SetAngle( -GetAngle() );
//Fall through
KI_FALLTHROUGH;
default:
case S_SEGMENT:
case S_CURVE:
@ -236,7 +237,8 @@ void EDGE_MODULE::Mirror( wxPoint aCentre, bool aMirrorAroundXAxis )
{
case S_ARC:
SetAngle( -GetAngle() );
//Fall through
KI_FALLTHROUGH;
default:
case S_CURVE:
case S_SEGMENT:

View File

@ -298,8 +298,7 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
case PCB_MODULE_TEXT_T:
// Only user text can be added this way.
assert( static_cast<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS );
// no break
KI_FALLTHROUGH;
case PCB_MODULE_EDGE_T:
if( aMode == ADD_MODE::APPEND )
@ -347,8 +346,7 @@ void MODULE::Remove( BOARD_ITEM* aBoardItem )
wxCHECK_RET(
static_cast<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS,
"Please report this bug: Invalid remove operation on required text" );
// no break
KI_FALLTHROUGH;
case PCB_MODULE_EDGE_T:
for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it )
@ -828,7 +826,8 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR inspector, void* testData, const KICAD_T
if( result == SEARCH_RESULT::QUIT )
break;
// Intentionally fall through since m_Drawings can hold TYPETEXTMODULE also
// Intentionally fall through since m_Drawings can hold TYPETEXTMODULE also
KI_FALLTHROUGH;
case PCB_MODULE_EDGE_T:
result = IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, p );
@ -949,7 +948,8 @@ void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
default:
wxASSERT_MSG( false, "Illegal layer" ); // do you really have modules placed on other layers?
// pass through
KI_FALLTHROUGH;
case F_Cu:
aLayers[1] = LAYER_MOD_FR;
break;

View File

@ -32,6 +32,7 @@
#include <class_marker_pcb.h>
#include <class_zone.h>
#include <class_drawsegment.h>
#include <macros.h>
#include <math/util.h> // for KiROUND
@ -277,7 +278,10 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
case PCB_MODULE_ZONE_AREA_T:
module = static_cast<MODULE*>( item->GetParent() );
// Fall through
// Fallthrough to get the zone as well
KI_FALLTHROUGH;
case PCB_ZONE_AREA_T:
zone = static_cast<ZONE_CONTAINER*>( item );
break;

View File

@ -381,6 +381,8 @@ void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
if( importFormat >= 0 )
importFile( path, importFormat );
break;
}
// many many others.

View File

@ -325,7 +325,7 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate()
// Check angle of arc.
if( m_angle.GetValue() == 0 )
error_msgs.Add( _( "The arc angle cannot be zero." ) );
// Fall through.
KI_FALLTHROUGH;
case S_CIRCLE:
// Check radius.

View File

@ -34,6 +34,7 @@
#include <dialog_pad_properties.h>
#include <gal/graphics_abstraction_layer.h>
#include <html_messagebox.h>
#include <macros.h>
#include <pcb_base_frame.h>
#include <pcb_painter.h>
#include <pcbnew.h>
@ -1110,7 +1111,8 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK()
if( padlayers_mask[B_Paste] || padlayers_mask[F_Paste] )
error_msgs.Add( _( "Error: Connector pads are not on the solder paste layer\n"
"Use SMD pads instead" ) );
// Intentionally fall through
KI_FALLTHROUGH;
case PAD_ATTRIB_SMD: // SMD and Connector pads (One external copper layer only)
{
LSET innerlayers_mask = padlayers_mask & LSET::InternalCuMask();

View File

@ -41,6 +41,7 @@
#include <tool/tool_manager.h>
#include <tools/zone_filler_tool.h>
#include <math/util.h> // for KiROUND
#include <macros.h>
DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aParent ) :
@ -402,6 +403,8 @@ void DIALOG_PLOT::SetPlotFormat( wxCommandEvent& event )
{
case PLOT_FORMAT::SVG:
m_PlotOptionsSizer->Show( m_svgOptionsSizer );
KI_FALLTHROUGH;
case PLOT_FORMAT::PDF:
m_drillShapeOpt->Enable( true );
m_plotModeOpt->Enable( false );

View File

@ -25,6 +25,7 @@
#include <dialog_push_pad_properties.h>
#include <class_pad.h>
#include <macros.h>
#include <pcb_edit_frame.h>
@ -72,8 +73,7 @@ void DIALOG_PUSH_PAD_PROPERTIES::PadPropertiesAccept( wxCommandEvent& event )
{
case wxID_APPLY:
returncode = 1;
// Fall through
KI_FALLTHROUGH;
case wxID_OK:
m_Pad_Shape_Filter = m_Pad_Shape_Filter_CB->GetValue();

Some files were not shown because too many files have changed in this diff Show More