Example #1
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import autogenutils as au

infilename, outbasename = au.parseJSONCommandLine()
json_def = au.parseJSONFile(infilename)

################################################################################
# generate header file
hf = open(outbasename + ".h", "w")
au.autogenWarning(hf, infilename)
au.beginIncludeGuard(hf, outbasename + ".h")

# includes, forward declarations
hf.write("#include <QtCore/QMetaType>\n")
hf.write("class QDBusArgument;\n")
hf.write("#include <QtDBus/QDBusObjectPath>\n")

# begin namespace
hf.write("namespace QsdPrivate {\n")

# struct declarations
for structName, members in json_def.iteritems():
    hf.write("struct " + structName + " {\n")
    for member in members:
        # skip commands to the generator in this step
Example #2
0
    # collect all readonly Q_PROPERTIES from the given file in the binary dir
    qpropertyRegex = re.compile("Q_PROPERTY\\((\\S*) \\w* READ (\\w*)\\)")
    binaryDir = os.path.dirname(outbasename)
    for line in open(os.path.join(binaryDir, interfaceHeader)).readlines():
        match = qpropertyRegex.search(line)
        if match:
            typeName, propName = match.group(1), match.group(2)
            # use pcROProperty to autogenerate unknown properties
            if not propName in propertyNames and not propName in exceptProps:
                pcROProperty(indent, " ".join((typeName, propName)))

################################################################################
# process public header file

hf = open(outbasename + ".h", "w")
au.autogenWarning(hf, inbasename + ".h.in")

commandLineRegex = re.compile("^(\\s*)#auto (\\S*)(.*)$")
def handleParserCommands(file, line):
    # directly output anything that does not look like a parser command
    match = commandLineRegex.match(line)
    if not match:
        file.write(line)
        return
    # read name of parser command (output line unchanged if unknown command)
    parseFunction = parserCommands.get(match.group(2))
    if parseFunction is None:
        file.write(line)
        return
    # call parser command with everything after the command name as argument
    indent = match.group(1)