Package org.bytedeco.javacpp.tools
Class Parser
- java.lang.Object
-
- org.bytedeco.javacpp.tools.Parser
-
public class Parser extends java.lang.Object
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 ofInfoMapper.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:
Info
,InfoMap
,InfoMapper
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,java.util.Map<Type,java.lang.Boolean>>
downcasts
Classes that have a base class appearing as a key in this map need a downcast constructor.(package private) java.lang.String
encoding
(package private) InfoMap
infoMap
(package private) InfoMap
leafInfoMap
(package private) java.lang.String
lineSeparator
(package private) Logger
logger
(package private) java.util.Set<java.lang.String>
polymorphicClasses
Java names of classes recognized as polymorphic.(package private) java.util.Properties
properties
(package private) TokenIndexer
tokens
(package private) java.util.Set<java.lang.String>
upcasts
Java names of classes needing upcast from their subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addDowncast(java.lang.String base, Type from, boolean virtual)
(package private) Attribute
attribute()
(package private) Attribute
attribute(boolean explicit)
(package private) java.lang.String
body()
(package private) java.lang.String
commentAfter()
Converts Doxygen-like documentation comments placed after identifiers to Javadoc-style.(package private) java.lang.String
commentBefore()
Converts Doxygen-like documentation comments placed before identifiers to Javadoc-style.(package private) java.lang.String
commentDoc(java.lang.String s, int startIndex)
Tries to adapt a Doxygen-style documentation comment to Javadoc-style.(package private) static java.lang.String
constructorName(java.lang.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, java.lang.String defaultName, int infoNumber, boolean useDefaults, int varNumber, boolean arrayAsPointer, boolean pointerAsArray)
(package private) static java.lang.String
desugarVarargs(java.lang.String s)
(package private) java.lang.String
downcast(Type derived, Type base, boolean virtual)
(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 java.lang.String
incorporateConstAnnotation(java.lang.String annotations, int constValueIndex, boolean constValue)
(package private) boolean
macro(Context context, DeclarationList declList)
(package private) boolean
namespace(Context context, DeclarationList declList)
private java.lang.String
operator(Context context)
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)
java.io.File[]
parse(java.io.File outputDirectory, java.lang.String[] classPath, java.lang.Class cls)
java.io.File[]
parse(java.lang.String outputDirectory, java.lang.String[] classPath, java.lang.Class cls)
(package private) void
parse(Context context, DeclarationList declList, java.lang.String[] includePath, java.lang.String include, boolean isCFile)
(package private) static java.lang.String
removeAnnotations(java.lang.String s)
(package private) TemplateMap
template(Context context)
(package private) Type[]
templateArguments(Context context)
(package private) java.lang.String
translate(java.lang.String text)
(package private) Type
type(Context context)
(package private) Type
type(Context context, boolean definition)
(package private) boolean
typedef(Context context, DeclarationList declList)
(package private) java.lang.String
upcast(Type derived, Type base, boolean override)
(package private) static java.lang.String
upcastMethodName(java.lang.String javaName)
(package private) boolean
using(Context context, DeclarationList declList)
(package private) boolean
variable(Context context, DeclarationList declList)
-
-
-
Field Detail
-
logger
final Logger logger
-
properties
final java.util.Properties properties
-
encoding
final java.lang.String encoding
-
infoMap
InfoMap infoMap
-
leafInfoMap
InfoMap leafInfoMap
-
tokens
TokenIndexer tokens
-
lineSeparator
java.lang.String lineSeparator
-
upcasts
java.util.Set<java.lang.String> upcasts
Java names of classes needing upcast from their subclasses.
-
downcasts
java.util.Map<java.lang.String,java.util.Map<Type,java.lang.Boolean>> 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.util.Set<java.lang.String> polymorphicClasses
Java names of classes recognized as polymorphic.
-
-
Method Detail
-
addDowncast
private void addDowncast(java.lang.String base, Type from, boolean virtual)
-
removeAnnotations
static java.lang.String removeAnnotations(java.lang.String s)
-
desugarVarargs
static java.lang.String desugarVarargs(java.lang.String s)
-
upcastMethodName
static java.lang.String upcastMethodName(java.lang.String javaName)
-
constructorName
static java.lang.String constructorName(java.lang.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. 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
java.lang.String translate(java.lang.String text)
-
containers
void containers(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
template
TemplateMap template(Context context) throws ParserException
- Throws:
ParserException
-
templateArguments
Type[] templateArguments(Context context) throws ParserException
- Throws:
ParserException
-
operator
private java.lang.String operator(Context context) throws ParserException
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
Type type(Context context) throws ParserException
- Throws:
ParserException
-
type
Type type(Context context, boolean definition) throws ParserException
- Throws:
ParserException
-
declarator
Declarator declarator(Context context, java.lang.String defaultName, int infoNumber, boolean useDefaults, int varNumber, boolean arrayAsPointer, boolean pointerAsArray) throws ParserException
- Throws:
ParserException
-
commentDoc
java.lang.String commentDoc(java.lang.String s, int startIndex)
Tries to adapt a Doxygen-style documentation comment to Javadoc-style.
-
commentBefore
java.lang.String commentBefore()
Converts Doxygen-like documentation comments placed before identifiers to Javadoc-style. Also leaves as is non-documentation comments.
-
commentAfter
java.lang.String commentAfter()
Converts Doxygen-like documentation comments placed after identifiers to Javadoc-style.
-
attribute
Attribute attribute()
-
attribute
Attribute attribute(boolean explicit)
-
body
java.lang.String body() throws ParserException
- Throws:
ParserException
-
parameters
Parameters parameters(Context context, int infoNumber, boolean useDefaults) throws ParserException
- Throws:
ParserException
-
incorporateConstAnnotation
static java.lang.String incorporateConstAnnotation(java.lang.String annotations, int constValueIndex, boolean constValue)
-
function
boolean function(Context context, DeclarationList declList) throws ParserException
- 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
boolean variable(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
macro
boolean macro(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
typedef
boolean typedef(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
using
boolean using(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
group
boolean group(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
enumeration
boolean enumeration(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
namespace
boolean namespace(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
extern
boolean extern(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
declarations
void declarations(Context context, DeclarationList declList) throws ParserException
- Throws:
ParserException
-
parse
void parse(Context context, DeclarationList declList, java.lang.String[] includePath, java.lang.String include, boolean isCFile) throws java.io.IOException, ParserException
- Throws:
java.io.IOException
ParserException
-
parse
public java.io.File[] parse(java.lang.String outputDirectory, java.lang.String[] classPath, java.lang.Class cls) throws java.io.IOException, ParserException
- Throws:
java.io.IOException
ParserException
-
parse
public java.io.File[] parse(java.io.File outputDirectory, java.lang.String[] classPath, java.lang.Class cls) throws java.io.IOException, ParserException
- Throws:
java.io.IOException
ParserException
-
-