Package org.bytedeco.javacpp.tools
Class Parser
java.lang.Object
org.bytedeco.javacpp.tools.Parser
The Parser, just like the Generator, is a mess that is not meant to support the
entirety of C++, but an appropriate subset as used by typical C/C++ header files.
To figure out what that subset is and what the output should be, the idea is to
apply it on as many C/C++ libraries as possible, and patch the code as we go.
At one point in time, when this prototype code appears to have stabilized, we can
start to redesign it in a more meaningful way.
That said, to understand how it is supposed to function in its present state, one can step through the code at runtime: It is quite friendly to debuggers.
Moreover, it relies on Info
objects created as part of the execution
of InfoMapper.map(InfoMap)
. We can understand better how the parsing
is supposed to get accomplished by studying that documentation as well.
To do: - Inherit constructors from helper classes, if possible - etc.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionClasses that have a base class appearing as a key in this map need a downcast constructor.(package private) final String
(package private) InfoMap
(package private) InfoMap
(package private) String
(package private) final Logger
Java names of classes recognized as polymorphic.(package private) final Properties
(package private) TokenIndexer
Java names of classes needing upcast from their subclasses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addDowncast
(String base, Type from, boolean virtual) (package private) Attribute
(package private) Attribute
attribute
(boolean explicit) (package private) String
body()
(package private) String
Converts Doxygen-like documentation comments placed after identifiers to Javadoc-style.(package private) String
Converts Doxygen-like documentation comments placed before identifiers to Javadoc-style.(package private) String
commentDoc
(String s, int startIndex) Tries to adapt a Doxygen-style documentation comment to Javadoc-style.(package private) static String
constructorName
(String cppName) Constructors have 2 kinds of fully qualified name: the calling name of a constructor, used when calling the constructor, e.g.: NS::CN(int) and the declaration name, used when defining the constructor outside its class or when referencing a constructor with using to inherit constructors of base class.(package private) void
containers
(Context context, DeclarationList declList) (package private) void
declarations
(Context context, DeclarationList declList) (package private) Declarator
declarator
(Context context, String defaultName, int infoNumber, boolean useDefaults, int varNumber, boolean arrayAsPointer, boolean pointerAsArray) (package private) static String
(package private) String
(package private) boolean
enumeration
(Context context, DeclarationList declList) (package private) boolean
extern
(Context context, DeclarationList declList) (package private) boolean
function
(Context context, DeclarationList declList) (package private) Type
functionAfter
(Context context, Declaration decl, Declarator dcl, Type type) Parse function declaration or definition after parameters: const, attributes, trailing type, pure virtual functions.(package private) boolean
group
(Context context, DeclarationList declList) (package private) static String
incorporateConstAnnotation
(String annotations, int constValueIndex, boolean constValue) (package private) boolean
macro
(Context context, DeclarationList declList) (package private) boolean
namespace
(Context context, DeclarationList declList) private String
Read and return the operator following an operator keyword: any ofnew, delete, + - * / % ^ & | ~ ! = < > += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= <=>(since C++20) && || ++ -- , ->* -> ( ) [ ]
taking care of template arguments, if any.(package private) Parameters
parameters
(Context context, int infoNumber, boolean useDefaults) File[]
File[]
(package private) void
parse
(Context context, DeclarationList declList, String[] includePath, String include, boolean isCFile) (package private) static String
(package private) TemplateMap
(package private) Type[]
templateArguments
(Context context) (package private) String
(package private) Type
(package private) Type
(package private) boolean
typedef
(Context context, DeclarationList declList) (package private) String
(package private) static String
upcastMethodName
(String javaName) (package private) boolean
using
(Context context, DeclarationList declList) (package private) boolean
variable
(Context context, DeclarationList declList)
-
Field Details
-
logger
-
properties
-
encoding
-
infoMap
InfoMap infoMap -
leafInfoMap
InfoMap leafInfoMap -
tokens
TokenIndexer tokens -
lineSeparator
String lineSeparator -
upcasts
Java names of classes needing upcast from their subclasses. -
downcasts
Classes that have a base class appearing as a key in this map need a downcast constructor. The associated value gives the class to downcast from and whether the inheritance is virtual. -
polymorphicClasses
Java names of classes recognized as polymorphic.
-
-
Constructor Details
-
Parser
-
Parser
-
Parser
-
-
Method Details
-
addDowncast
-
removeAnnotations
-
desugarVarargs
-
upcastMethodName
-
constructorName
Constructors have 2 kinds of fully qualified name: the calling name of a constructor, used when calling the constructor, e.g.: NS::CN(int) and the declaration name, used when defining the constructor outside its class or when referencing a constructor with using to inherit constructors of base class. NS::CN::CN(int) Declarator.cppName contains the calling name, and this method returns the declaration name. Keys in info map should use the declaration name, because the calling name cannot specify arguments in case of constructor templates, and to avoid confusion between classes and constructors info. -
translate
-
containers
- Throws:
ParserException
-
template
- Throws:
ParserException
-
templateArguments
- Throws:
ParserException
-
operator
Read and return the operator following an operator keyword: any ofnew, delete, + - * / % ^ & | ~ ! = < > += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= <=>(since C++20) && || ++ -- , ->* -> ( ) [ ]
taking care of template arguments, if any.- Throws:
ParserException
-
type
- Throws:
ParserException
-
type
- Throws:
ParserException
-
declarator
Declarator declarator(Context context, String defaultName, int infoNumber, boolean useDefaults, int varNumber, boolean arrayAsPointer, boolean pointerAsArray) throws ParserException - Throws:
ParserException
-
commentDoc
Tries to adapt a Doxygen-style documentation comment to Javadoc-style. -
commentBefore
String commentBefore()Converts Doxygen-like documentation comments placed before identifiers to Javadoc-style. Also leaves as is non-documentation comments. -
commentAfter
String commentAfter()Converts Doxygen-like documentation comments placed after identifiers to Javadoc-style. -
attribute
Attribute attribute() -
attribute
-
body
- Throws:
ParserException
-
parameters
- Throws:
ParserException
-
incorporateConstAnnotation
-
function
- Throws:
ParserException
-
functionAfter
Type functionAfter(Context context, Declaration decl, Declarator dcl, Type type) throws ParserException Parse function declaration or definition after parameters: const, attributes, trailing type, pure virtual functions. Updates dcl, decl and/or type accordingly.- Throws:
ParserException
-
variable
- Throws:
ParserException
-
macro
- Throws:
ParserException
-
typedef
- Throws:
ParserException
-
using
- Throws:
ParserException
-
downcast
-
upcast
-
group
- Throws:
ParserException
-
enumeration
- Throws:
ParserException
-
namespace
- Throws:
ParserException
-
extern
- Throws:
ParserException
-
declarations
- Throws:
ParserException
-
parse
void parse(Context context, DeclarationList declList, String[] includePath, String include, boolean isCFile) throws IOException, ParserException - Throws:
IOException
ParserException
-
parse
public File[] parse(String outputDirectory, String[] classPath, Class cls) throws IOException, ParserException - Throws:
IOException
ParserException
-
parse
public File[] parse(File outputDirectory, String[] classPath, Class cls) throws IOException, ParserException - Throws:
IOException
ParserException
-