bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.51k stars 586 forks source link

#Help Wanted# ParserException: Could not parse declaration at 'delete' #783

Open HelloRayDeng opened 1 month ago

HelloRayDeng commented 1 month ago

Situation: I am keeping getting org.bytedeco.javacpp.tools.ParserException as shown below at the code line like this Scope & operator = (const Scope&) = delete; by using JavaCPP.

Here is the ParserException message, which shows "Could not parse declaration at 'delete'":

[ERROR] Failed to execute JavaCPP Builder: /mnt/c/Users/ksas/Workspace/KS-Workspace/SOAMaster-ng/common/service-monitor-tracer-java/cppbuild/linux-x86_64/include/scope.hpp:30:Could not parse declaration at 'delete' [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 32.953 s [INFO] Finished at: 2024-10-15T10:08:00+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.bytedeco:javacpp:1.7.0-SNAPSHOT:parse (javacpp-parser) on project service-monitor-tracer-java: Failed to execute JavaCPP Builder: /mnt/c/Users/ksas/Workspace/KS-Workspace/SOAMaster-ng/common/service-monitor-tracer-java/cppbuild/linux-x86_64/include/scope.hpp:30:Could not parse declaration at 'delete' -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.bytedeco:javacpp:1.7.0-SNAPSHOT:parse (javacpp-parser) on project service-monitor-tracer-java: Failed to execute JavaCPP Builder at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289) at org.apache.maven.cli.MavenCli.main (MavenCli.java:193) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:569) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347) Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to execute JavaCPP Builder at org.bytedeco.javacpp.tools.BuildMojo.execute (BuildMojo.java:426) at org.bytedeco.javacpp.tools.ParseMojo.execute (ParseMojo.java:39) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289) at org.apache.maven.cli.MavenCli.main (MavenCli.java:193) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:569) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347) Caused by: org.bytedeco.javacpp.tools.ParserException: /mnt/c/Users/ksas/Workspace/KS-Workspace/SOAMaster-ng/common/service-monitor-tracer-java/cppbuild/linux-x86_64/include/scope.hpp:30:Could not parse declaration at 'delete' at org.bytedeco.javacpp.tools.Parser.declarations (Parser.java:4250) at org.bytedeco.javacpp.tools.Parser.group (Parser.java:3597) at org.bytedeco.javacpp.tools.Parser.declarations (Parser.java:4243) at org.bytedeco.javacpp.tools.Parser.namespace (Parser.java:4127) at org.bytedeco.javacpp.tools.Parser.declarations (Parser.java:4242) at org.bytedeco.javacpp.tools.Parser.parse (Parser.java:4333) at org.bytedeco.javacpp.tools.Parser.parse (Parser.java:4483) at org.bytedeco.javacpp.tools.Builder.parse (Builder.java:101) at org.bytedeco.javacpp.tools.Builder.build (Builder.java:1102) at org.bytedeco.javacpp.tools.BuildMojo.execute (BuildMojo.java:420) at org.bytedeco.javacpp.tools.ParseMojo.execute (ParseMojo.java:39)

Here is my cpp code of 'scope.hpp':

#ifndef SOAMASTER_SCOPE_H
#define SOAMASTER_SCOPE_H

#include "span.hpp"
#include "visibility_control.hpp"

namespace soamaster {

/// @brief Calling stack manager.
class SOAMASTER_PUBLIC Scope {
public:
  /// @brief Construct the scope object, it always appears with StartSpan().
  /// @param pSpan  The pointer of the matched span.
  explicit Scope(Span * pSpan) noexcept;
  // @brief Destruct the scope object.
  ~Scope() noexcept;

private:
  /// @brief Reserve the current span, which should match the top one of runtime context.
  Span * pSpan_;
  /// @brief Mask some default methods in class.
  Scope() = delete;
  Scope(const Scope&) = delete;
  Scope(Scope&&) = delete;
  Scope & operator = (const Scope&) = delete;
  Scope & operator = (const Scope&&) = delete;
};

} // End namespace

#endif /* SOAMASTER_SCOPE_H */

Here is my java code using InfoMapper:

@Properties(
        inherit = javacpp.class,
        target = "com.xxxxxx.tracer",
        global = "com.xxxxxx.tracer.global.TracerApi",
        value = {
                @Platform(
                        include = {
                                "span.hpp",
                                "scope.hpp",
                                "service_monitor_tracer.hpp"
                        },
                        link = {
                                "tracer@.1",
                                "ddsc@.1",
                                "ddscxx@.1",
                                "ks"
                        },
                        resource = {
                                "include",
                                "lib",
                                "bin"
                        }
                )
        }
)
@NoException
public class TracerApi implements InfoMapper {
    @Override
    public void map(InfoMap infoMap) {
        infoMap
                // Skip visibility macros in both C++ and Java code
                .put(new Info("SOAMASTER_PUBLIC").cppTypes().annotations().skip())
                .put(new Info("SOAMASTER_EXPORT").cppTypes().annotations().skip())
                .put(new Info("SOAMASTER_IMPORT").cppTypes().annotations().skip())
                .put(new Info("SOAMASTER_PUBLIC_TYPE").cppTypes().annotations().skip())

                .put(new Info("soamaster::Scope::Scope").skip())
                .put(new Info("soamaster::Scope::Scope(const soamaster::Scope&)").skip())
                .put(new Info("soamaster::Scope::Scope(soamaster::Scope&&)").skip())

                .put(new Info("soamaster::Scope& operator=").skip())
                .put(new Info("soamaster::Scope& operator=(const soamaster::Scope&)").skip())
                .put(new Info("soamaster::Scope& operator=(soamaster::Scope&&)").skip());
    }
}

Trying: I have already set a few Info objects in infoMap to skip parsing those methods with delete syntax, which work for constructors, but not for the opearator= with delete, and always failed with this ParserException: Could not parse declaration at 'delete'? Can someone please tell me how can I solve this problem? How should I handle this operator override with delete syntax in javacpp? Thanks for help!

saudet commented 1 month ago

But this is something that we should be able to skip with Info.linePatterns().skip()

HelloRayDeng commented 1 month ago

But this is something that we should be able to skip with Info.linePatterns().skip()

Hi, but I just tried with your solution like this: inforMap.put(new Info("soamaster::Scope& operator=(const soamaster::Scope&)").linePatterns().skip()), which still does not work by me. Can you please show me how to use it in details? Thanks.

saudet commented 1 month ago

There's an example here: https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#skipping-lines-from-header-files