Package org.bytedeco.javacpp.tools
Class Parser
- java.lang.Object
-
- org.bytedeco.javacpp.tools.Parser
-
public class Parser extends 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
Infoobjects 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.
- Author:
- Samuel Audet
- See Also:
Info,InfoMap,InfoMapper
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Map<String,Map<Type,Boolean>>downcastsClasses that have a base class appearing as a key in this map need a downcast constructor.(package private) Stringencoding(package private) InfoMapinfoMap(package private) InfoMapleafInfoMap(package private) StringlineSeparator(package private) Loggerlogger(package private) Set<String>polymorphicClassesJava names of classes recognized as polymorphic.(package private) Propertiesproperties(package private) TokenIndexertokens(package private) Set<String>upcastsJava names of classes needing upcast from their subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddDowncast(String base, Type from, boolean virtual)(package private) Attributeattribute()(package private) Attributeattribute(boolean explicit)(package private) Stringbody()(package private) StringcommentAfter()Converts Doxygen-like documentation comments placed after identifiers to Javadoc-style.(package private) StringcommentBefore()Converts Doxygen-like documentation comments placed before identifiers to Javadoc-style.(package private) StringcommentDoc(String s, int startIndex)Tries to adapt a Doxygen-style documentation comment to Javadoc-style.(package private) static StringconstructorName(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) voidcontainers(Context context, DeclarationList declList)(package private) voiddeclarations(Context context, DeclarationList declList)(package private) Declaratordeclarator(Context context, String defaultName, int infoNumber, boolean useDefaults, int varNumber, boolean arrayAsPointer, boolean pointerAsArray)(package private) static StringdesugarVarargs(String s)(package private) Stringdowncast(Type derived, Type base, boolean virtual)(package private) booleanenumeration(Context context, DeclarationList declList)(package private) booleanextern(Context context, DeclarationList declList)(package private) static StringfilterJavaAnnotations(String s)(package private) booleanfunction(Context context, DeclarationList declList)(package private) TypefunctionAfter(Context context, Declaration decl, Declarator dcl, Type type)Parse function declaration or definition after parameters: const, attributes, trailing type, pure virtual functions.(package private) booleangroup(Context context, DeclarationList declList)(package private) static StringincorporateConstAnnotation(String annotations, int constValueIndex, boolean constValue)(package private) booleanmacro(Context context, DeclarationList declList)(package private) booleannamespace(Context context, DeclarationList declList)private Stringoperator(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) Parametersparameters(Context context, int infoNumber, boolean useDefaults)File[]parse(File outputDirectory, String[] classPath, Class cls)File[]parse(String outputDirectory, String[] classPath, Class cls)(package private) voidparse(Context context, DeclarationList declList, String[] includePath, String include, boolean isCFile)(package private) static StringremoveAnnotations(String s)(package private) static String[]removeDuplicates(String[] a)De-deduplicate an array of strings, keeping order.(package private) TemplateMaptemplate(Context context)(package private) Type[]templateArguments(Context context)(package private) Stringtranslate(String text)(package private) Typetype(Context context)(package private) Typetype(Context context, boolean definition)(package private) booleantypedef(Context context, DeclarationList declList)(package private) Stringupcast(Type derived, Type base, boolean override)(package private) static StringupcastMethodName(String javaName)(package private) booleanusing(Context context, DeclarationList declList)(package private) booleanvariable(Context context, DeclarationList declList)
-
-
-
Field Detail
-
logger
final Logger logger
-
properties
final Properties properties
-
encoding
final String encoding
-
infoMap
InfoMap infoMap
-
leafInfoMap
InfoMap leafInfoMap
-
tokens
TokenIndexer tokens
-
lineSeparator
String lineSeparator
-
downcasts
Map<String,Map<Type,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.
-
-
Constructor Detail
-
Parser
public Parser(Logger logger, Properties properties)
-
Parser
public Parser(Logger logger, Properties properties, String encoding, String lineSeparator)
-
-
Method Detail
-
removeDuplicates
static String[] removeDuplicates(String[] a)
De-deduplicate an array of strings, keeping order.
-
constructorName
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. 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.
-
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 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, String defaultName, int infoNumber, boolean useDefaults, int varNumber, boolean arrayAsPointer, boolean pointerAsArray) throws ParserException
- Throws:
ParserException
-
commentDoc
String commentDoc(String s, int startIndex)
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
Attribute attribute(boolean explicit)
-
body
String body() throws ParserException
- Throws:
ParserException
-
parameters
Parameters parameters(Context context, int infoNumber, boolean useDefaults) throws ParserException
- Throws:
ParserException
-
incorporateConstAnnotation
static String incorporateConstAnnotation(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, String[] includePath, String include, boolean isCFile) throws IOException, ParserException
- Throws:
IOExceptionParserException
-
parse
public File[] parse(String outputDirectory, String[] classPath, Class cls) throws IOException, ParserException
- Throws:
IOExceptionParserException
-
parse
public File[] parse(File outputDirectory, String[] classPath, Class cls) throws IOException, ParserException
- Throws:
IOExceptionParserException
-
-