Compiler Implementation#
Preprocessing#
- class bshark.compiler._compiler.Preprocessor(unit: Unit)[source]#
A preprocessor for AIDL files.
This simple class can be used to view and inspect basic characteristics of AIDL (and Java) files. The base
Unit
must be loaded first, e.g. by aBaseLoader
.- property declared_class: Node | None#
Returns the body of the unit.
- property lang: Language#
Returns the language of the unit.
- property qname: str#
Returns the qualified name of the unit.
- property rpath: str#
Returns the relative path of the unit.
Internal Model Types#
- class bshark.compiler._compiler.TypeHandler[source]#
A special base class to support a mapping of type names to their corresponding Parcel calls.
- class bshark.compiler._compiler.NodeVisitor(compiler: Compiler)[source]#
A simple visitor class for traversing the AST.
This class will be responsible for generating
FieldDef
andConditionDef
instances.- visit(node: Node, tracker: str, index: int) List[FieldDef] [source]#
Traverses the given node and returns a list of
FieldDef
instances (optional).
- visit_assignment_expression(expr: Node, tracker: str, index: int) List[FieldDef] [source]#
Parse an assignment statement and return a member definitions.
Public API#
- class bshark.compiler._compiler.Compiler(unit: Unit, loader: BaseLoader, type_handler: TypeHandler | None = None, visitor_cls: Type[NodeVisitor] = None)[source]#
The _compiler_ class is used to translate given AIDL definitions into a pre-defined structure that can be used to decode and potentially encode data.
The internal processing depends on which type the underlying unit was associated with. For instance,
BINDER
declarations will result in a different output than parsedPARCELABLE_JAVA
declarations.In general, the compiler tries to describe what operations need to be performed on a
Unit
in order to decode or encode data. There are predefined methods, which will be mapped to their Python equivalents:Method
Python Type
readInt, readLong, readShort, readByte
int
readBoolean
bool
readString
str (
utf-16-le
codec)readString8
str (
utf-8
codec)readFloat, readDouble
float
Binder: All defined methods will be inspected and their parameters will be translated according to the scheme introduced before.
- Parameters:
unit (Unit) – The unit to compile.
loader (BaseLoader) – The
BaseLoader
object to use.
- as_parcelable() ParcelableDef [source]#
Returns the given unit as a
ParcelableDef
.
- compile() BinderDef | ParcelableDef [source]#
Compiles the stored unit. (if possible)
- get_import(qname: str) ImportDef [source]#
Returns the import with the given qualified name (or tries to import it).
- get_local_member(expr: Node) str | None [source]#
Returns the name of the member that is assigned to.
- get_method_call(expr: Node, tracker: str) Node | None [source]#
Tries to resolve a method invocation node from the given start node.
- is_delegate(expr: Node, tracker: str) bool [source]#
Check if a method is a delegate to another internal method (not constructor)
- is_local_assignment(expr: Node, tracker: str) bool [source]#
Check if an expression is a local assignment with the tracker.
- is_target_assignment(expr: Node, tracker: str) bool [source]#
Check if an expression is an assignment with the tracker.
- parse_condition(expr: Node, tracker: str) ConditionDef | None [source]#
Parse an if statement and return a condition definition.
- resolve_parcel_tracker(method: Node) str [source]#
Tries to retrieve the parameter name of the parcel argument
- property resolved_imports: ImportDefList#
Returns the list of resolved imports.