2022-05-13 15:25:40 +02:00
|
|
|
#!/usr/bin/env python3.10
|
2019-04-24 14:44:31 +02:00
|
|
|
############################################################################
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
# Contact: https://www.qt.io/licensing/
|
|
|
|
#
|
|
|
|
# This file is part of Qt Creator.
|
|
|
|
#
|
|
|
|
# Commercial License Usage
|
|
|
|
# Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
# accordance with the commercial license agreement provided with the
|
|
|
|
# Software or, alternatively, in accordance with the terms contained in
|
|
|
|
# a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
# and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
# information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
#
|
|
|
|
# GNU General Public License Usage
|
|
|
|
# Alternatively, this file may be used under the terms of the GNU
|
|
|
|
# General Public License version 3 as published by the Free Software
|
|
|
|
# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
# included in the packaging of this file. Please review the following
|
|
|
|
# information to ensure the GNU General Public License requirements will
|
|
|
|
# be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
2022-05-13 15:25:40 +02:00
|
|
|
# for installing use pip3 install robotpy-cppheaderparse
|
|
|
|
import CppHeaderParser
|
|
|
|
|
|
|
|
def parse_arguments():
|
|
|
|
parser = argparse.ArgumentParser(description='Clazy checks header file \
|
|
|
|
generator')
|
|
|
|
parser.add_argument('--clang-format-header-file', help='path to \
|
|
|
|
Format.h usually /usr/lib/llvm-x/include/clang/Format/Format.h',
|
|
|
|
default=None, dest='options_header', required=True)
|
|
|
|
return parser.parse_args()
|
2019-04-24 14:44:31 +02:00
|
|
|
|
|
|
|
def full_ui_content(checks):
|
|
|
|
return '''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<ui version="4.0">
|
|
|
|
<class>ClangFormat::ClangFormatChecksWidget</class>
|
|
|
|
<widget class="QWidget" name="ClangFormat::ClangFormatChecksWidget">
|
|
|
|
<property name="maximumSize">
|
|
|
|
<size>
|
2022-05-13 15:25:40 +02:00
|
|
|
<width>580</width>
|
2019-04-24 14:44:31 +02:00
|
|
|
<height>16777215</height>
|
|
|
|
</size>
|
|
|
|
</property>
|
|
|
|
<layout class="QGridLayout" name="checksLayout">
|
|
|
|
''' + checks + ''' </layout>
|
|
|
|
</widget>
|
|
|
|
<resources/>
|
|
|
|
<connections/>
|
|
|
|
</ui>
|
|
|
|
'''
|
|
|
|
|
2022-05-13 15:25:40 +02:00
|
|
|
def lable_ui(name, index, offset = ""):
|
|
|
|
return ''' <item row="''' + str(index) + '''" column="0">
|
|
|
|
<widget class="QLabel" name="label''' + name + '''">
|
2019-04-24 14:44:31 +02:00
|
|
|
<property name="text">
|
2022-05-13 15:25:40 +02:00
|
|
|
<string notr="true">''' + offset + name + '''</string>
|
2019-04-24 14:44:31 +02:00
|
|
|
</property>
|
|
|
|
</widget>
|
|
|
|
</item>
|
|
|
|
'''
|
2022-05-13 15:25:40 +02:00
|
|
|
|
|
|
|
def combobox_ui(name, values, index):
|
|
|
|
combobox = ''' <item row="''' + str(index) + '''" column="1">
|
|
|
|
<widget class="QComboBox" name="''' + name + '''">
|
2019-04-24 14:44:31 +02:00
|
|
|
<property name="focusPolicy">
|
|
|
|
<enum>Qt::StrongFocus</enum>
|
|
|
|
</property>
|
2022-05-13 15:25:40 +02:00
|
|
|
'''
|
|
|
|
for value in values:
|
|
|
|
combobox += ''' <item>
|
2019-04-24 14:44:31 +02:00
|
|
|
<property name="text">
|
2022-05-13 15:25:40 +02:00
|
|
|
<string notr="true">''' + value + '''</string>
|
2019-04-24 14:44:31 +02:00
|
|
|
</property>
|
|
|
|
</item>
|
2022-05-13 15:25:40 +02:00
|
|
|
'''
|
|
|
|
# for
|
|
|
|
combobox += ''' </widget>
|
2019-04-24 14:44:31 +02:00
|
|
|
</item>
|
|
|
|
'''
|
2022-05-13 15:25:40 +02:00
|
|
|
return combobox
|
|
|
|
|
|
|
|
def string_ui(name, index):
|
|
|
|
return ''' <item row="''' + str(index) + '''" column="1">
|
2019-04-24 14:44:31 +02:00
|
|
|
<layout class="QHBoxLayout">
|
|
|
|
<item>
|
2022-05-13 15:25:40 +02:00
|
|
|
<widget class="QLineEdit" name="''' + name + '''">
|
2019-04-24 14:44:31 +02:00
|
|
|
</widget>
|
|
|
|
</item>
|
|
|
|
<item>
|
2022-05-13 15:25:40 +02:00
|
|
|
<widget class="QPushButton" name="set''' + name + '''">
|
2019-04-24 14:44:31 +02:00
|
|
|
<property name="maximumSize">
|
|
|
|
<size>
|
|
|
|
<width>40</width>
|
|
|
|
<height>16777215</height>
|
|
|
|
</size>
|
|
|
|
</property>
|
|
|
|
<property name="text">
|
2019-04-25 10:20:07 +02:00
|
|
|
<string notr="true">Set</string>
|
2019-04-24 14:44:31 +02:00
|
|
|
</property>
|
|
|
|
</widget>
|
|
|
|
</item>
|
|
|
|
</layout>
|
|
|
|
</item>
|
|
|
|
'''
|
2022-05-13 15:25:40 +02:00
|
|
|
|
|
|
|
def vector_ui(name, index):
|
|
|
|
return ''' <item row="''' + str(index) + '''" column="1">
|
2019-04-24 14:44:31 +02:00
|
|
|
<layout class="QHBoxLayout">
|
|
|
|
<item>
|
2022-05-13 15:25:40 +02:00
|
|
|
<widget class="QPlainTextEdit" name="''' + name + '''">
|
2019-04-24 14:44:31 +02:00
|
|
|
<property name="sizePolicy">
|
|
|
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"/>
|
|
|
|
</property>
|
|
|
|
<property name="maximumSize">
|
|
|
|
<size>
|
|
|
|
<width>16777215</width>
|
|
|
|
<height>50</height>
|
|
|
|
</size>
|
|
|
|
</property>
|
|
|
|
</widget>
|
|
|
|
</item>
|
|
|
|
<item>
|
2022-05-13 15:25:40 +02:00
|
|
|
<widget class="QPushButton" name="set''' + name + '''">
|
2019-04-24 14:44:31 +02:00
|
|
|
<property name="maximumSize">
|
|
|
|
<size>
|
|
|
|
<width>40</width>
|
|
|
|
<height>16777215</height>
|
|
|
|
</size>
|
|
|
|
</property>
|
|
|
|
<property name="text">
|
2019-04-25 10:20:07 +02:00
|
|
|
<string notr="true">Set</string>
|
2019-04-24 14:44:31 +02:00
|
|
|
</property>
|
|
|
|
</widget>
|
|
|
|
</item>
|
|
|
|
</layout>
|
|
|
|
</item>
|
|
|
|
'''
|
|
|
|
|
2022-05-13 15:25:40 +02:00
|
|
|
def combobox_ui_bool(name, index):
|
|
|
|
return combobox_ui(name, ["Default", "true", "false"], index)
|
|
|
|
|
|
|
|
def in_list(list, type):
|
|
|
|
for element in list:
|
|
|
|
if element["name"] == type:
|
|
|
|
return element;
|
|
|
|
return
|
|
|
|
|
|
|
|
create_checks_index = 0
|
|
|
|
def create_checks(variables, enums, structs, offset = ""):
|
|
|
|
checks = ""
|
|
|
|
global create_checks_index
|
|
|
|
# create BasedOnStyle combobox ussually not presented in FormatStyle struct
|
|
|
|
if 0 == create_checks_index:
|
|
|
|
create_checks_index += 1
|
|
|
|
checks = lable_ui("BasedOnStyle", create_checks_index)
|
|
|
|
checks += combobox_ui("BasedOnStyle", ["LLVM", "Google", "Chromium", "Mozilla", "WebKit", "Microsoft", "GNU"], create_checks_index)
|
|
|
|
|
|
|
|
for variable in variables:
|
|
|
|
create_checks_index += 1
|
|
|
|
type = variable["type"]
|
|
|
|
name = variable["name"]
|
|
|
|
enum = in_list(enums, type)
|
|
|
|
struct = in_list(structs, type)
|
|
|
|
if enum:
|
|
|
|
checks += lable_ui(name, create_checks_index, offset)
|
|
|
|
checks += combobox_ui(name, [value["name"].split("_")[1] for value in enum["values"]], create_checks_index)
|
|
|
|
elif struct:
|
|
|
|
checks += lable_ui(name, create_checks_index, offset)
|
|
|
|
check = create_checks(struct["properties"]["public"], enums, structs, " ")
|
|
|
|
checks += check
|
|
|
|
elif "std::string" == type or "unsigned" == type or "int" == type:
|
|
|
|
checks += lable_ui(name, create_checks_index, offset)
|
|
|
|
checks += string_ui(name, create_checks_index)
|
|
|
|
elif "std::vector<std::string >" == type:
|
|
|
|
checks += lable_ui(name, create_checks_index, offset)
|
|
|
|
checks += vector_ui(name, create_checks_index)
|
|
|
|
elif "bool" == type:
|
|
|
|
checks += lable_ui(name, create_checks_index, offset)
|
|
|
|
checks += combobox_ui_bool(name, create_checks_index)
|
|
|
|
return checks
|
2019-04-24 14:44:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
arguments = parse_arguments()
|
2022-05-13 15:25:40 +02:00
|
|
|
header = CppHeaderParser.CppHeader(arguments.options_header)
|
2019-04-24 14:44:31 +02:00
|
|
|
|
2022-05-13 15:25:40 +02:00
|
|
|
enums = header.classes["FormatStyle"]["enums"]["public"]
|
|
|
|
structs = header.classes["FormatStyle"]["nested_classes"]
|
|
|
|
variables = header.classes["FormatStyle"]["properties"]["public"]
|
2019-04-24 14:44:31 +02:00
|
|
|
|
2022-05-13 15:25:40 +02:00
|
|
|
checks = create_checks(variables, enums, structs)
|
2019-04-24 14:44:31 +02:00
|
|
|
|
|
|
|
current_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
ui_path = os.path.abspath(os.path.join(current_path, '..', 'src',
|
|
|
|
'plugins', 'clangformat', 'clangformatchecks.ui'))
|
|
|
|
with open(ui_path, 'w') as f:
|
2022-05-13 15:25:40 +02:00
|
|
|
f.write(full_ui_content(checks))
|
|
|
|
|
2019-04-24 14:44:31 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|