Compare commits

...

3 Commits

Author SHA1 Message Date
Přemysl Eric Janouch 9dcef6a14f
Make ld_library_find_symbol() easier to read
As well as shorter, strangely.

Symbols may technically exist directly in the root category now.
2021-10-29 01:31:50 +02:00
Přemysl Eric Janouch ee7be81434
Clean up 2021-10-29 00:24:12 +02:00
Přemysl Eric Janouch 0c5c680f62
Get rid of broken vera++, integrate clang-tidy 2021-10-29 00:22:43 +02:00
7 changed files with 72 additions and 92 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "vera++"]
path = vera++
url = https://bitbucket.org/verateam/vera.git

View File

@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 3.10)
project (logdiag VERSION 0.2.1 LANGUAGES C)
# Options
option (OPTION_USE_VERA "Use vera++ for source code style checks" OFF)
option (OPTION_CLANG_TIDY "Enable use of clang-tidy" OFF)
option (OPTION_NOINSTALL "For developers only--work without installing" OFF)
option (OPTION_GTKDOC "For developers only--enable use of gtk-doc" OFF)
option (BUILD_TESTING "Build tests" OFF)
@ -266,42 +266,38 @@ find_package (CppCheck)
GENERATE_CPPCHECK (SOURCES liblogdiag src tests ENABLE_IDS all
TARGET_NAME ${PROJECT_NAME}_cppcheck INCLUDES ${PROJECT_BINARY_DIR})
if (OPTION_USE_VERA)
# Force this off, we don't need it
option (VERA_LUA "" OFF)
# Various clang-based diagnostics, loads of fake positives and spam
if (OPTION_CLANG_TIDY)
set (clang_tidy_checks
clang-analyzer-* bugprone-* misc-* readability-* performance-*
-bugprone-reserved-identifier # GObject
-performance-no-int-to-ptr # GObject
-bugprone-narrowing-conversions
-bugprone-macro-parentheses # too coarse-grained
-readability-braces-around-statements # fine by me
-readability-isolate-declaration # fine by me
-readability-magic-numbers # too coarse-grained
-misc-unused-parameters) # fine by me
# Make it build within the same build tree
get_directory_property (backup_includes INCLUDE_DIRECTORIES)
set_directory_properties (PROPERTIES INCLUDE_DIRECTORIES "")
set (backup_source_dir "${CMAKE_SOURCE_DIR}")
set (CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}/vera++")
string (REPLACE ";" "," clang_tidy_checks "${clang_tidy_checks}")
set (clang_tidy_config "{
Checks: '${clang_tidy_checks}',
CheckOptions: [{
key: readability-function-cognitive-complexity.Threshold,
value: '30'
}]}")
add_subdirectory ("vera++")
string (REPLACE "\n" " " clang_tidy_config "${clang_tidy_config}")
set_directory_properties (PROPERTIES INCLUDE_DIRECTORIES "${backup_includes}")
set (CMAKE_SOURCE_DIR "${backup_source_dir}")
# Check the sources
# XXX: maybe do it per source file and not all at once
set (vera_srcs ${liblogdiag_SOURCES} ${logdiag_SOURCES} ${logdiag_HEADERS})
set (vera_output ${PROJECT_BINARY_DIR}/vera.log)
add_custom_command (OUTPUT ${vera_output}
COMMAND vera
-R F001 -R L001 -R T001 -R T004 -R T005 -R T006
-R T007 -R T009 -R T010 -R T015 -R T017 -R T018
-R L004 -P max-line-length=80
-R L005 -P max-consecutive-empty-lines=2
--root ${CMAKE_SOURCE_DIR}/vera++
--std-report=-
--std-report=${vera_output}
--warning -s
${vera_srcs}
DEPENDS ${vera_srcs}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Checking style for logdiag")
add_custom_target (logdiag_vera ALL DEPENDS ${vera_output})
endif (OPTION_USE_VERA)
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
set (clang_tidy_sources ${liblogdiag_SOURCES} ${logdiag_SOURCES})
add_custom_target (${PROJECT_NAME}_clang_tidy
COMMAND clang-tidy --quiet -p ${PROJECT_BINARY_DIR}
"--config=${clang_tidy_config}" ${clang_tidy_sources}
| sh -c "cat 1>&2"
DEPENDS ${clang_tidy_sources} VERBATIM
USES_TERMINAL WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif ()
# GSettings
find_program (GLIB_COMPILE_SCHEMAS_EXECUTABLE glib-compile-schemas)

View File

@ -1315,7 +1315,7 @@ point_to_line_segment_distance
/* The projection is beyond the line segment. */
if (u < 0.)
return ld_point_distance (point, p1->x, p1->y);
else if (u > 1.)
if (u > 1.)
return ld_point_distance (point, p2->x, p2->y);
/* The projection is on the line segment. */

View File

@ -49,6 +49,8 @@ static gboolean foreach_dir (const gchar *path,
gboolean (*callback) (const gchar *, const gchar *, gpointer),
gpointer userdata, GError **error);
static LdSymbol *traverse_path (LdCategory *category, gchar **path);
G_DEFINE_TYPE (LdLibrary, ld_library, G_TYPE_OBJECT)
@ -356,62 +358,51 @@ ld_library_load (LdLibrary *self, const gchar *directory)
LdSymbol *
ld_library_find_symbol (LdLibrary *self, const gchar *identifier)
{
gchar **id_el_start, **id_el;
const GSList *list, *list_el;
LdCategory *cat;
gchar **path;
LdSymbol *symbol = NULL;
g_return_val_if_fail (LD_IS_LIBRARY (self), NULL);
g_return_val_if_fail (identifier != NULL, NULL);
id_el_start = g_strsplit (identifier, LD_LIBRARY_IDENTIFIER_SEPARATOR, 0);
if (!id_el_start)
return NULL;
/* We need at least one category name plus the symbol name. */
id_el = id_el_start;
if (!id_el[0] || !id_el[1])
goto ld_library_find_symbol_error;
/* Find the category where the symbol is in. */
cat = self->priv->root;
while (1)
path = g_strsplit (identifier, LD_LIBRARY_IDENTIFIER_SEPARATOR, 0);
if (path)
{
gboolean found = FALSE;
symbol = traverse_path (self->priv->root, path);
g_strfreev (path);
}
return symbol;
}
list = ld_category_get_children (cat);
for (list_el = list; list_el; list_el = g_slist_next (list_el))
static LdSymbol *
traverse_path (LdCategory *category, gchar **path)
{
const GSList *list, *iter;
LdSymbol *symbol;
g_return_val_if_fail (*path != NULL, NULL);
/* Walk the category tree to where the symbol is supposed to be. */
for (; path[1]; path++)
{
list = ld_category_get_children (category);
for (iter = list; iter; iter = g_slist_next (iter))
{
cat = LD_CATEGORY (list_el->data);
if (!strcmp (*id_el, ld_category_get_name (cat)))
{
found = TRUE;
category = LD_CATEGORY (iter->data);
if (!strcmp (*path, ld_category_get_name (category)))
break;
}
}
if (!found)
goto ld_library_find_symbol_error;
if (!(id_el++)[2])
break;
if (!iter)
return NULL;
}
/* And then the actual symbol. */
list = ld_category_get_symbols (cat);
for (list_el = list; list_el; list_el = g_slist_next (list_el))
/* And look up the actual symbol at the leaf. */
list = ld_category_get_symbols (category);
for (iter = list; iter; iter = g_slist_next (iter))
{
LdSymbol *symbol;
symbol = LD_SYMBOL (list_el->data);
if (!strcmp (*id_el, ld_symbol_get_name (symbol)))
{
g_strfreev (id_el_start);
symbol = LD_SYMBOL (iter->data);
if (!strcmp (*path, ld_symbol_get_name (symbol)))
return symbol;
}
}
ld_library_find_symbol_error:
g_strfreev (id_el_start);
return NULL;
}

View File

@ -250,8 +250,7 @@ ld_lua_alloc (void *ud, void *ptr, size_t osize, size_t nsize)
g_free (ptr);
return NULL;
}
else
return g_try_realloc (ptr, nsize);
return g_try_realloc (ptr, nsize);
}
/**

View File

@ -618,8 +618,8 @@ diagram_get_name (LdWindowMain *self)
if (self->priv->filename)
return g_filename_display_basename (self->priv->filename);
else
return g_strdup (_("Unsaved Diagram"));
return g_strdup (_("Unsaved Diagram"));
}
/*
@ -698,12 +698,10 @@ diagram_save (LdWindowMain *self, GtkWindow *dialog_parent,
gtk_widget_destroy (message_dialog);
return FALSE;
}
else
{
ld_diagram_set_modified (self->priv->diagram, FALSE);
update_title (self);
return TRUE;
}
ld_diagram_set_modified (self->priv->diagram, FALSE);
update_title (self);
return TRUE;
}
/*
@ -1179,11 +1177,11 @@ static gboolean
on_action_about_activate_link (GtkAboutDialog *dialog, gchar *uri,
LdWindowMain *self)
{
#ifdef G_OS_WIN32
GdkWindow *window;
window = gtk_widget_get_window (GTK_WIDGET (self));
#ifdef G_OS_WIN32
/* gtk_show_uri() on Windows XP fails, due to trying to establish
* an SSL connection, so let's first try to not do that on Windows.
* `cmd.exe /c start "" ...` would pop up a command line window,

1
vera++

@ -1 +0,0 @@
Subproject commit 45f3ab870d3722891642098bd7fc0d6fc97c8571