Why are my custom clang-tidy checks not showing up after adding custom module? - clang

I have a few custom clang-tidy checks. For instance one in the cppcoreguidelines module and another in the misc module. They work fine. Now I extended clang-tidy by a custom module to organize them into.
When I rebuild, it succeeds but when I run ./clang-tidy -list-checks -checks=*, my checks do not show up.
Here is what I did to add my custom module called sw:
Created a subdirectory sw under /clang-tools-extra/clang-tidy/
Updated /clang-tools-extra/clang-tidy/CMakeLists.txt by:
adding add_subdirectory(sw) right below add_subdirectory(readability)
listing clangTidySWModule inside the set(ALL_CLANG_TIDY_CHECKS ...) command
Added /clang-tools-extra/clang-tidy/sw/CMakeLists.txt with the following content:
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)
add_clang_library(clangTidySWModule
AllCapsEnumeratorsCheck.cpp
CatchByConstReferenceCheck.cpp
SWTidyModule.cpp
LINK_LIBS
clangTidy
clangTidyUtils
DEPENDS
omp_gen
)
clang_target_link_libraries(clangTidySWModule
PRIVATE
clangAnalysis
clangAST
clangASTMatchers
clangBasic
clangLex
clangTooling
)
Added /clang-tools-extra/clang-tidy/sw/SWTidyModule.cpp with the following content:
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "AllCapsEnumeratorsCheck.h"
#include "CatchByConstReferenceCheck.h"
namespace clang {
namespace tidy {
namespace sw {
class SWModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AllCapsEnumeratorsCheck>(
"sw-all-caps-enumerators");
CheckFactories.registerCheck<CatchByConstReferenceCheck>(
"sw-catch-by-const-reference");
}
};
// Register the SWModule using this statically initialized variable.
static ClangTidyModuleRegistry::Add<SWModule>
X("sw-module", "Adds my custom checks.");
} // namespace sw
// This anchor is used to force the linker to link in the generated object file
// and thus register the ReadabilityModule.
volatile int SWModuleAnchorSource = 0;
} // namespace tidy
} // namespace clang
I added the two checks all-caps-enumerators and catch-by-const-reference like I did under other modules before:
python3 add_new_check.py sw all-caps-enumerators
python3 add_new_check.py sw catch-by-const-reference
Am I missing something? Why are my checks not showing up?

