Class PythonGenerator
java.lang.Object
edu.nps.moves.dis7.source.generator.pdus.AbstractGenerator
edu.nps.moves.dis7.source.generator.pdus.PythonGenerator
This class autogenerates Python source code from XML PDU definitions, specifically
producing most source code needed for the open-dis7-python distribution.
TODO see JavaGenerator for related functionality that will be needed in Python.
Constructor, not fully implemented.
- Author:
- DMcG
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionStandard python indent is four spacesProperties of interestProperties of interestFields inherited from class edu.nps.moves.dis7.source.generator.pdus.AbstractGenerator
classDescriptions, generatedSourceDirectoryName, languageProperties
-
Constructor Summary
ConstructorsConstructorDescriptionPythonGenerator
(Map<String, GeneratedClass> pClassDescriptions, Properties languagePropertiesPython) Given the input object, something of an abstract syntax tree, this generates a source code file in the Python language.It has ivars, getters, setters, and serialization/deserialization methods.Warning: only partially implemented. -
Method Summary
Modifier and TypeMethodDescriptionPython doesn't like forward-declaring classes, so a subclass must be declared after its superclass.This reorders the list of classes so that this is the case.void
writeClass
(PrintWriter printWriter, GeneratedClass aClass) Create custom outputvoid
writeClassComments
(PrintWriter printWriter, GeneratedClass aClass) Create custom outputvoid
Overridden by the subclasses to generate the code specific to that language.void
writeFlagMethods
(PrintWriter pw, GeneratedClass aClass) Some fields have integers with bit fields defined, eg an integer where bits 0-2 represent some value, while bits 3-4 represent another value, and so on.void
writeLicense
(PrintWriter printWriter) Create outputvoid
writeMarshal
(PrintWriter pw, GeneratedClass aClass) The method that writes out the python marshalling codevoid
writeUnmarshal
(PrintWriter printWriter, GeneratedClass aClass) Create custom methodMethods inherited from class edu.nps.moves.dis7.source.generator.pdus.AbstractGenerator
createGeneratedSourceDirectory, getBitsToShift, getGeneratedSourceDirectoryName, initialCapital, initialLower, setGeneratedSourceDirectoryName
-
Field Details
-
INDENT
Standard python indent is four spaces -
marshalTypes
Properties of interest -
unmarshalTypes
Properties of interest
-
-
Constructor Details
-
PythonGenerator
public PythonGenerator(Map<String, GeneratedClass> pClassDescriptions, Properties languagePropertiesPython) Given the input object, something of an abstract syntax tree, this generates a source code file in the Python language.It has ivars, getters, setters, and serialization/deserialization methods.Warning: only partially implemented.- Parameters:
pClassDescriptions
- String Map of class descriptionslanguagePropertiesPython
- special language properties
-
-
Method Details
-
writeClasses
public void writeClasses()Description copied from class:AbstractGenerator
Overridden by the subclasses to generate the code specific to that language.- Specified by:
writeClasses
in classAbstractGenerator
-
writeClass
Create custom output- Parameters:
printWriter
- outputaClass
- class of interest
-
writeMarshal
The method that writes out the python marshalling code- Parameters:
pw
- PrintWriteraClass
- of interest
-
writeUnmarshal
Create custom method- Parameters:
printWriter
- outputaClass
- class of interest
-
writeClassComments
Create custom output- Parameters:
printWriter
- outputaClass
- class of interest
-
writeFlagMethods
Some fields have integers with bit fields defined, eg an integer where bits 0-2 represent some value, while bits 3-4 represent another value, and so on. This writes accessor and mutator methods for those fields.- Parameters:
pw
- PrintWriteraClass
- of interest
-
writeLicense
Create output- Parameters:
printWriter
- output
-
sortClasses
Python doesn't like forward-declaring classes, so a subclass must be declared after its superclass.This reorders the list of classes so that this is the case. This re-creates the semantic class inheritance tree structure, then traverses the tree in preorder fashion to ensure that a base class is written before a subclass. The implementation is a little wonky in places. // TODO alternative is to provide __inii.py list of classes- Returns:
- sorted List of classes
-