DME — Code Reflection¶
- class DME¶
The
DMEclass provides reflection information for a BYOND project. This includes looking up available types, proc and var names on those types, and basic support for AST walking.DMEinstances are created with the following methods:- static from_file(filename: str | os.PathLike[str], parse_procs=False) DME¶
Read the BYOND environment from the filename referring to a “.dme” file. If the optional parse_procs argument is
True, reflection data is made available for all procs.- Raises:
OSError: If the file is not found or there was an error opening it.- Raises:
RuntimeError: If there was an error parsing the DME environment.
Once instantiated, the following properties and methods are available:
- class ProcDecl¶
A declaration for a specific proc on a type. Note that a type may have multiple definitions of a given proc with the same name. This only represents one proc definition.
- property source_loc: SourceLoc¶
The
SourceLocof the proc’s declaration, as determined by the parser.
- walk(walker)¶
Use the AST walker to walk this proc.
The argument walker is expected to be a Python object which exposes methods for each kind of AST node you wish to visit. Each method should take two arguments: node, which will be filled in with information about that node in the AST, and source_loc, which includes lexical information about the AST node, such as line, column, and filename. The currently available visitors are:
visit_AssignOpvisit_BinaryOpvisit_Breakvisit_Callvisit_Constantvisit_Continuevisit_Crashvisit_Delvisit_DoWhilevisit_DynamicCallvisit_Exprvisit_ExternalCallvisit_Fieldvisit_ForInfinitevisit_ForKeyValuevisit_ForListvisit_ForLoopvisit_ForRangevisit_Gotovisit_Identifiervisit_Ifvisit_Indexvisit_Inputvisit_InterpStringvisit_Labelvisit_Listvisit_Locatevisit_NewImplicitvisit_NewMiniExprvisit_NewPrefabvisit_ParentCallvisit_Pickvisit_ProcReferencevisit_Returnvisit_SelfCallvisit_Settingvisit_StaticFieldvisit_Switchvisit_TernaryOpvisit_Throwvisit_TryCatchvisit_UnaryOpvisit_Varvisit_While
As with
ast.NodeVisitor, child nodes of a custom visitor method will not be visited. There is currently no analogousgeneric_visitsupport.
- class VarDecl¶
The
VarDeclclass returns basic information about a variable declared on aTypeDecltype declaration.
- class TypeDecl¶
The
TypeDeclclass returns basic information about a type declared in theDMEfile.- property source_loc: SourceLoc¶
The
SourceLocof the type’s initial declaration, as determined by the parser.
- proc_decls(name=None) list[ProcDecl]¶
Returns a list of
ProcDecls for the type. If name is set, only proc declarations with that name will be returned.
- proc_names(self, declared=False, modified=False, unmodified=False) list[str]¶
Returns a list of proc names associated with the type. At least one of the arguments must be true:
If declared is true, the list of proc names will include names declared on the type directly.
If modified is true, the list of proc names will include names of proc declared on a parent type but changed by this type.
if unmodified is true, the list of proc names will include names of proc which were declared on a parent type and unchanged by this type.
- var_decl(name: str, parents: bool = True) VarDecl¶
Returns the variable declaration of the var name. If parents is
True, the type’s parents will be checked for a variable declaration if not specified on the current type.
- var_names(self, declared=False, modified=False, unmodified=False) list[str]¶
Returns a list of variables names for the type declaration.
At least one of the arguments must be true:
If declared is true, the list of variable names will include names declared on the type directly.
If modified is true, the list of variable names will include names of variables declared on a parent type but changed by this type.
if unmodified is true, the list of variable names will include names of variables which were declared on a parent type and unchanged by this type.