I found what I was missing here. Hopefully this post will at least help others finding an answer quicker plus where to exactly add the missing piece.
I was missing the following in /clang-tools-extra/clang-tidy/ClangTidyForceLinker.h:
// This anchor is used to force the linker to link the SWModule.
extern volatile int SWModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED SWModuleAnchorDestination =
SWModuleAnchorSource;
Now my checks show up and I am happy (:

Related

C++ Builder E2303 Type name expected

I am attempting to use the HP APDK with C++ Builder in RAD Studio XE5. I need to derive a class PlatformServices (or any name of my choosing) from HP's base class SystemServices. Here is my header PlatformServices.h:
/***************************************************************************\
APDK Platform Services
\***************************************************************************/
#ifndef _H_PLATFORMSERVICES
#define _H_PLATFORMSERVICES
#include "header.h" // HP APDK General Header
// class SystemServices {
// };
class PlatformServices : public SystemServices {
~PlatformServices ();
PlatformServices ();
};
#endif
Compiled as-is, I get the error:
[bcc32 Error] PlatformServices.h(13): E2303 Type name expected
Full parser context
PlatformServices.cpp(5): #include PlatformServices.h
PlatformServices.h(13): class PlatformServices
But if I comment out the #include and uncomment the definition for an empty class named SystemServices, the code compiles without error.
I can preprocess the code as-is (in Project Manager, right click on PlatformServices and select Preprocess) and I can see that the #include defines a well formed SystemServices class.
I've also disabled pre-compiled headers.
This seems like a compiler error, but it's a poor workman who blames his tools. I just can't believe C++ Builder would choke on something this basic, yet I can't see what I'm doing wrong. Help!
P.S. I've posted the full code and project files at: https://www.dropbox.com/s/sn1377y59r3idtz/apdk.zip
SystemServices is declared in the apdk namespace, so you need to specify that in your code, either directly:
class PlatformServices : public apdk::SystemServices
Or with a using namespace statement:
using namespace apdk;
class PlatformServices : public SystemServices

Use dynamic reconfiguration to set the parameter value in ROS

I am new to ROS and i want to use Dynamic reconfiguration technique to set a parameter (rectangle_height).
Through internet i came across with the following method but its not working.
Problem: when i run rqt_reconfigure, in that my node (visual_analysis) is not visual so i can't change the parameter.
-In my Includes, i have included the following:
#include <dynamic_reconfigure/DoubleParameter.h>
#include <dynamic_reconfigure/Reconfigure.h>
#include <dynamic_reconfigure/Config.h>
-In my main() where my variable is declared, i have written the following:
int main( )
{
double rectangle_height;
///////////////////Dynamic Reconfig
dynamic_reconfigure::ReconfigureRequest srv_req;
dynamic_reconfigure::ReconfigureResponse srv_resp;
dynamic_reconfigure::DoubleParameter double_param;
dynamic_reconfigure::Config conf;
//Entering values using Dynamic Reconfig
double_param.name = "kurtana_pitch_joint";
double_param.value = rectangle_height;
conf.doubles.push_back(double_param);
srv_req.config = conf;
ros::service::call("/visual_analysis/set_parameters", srv_req, srv_resp);
return 0;
}
You should follow the following steps to have the dynamic Reconfig working:
Make a cfg folder and create a .cfg file where you can declare the parameters you want to change using dynamic reconfig.
Make changes in your CMakeList.txt and MakeFile to adapt them for dynamic reconfig
Make a dynamicReconfigCallBack() in which you can receive/set the changed parameters.
You can follow this tutorial for further detials.

Monodroid Spinner Resource reference error

I'm following the spinner from monodroid tutorial. But encountered problem on the resource.
It cannot lookup the SimpleSpinnerItem & SimpleSpinnerDropDownItem on VS 2010.
Am I missing something?
Edit: Create a partial class to register android runtime as per jonp
public partial class Resource
{
public partial class Layout
{
[Register("simple_spinner_dropdown_item")]
public const int SimpleSpinnerDropDownItem = 17367049;
[Register("simple_spinner_item")]
public const int SimpleSpinnerItem = 17367048;
}
}
Edit 2: Tried the global resource
Edit 3: Conflict on my project namespace
I already identified why the const cannot be recognize. It's because of my namespace projectname.Android, it's being duplicated. When I changed it to projectname.AndroidMobile the global resource is there.
See the conflict below.
Also, to avoid the conflict just use the global:: as per jonp
You need to qualify the class, as there are two Resource types: one local to your project (Your.Namespace.Resource, located in Resource.designer.cs), and global::Android.Resource. You need to use global::Android.Resource.Layout.SimpleSpinnerItem.

Duplicate top-level declaration 'METHOD main' in dart

I'm new to dart, and trying to use dart to write a hello world and a unit test, but I get the error:
duplicate top-level declaration 'METHOD main' at ../app.dart::5:6
My project dir is test-dart, and it has 3 files.
test-dart/models.dart
class User {
hello(String name) {
print("Hello, ${name}");
}
}
test-dart/app.dart
#library("app");
#source("./models.dart");
void main() {
new User().hello("app");
}
test-dart/test/test.dart
#library("test");
#import("../app.dart");
void main() {
print("hello, test");
}
Now there is an error in "test.dart" on void main(), the error message is:
duplicate top-level declaration 'METHOD main' at ../app.dart::5:6
The two main() methods are in different libraries, why they are still duplicated? How to fix it?
If you import a library like this #import('../app.dart), then all names from app.dart become visible in the importing code (all public names, actually -- those that don't start with a _). So in your test.dart library, you now have two main functions visible. That is obviously a collision. There are two ways to solve it (that I know of).
First: import the library with a prefix, like this: #import('../app.dart', prefix: 'app'). Then, all public names from app.dart are still visible, but only with an app prefix, so the main function from app.dart is only accessible by app.main. No collision here, but you have to use a prefix everytime.
Second: using a show combinator, like this: #import('../app.dart', show: ['a', 'b']). Then, it is no longer true that all names from app.dart are visible, only those explicitly named (a and b here). I'm not sure if this is already implemented, though.
Maybe in the future, we will get something opposite to the show combinator, so that you could do #import('../app.dart', hide: ['main']). That would be the best solution for your problem, but it isn't in the current language (as specified by 0.09).
You are importing app.dart without a prefix which means that the symbols of the importing and imported library can collide if there are duplicates such as in your example.
To resolve these collisions the library import allows you to prefix imports with an identifier. Your example should work if you change test.dart as follows:
#library("test");
#import("../app.dart", prefix: "app");
void main() {
print("hello, test");
app.main();
new app.User().hello("main");
}
Notice how the classes and top-level functions in the app.dart library are now accessed using the "app" prefix and thus do not collide with the names in test.dart.

LuaBind and package.loadlib

I'm trying to go through the tutorial with luabind here, http://www.rasterbar.com/products/luabind/docs.html, however i'm having trouble loading the library. I'm currently using version 5.1 of lua, so I believe I would use package.loadlib instead of loadlib. I made a simple dll which is this:
#include <iostream>
#include <luabind\luabind.hpp>
void greet()
{
std::cout << "Hello world!\n";
}
extern "C" int init(lua_State* L)
{
luabind::open(L);
luabind::module(L)
[
luabind::def("greet", &greet)
];
return 0;
}
This builds just fine. However I get an error in lua when I try to run this code:
package.loadlib("LuaTestLib.dll", "init")
greet()
It states that greet is nil. How do I load the functions from the dll properly?
From the first two sentences of package.loadlib's documentation:
Dynamically links the host program with the C library libname. Inside this library, looks for a function funcname and returns this function as a C function.
(emphasis added)
This doesn't execute funcname. It simply returns it as a function for you to call. You still have to call it:
package.loadlib("LuaTestLib.dll", "init")()

Resources