4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
41 # Use custom copytree function
47 import DefineException
50 def isBertosDir(directory):
51 return os.path.exists(directory + "/VERSION")
53 def bertosVersion(directory):
54 return open(directory + "/VERSION").readline().strip()
56 def loadBertosProject(project_file):
57 project_data = pickle.loads(open(project_file, "r").read())
58 project_info = BProject.BProject()
59 project_info.setInfo("PROJECT_PATH", os.path.dirname(project_file))
60 project_info.setInfo("SOURCES_PATH", project_data["SOURCES_PATH"])
61 loadSourceTree(project_info)
62 cpu_name = project_data["CPU_NAME"]
63 project_info.setInfo("CPU_NAME", cpu_name)
64 cpu_info = loadCpuInfos(project_info)
66 print cpu["CPU_NAME"], cpu_name
67 if cpu["CPU_NAME"] == cpu_name:
69 project_info.setInfo("CPU_INFOS", cpu)
71 loadModuleData(project_info)
75 def projectFileGenerator(project_info):
76 directory = project_info.info("PROJECT_PATH")
79 for module, information in project_info.info("MODULES").items():
80 if information["enabled"]:
81 enabled_modules.append(module)
82 project_data["ENABLED_MODULES"] = enabled_modules
83 project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH")
84 project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
85 project_data["CPU_NAME"] = project_info.info("CPU_NAME")
86 print project_info.info("CPU_NAME")
87 project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
88 return pickle.dumps(project_data)
90 def createBertosProject(project_info):
91 directory = project_info.info("PROJECT_PATH")
92 sources_dir = project_info.info("SOURCES_PATH")
93 if os.path.isdir(directory):
94 shutil.rmtree(directory, True)
95 os.makedirs(directory)
96 f = open(directory + "/project.bertos", "w")
97 f.write(projectFileGenerator(project_info))
99 # Destination source dir
100 srcdir = directory + "/bertos"
101 shutil.rmtree(srcdir, True)
102 copytree.copytree(sources_dir + "/bertos", srcdir, ignore_list=const.IGNORE_LIST)
103 # Destination makefile
104 makefile = directory + "/Makefile"
105 if os.path.exists(makefile):
107 makefile = open("mktemplates/Makefile").read()
108 makefile = makefileGenerator(project_info, makefile)
109 open(directory + "/Makefile", "w").write(makefile)
110 # Destination project dir
111 prjdir = directory + "/" + os.path.basename(directory)
112 shutil.rmtree(prjdir, True)
114 # Destination hw files
115 hwdir = prjdir + "/hw"
116 shutil.rmtree(hwdir, True)
118 # Copy all the hw files
119 for module, information in project_info.info("MODULES").items():
120 for hwfile in information["hw"]:
121 string = open(sources_dir + "/" + hwfile, "r").read()
122 open(hwdir + "/" + os.path.basename(hwfile), "w").write(string)
123 # Destination configurations files
124 cfgdir = prjdir + "/cfg"
125 shutil.rmtree(cfgdir, True)
127 # Set to 1 the autoenabled for enabled modules
128 for module, information in project_info.info("MODULES").items():
129 if information["enabled"] and "configuration" in information and information["configuration"] != "":
130 configurations = project_info.info("CONFIGURATIONS")
131 configuration = configurations[information["configuration"]]
132 for start, parameter in configuration["paramlist"]:
133 if "type" in configuration[parameter]["informations"] and configuration[parameter]["informations"]["type"] == "autoenabled":
134 configuration[parameter]["value"] = "1"
135 project_info.setInfo("CONFIGURATIONS", configurations)
136 # Copy all the configuration files
137 for configuration, information in project_info.info("CONFIGURATIONS").items():
138 string = open(sources_dir + "/" + configuration, "r").read()
139 for start, parameter in information["paramlist"]:
140 infos = information[parameter]
141 value = infos["value"]
142 if "unsigned" in infos["informations"] and infos["informations"]["unsigned"]:
144 if "long" in infos["informations"] and infos["informations"]["long"]:
146 string = sub(string, parameter, value)
147 f = open(cfgdir + "/" + os.path.basename(configuration), "w")
151 makefile = open("mktemplates/template.mk", "r").read()
152 makefile = mkGenerator(project_info, makefile)
153 open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile)
154 # Destination main.c file
155 main = open("srctemplates/main.c", "r").read()
156 open(prjdir + "/main.c", "w").write(main)
157 # Files for selected plugins
159 for plugin in project_info.info("OUTPUT"):
160 module = loadPlugin(plugin)
161 relevants_files[plugin] = module.createProject(project_info)
162 project_info.setInfo("RELEVANT_FILES", relevants_files)
164 def loadPlugin(plugin):
166 Returns the given plugin module.
168 return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
170 def mkGenerator(project_info, makefile):
172 Generates the mk file for the current project.
175 mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
176 mk_data["$cpuflag"] = project_info.info("CPU_INFOS")["CPU_FLAG_NAME"]
177 mk_data["$cpuname"] = project_info.info("CPU_INFOS")["CORE_CPU"]
178 mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
179 mk_data["$cflags"] = " ".join(project_info.info("CPU_INFOS")["C_FLAGS"])
180 mk_data["$ldflags"] = " ".join(project_info.info("CPU_INFOS")["LD_FLAGS"])
181 mk_data["$cppflags"] = " ".join(project_info.info("CPU_INFOS")["CPP_FLAGS"])
182 mk_data["$cppaflags"] = " ".join(project_info.info("CPU_INFOS")["CPPA_FLAGS"])
183 mk_data["$cxxflags"] = " ".join(project_info.info("CPU_INFOS")["CXX_FLAGS"])
184 mk_data["$asflags"] = " ".join(project_info.info("CPU_INFOS")["AS_FLAGS"])
185 mk_data["$arflags"] = " ".join(project_info.info("CPU_INFOS")["AR_FLAGS"])
186 mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
187 mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
188 mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
189 mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
191 while makefile.find(key) != -1:
192 makefile = makefile.replace(key, mk_data[key])
195 def makefileGenerator(project_info, makefile):
197 Generate the Makefile for the current project.
199 # TODO write a general function that works for both the mk file and the Makefile
200 while makefile.find("project_name") != -1:
201 makefile = makefile.replace("project_name", os.path.basename(project_info.info("PROJECT_PATH")))
204 def csrcGenerator(project_info):
205 modules = project_info.info("MODULES")
206 files = project_info.info("FILES")
207 if "harvard" in project_info.info("CPU_INFOS")["CPU_TAGS"]:
211 # file to be included in CSRC variable
213 # file to be included in PCSRC variable
215 # files to be included in CPPASRC variable
217 # files to be included in CXXSRC variable
219 # files to be included in ASRC variable
221 # constants to be included at the beginning of the makefile
223 for module, information in modules.items():
224 module_files = set([])
225 dependency_files = set([])
228 hwdir = os.path.basename(project_info.info("PROJECT_PATH")) + "/hw"
229 if information["enabled"]:
230 if "constants" in information:
231 constants.update(information["constants"])
232 cfiles, sfiles = findModuleFiles(module, project_info)
233 module_files |= set(cfiles)
234 asm_files |= set(sfiles)
235 for file in information["hw"]:
236 if file.endswith(".c"):
237 module_files |= set([hwdir + "/" + os.path.basename(file)])
238 for file_dependency in information["depends"]:
239 if file_dependency in files:
240 dependencyCFiles, dependencySFiles = findModuleFiles(file_dependency, project_info)
241 dependency_files |= set(dependencyCFiles)
242 asm_files |= set(dependencySFiles)
243 for file in module_files:
244 if not harvard or information.get("harvard", "both") == "both":
246 if harvard and "harvard" in information:
248 for file in dependency_files:
250 for file in project_info.info("CPU_INFOS")["C_SRC"]:
252 for file in project_info.info("CPU_INFOS")["PC_SRC"]:
254 for file in asm_files:
256 for file in project_info.info("CPU_INFOS")["CPPA_SRC"]:
258 for file in project_info.info("CPU_INFOS")["CXX_SRC"]:
260 for file in project_info.info("CPU_INFOS")["ASRC"]:
262 csrc = " \\\n\t".join(csrc) + " \\"
263 pcsrc = " \\\n\t".join(pcsrc) + " \\"
264 cppasrc = " \\\n\t".join(cppasrc) + " \\"
265 cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
266 asrc = " \\\n\t".join(asrc) + " \\"
267 constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + unicode(value) for key, value in constants.items()])
268 return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
270 def findModuleFiles(module, project_info):
271 # Find the files related to the selected module
274 # .c files related to the module and the cpu architecture
275 for filename, path in findDefinitions(module + ".c", project_info) + \
276 findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".c", project_info):
277 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
278 path = replaceSeparators(path)
279 cfiles.append(path + "/" + filename)
280 # .s files related to the module and the cpu architecture
281 for filename, path in findDefinitions(module + ".s", project_info) + \
282 findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".s", project_info) + \
283 findDefinitions(module + ".S", project_info) + \
284 findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".S", project_info):
285 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
286 path = replaceSeparators(path)
287 sfiles.append(path + "/" + filename)
288 # .c and .s files related to the module and the cpu tags
289 for tag in project_info.info("CPU_INFOS")["CPU_TAGS"]:
290 for filename, path in findDefinitions(module + "_" + tag + ".c", project_info):
291 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
293 path = replaceSeparators(path)
294 cfiles.append(path + "/" + filename)
295 for filename, path in findDefinitions(module + "_" + tag + ".s", project_info) + \
296 findDefinitions(module + "_" + tag + ".S", project_info):
297 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
298 path = replaceSeparators(path)
299 sfiles.append(path + "/" + filename)
300 return cfiles, sfiles
302 def replaceSeparators(path):
304 Replace the separators in the given path with unix standard separator.
307 while path.find(os.sep) != -1:
308 path = path.replace(os.sep, "/")
312 path = os.environ["PATH"]
314 path = path.split(";")
316 path = path.split(":")
319 def findToolchains(path_list):
321 for element in path_list:
322 for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
323 toolchains.append(toolchain)
324 return list(set(toolchains))
326 def getToolchainInfo(output):
328 expr = re.compile("Target: .*")
329 target = expr.findall(output)
331 info["target"] = target[0].split("Target: ")[1]
332 expr = re.compile("gcc version [0-9,.]*")
333 version = expr.findall(output)
334 if len(version) == 1:
335 info["version"] = version[0].split("gcc version ")[1]
336 expr = re.compile("gcc version [0-9,.]* \(.*\)")
337 build = expr.findall(output)
339 build = build[0].split("gcc version ")[1]
340 build = build[build.find("(") + 1 : build.find(")")]
341 info["build"] = build
342 expr = re.compile("Configured with: .*")
343 configured = expr.findall(output)
344 if len(configured) == 1:
345 info["configured"] = configured[0].split("Configured with: ")[1]
346 expr = re.compile("Thread model: .*")
347 thread = expr.findall(output)
349 info["thread"] = thread[0].split("Thread model: ")[1]
352 def loadSourceTree(project):
353 fileList = [f for f in os.walk(project.info("SOURCES_PATH"))]
354 project.setInfo("FILE_LIST", fileList)
356 def findDefinitions(ftype, project):
357 L = project.info("FILE_LIST")
360 for filename in element[2]:
361 if fnmatch.fnmatch(filename, ftype):
362 definitions.append((filename, element[0]))
365 def loadCpuInfos(project):
367 for definition in findDefinitions(const.CPU_DEFINITION, project):
368 cpuInfos.append(getInfos(definition))
371 def getTagSet(cpu_info):
374 tag_set |= set([cpu["CPU_NAME"]])
375 tag_set |= set(cpu["CPU_TAGS"])
376 tag_set |= set([cpu["CORE_CPU"]])
377 tag_set |= set([cpu["TOOLCHAIN"]])
381 def getInfos(definition):
383 D.update(const.CPU_DEF)
384 def include(filename, dict = D, directory=definition[1]):
385 execfile(directory + "/" + filename, {}, D)
386 D["include"] = include
387 include(definition[0], D)
388 D["CPU_NAME"] = definition[0].split(".")[0]
389 D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
393 def getCommentList(string):
394 comment_list = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
395 comment_list = [re.findall(r"^\s*\* *(.*?)$", comment, re.MULTILINE) for comment in comment_list]
398 def loadModuleDefinition(first_comment):
400 module_definition = {}
401 for num, line in enumerate(first_comment):
402 index = line.find("$WIZ$")
406 exec line[index + len("$WIZ$ "):] in {}, module_definition
408 raise ParseError(num, line[index:])
409 elif line.find("\\brief") != -1:
410 module_definition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
412 if "module_name" in module_definition:
413 module_name = module_definition[const.MODULE_DEFINITION["module_name"]]
414 del module_definition[const.MODULE_DEFINITION["module_name"]]
415 module_dict[module_name] = {}
416 if const.MODULE_DEFINITION["module_depends"] in module_definition:
417 depends = module_definition[const.MODULE_DEFINITION["module_depends"]]
418 del module_definition[const.MODULE_DEFINITION["module_depends"]]
419 if type(depends) == str:
421 module_dict[module_name]["depends"] = depends
423 module_dict[module_name]["depends"] = ()
424 if const.MODULE_DEFINITION["module_configuration"] in module_definition:
425 module_dict[module_name]["configuration"] = module_definition[const.MODULE_DEFINITION["module_configuration"]]
426 del module_definition[const.MODULE_DEFINITION["module_configuration"]]
428 module_dict[module_name]["configuration"] = ""
429 if "module_description" in module_definition:
430 module_dict[module_name]["description"] = module_definition["module_description"]
431 del module_definition["module_description"]
432 if const.MODULE_DEFINITION["module_harvard"] in module_definition:
433 harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
434 if harvard == "both" or harvard == "pgm_memory":
435 module_dict[module_name]["harvard"] = harvard
436 del module_definition[const.MODULE_DEFINITION["module_harvard"]]
437 if const.MODULE_DEFINITION["module_hw"] in module_definition:
438 hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
439 del module_definition[const.MODULE_DEFINITION["module_hw"]]
442 module_dict[module_name]["hw"] = hw
444 module_dict[module_name]["hw"] = ()
445 if const.MODULE_DEFINITION["module_supports"] in module_definition:
446 supports = module_definition[const.MODULE_DEFINITION["module_supports"]]
447 del module_definition[const.MODULE_DEFINITION["module_supports"]]
448 module_dict[module_name]["supports"] = supports
449 module_dict[module_name]["constants"] = module_definition
450 module_dict[module_name]["enabled"] = False
451 return to_be_parsed, module_dict
453 def isSupported(project, module=None, property_id=None):
454 if not module and property_id:
455 item = project.info("CONFIGURATIONS")[property_id[0]][property_id[1]]["informations"]
457 item = project.info("MODULES")[module]
458 tag_dict = project.info("ALL_CPU_TAGS")
459 if "supports" in item:
460 support_string = item["supports"]
463 exec "supported = " + support_string in tag_dict, supported
465 raise SupportedException(support_string)
466 return supported["supported"]
470 def loadDefineLists(comment_list):
472 for comment in comment_list:
473 for num, line in enumerate(comment):
474 index = line.find("$WIZ$")
477 exec line[index + len("$WIZ$ "):] in {}, define_list
479 raise ParseError(num, line[index:])
480 for key, value in define_list.items():
481 if type(value) == str:
482 define_list[key] = (value,)
485 def getDescriptionInformations(comment):
487 Take the doxygen comment and strip the wizard informations, returning the tuple
488 (comment, wizard_information)
493 for num, line in enumerate(comment):
494 index = line.find("$WIZ$")
497 brief += line[:index].strip()
499 description += " " + line[:index]
501 exec line[index + len("$WIZ$ "):] in {}, information
503 raise ParseError(num, line[index:])
506 brief += line.strip()
508 description += " " + line
509 description = description.strip()
510 return brief.strip(), description.strip(), information
512 def getDefinitionBlocks(text):
514 Take a text and return a list of tuple (description, name-value).
517 block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
518 for match in block_tmp:
519 # Only the first element is needed
520 comment = match.group(1)
521 define = match.group(2)
522 start = match.start()
523 block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
524 for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
525 comment = match.group(1)
526 define = match.group(2)
527 start = match.start()
528 block.append(([comment], define, start))
529 for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
530 comment = match.group(2)
531 define = match.group(1)
532 start = match.start()
533 block.append(([comment], define, start))
536 def loadModuleData(project):
537 module_info_dict = {}
539 configuration_info_dict = {}
541 for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project):
542 comment_list = getCommentList(open(path + "/" + filename, "r").read())
543 if len(comment_list) > 0:
545 configuration_info = {}
547 to_be_parsed, module_dict = loadModuleDefinition(comment_list[0])
548 except ParseError, err:
549 raise DefineException.ModuleDefineException(path, err.line_number, err.line)
550 for module, information in module_dict.items():
551 if "depends" not in information:
552 information["depends"] = ()
553 information["depends"] += (filename.split(".")[0],)
554 information["category"] = os.path.basename(path)
555 if "configuration" in information and len(information["configuration"]):
556 configuration = module_dict[module]["configuration"]
558 configuration_info[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
559 except ParseError, err:
560 raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
561 module_info_dict.update(module_dict)
562 configuration_info_dict.update(configuration_info)
565 list_dict = loadDefineLists(comment_list[1:])
566 list_info_dict.update(list_dict)
567 except ParseError, err:
568 raise DefineException.EnumDefineException(path, err.line_number, err.line)
569 for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project):
570 comment_list = getCommentList(open(path + "/" + filename, "r").read())
571 list_info_dict.update(loadDefineLists(comment_list))
572 for tag in project.info("CPU_INFOS")["CPU_TAGS"]:
573 for filename, path in findDefinitions("*_" + tag + ".h", project):
574 comment_list = getCommentList(open(path + "/" + filename, "r").read())
575 list_info_dict.update(loadDefineLists(comment_list))
576 project.setInfo("MODULES", module_info_dict)
577 project.setInfo("LISTS", list_info_dict)
578 project.setInfo("CONFIGURATIONS", configuration_info_dict)
579 project.setInfo("FILES", file_dict)
581 def formatParamNameValue(text):
583 Take the given string and return a tuple with the name of the parameter in the first position
584 and the value in the second.
586 block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
589 def loadConfigurationInfos(path):
591 Return the module configurations found in the given file as a dict with the
592 parameter name as key and a dict containig the fields above as value:
593 "value": the value of the parameter
594 "description": the description of the parameter
595 "informations": a dict containig optional informations:
596 "type": "int" | "boolean" | "enum"
597 "min": the minimum value for integer parameters
598 "max": the maximum value for integer parameters
599 "long": boolean indicating if the num is a long
600 "unsigned": boolean indicating if the num is an unsigned
601 "value_list": the name of the enum for enum parameters
603 configuration_infos = {}
604 configuration_infos["paramlist"] = []
605 for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
606 name, value = formatParamNameValue(define)
607 brief, description, informations = getDescriptionInformations(comment)
608 configuration_infos["paramlist"].append((start, name))
609 configuration_infos[name] = {}
610 configuration_infos[name]["value"] = value
611 configuration_infos[name]["informations"] = informations
612 if not "type" in configuration_infos[name]["informations"]:
613 configuration_infos[name]["informations"]["type"] = findParameterType(configuration_infos[name])
614 if ("type" in configuration_infos[name]["informations"] and
615 configuration_infos[name]["informations"]["type"] == "int" and
616 configuration_infos[name]["value"].find("L") != -1):
617 configuration_infos[name]["informations"]["long"] = True
618 configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("L", "")
619 if ("type" in configuration_infos[name]["informations"] and
620 configuration_infos[name]["informations"]["type"] == "int" and
621 configuration_infos[name]["value"].find("U") != -1):
622 configuration_infos[name]["informations"]["unsigned"] = True
623 configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("U", "")
624 configuration_infos[name]["description"] = description
625 configuration_infos[name]["brief"] = brief
626 return configuration_infos
628 def findParameterType(parameter):
629 if "value_list" in parameter["informations"]:
631 if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
634 def sub(string, parameter, value):
636 Substitute the given value at the given parameter define in the given string
638 return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)
640 def isInt(informations):
642 Return True if the value is a simple int.
644 if ("long" not in informatios or not informations["long"]) and ("unsigned" not in informations or informations["unsigned"]):
649 def isLong(informations):
651 Return True if the value is a long.
653 if "long" in informations and informations["long"] and "unsigned" not in informations:
658 def isUnsigned(informations):
660 Return True if the value is an unsigned.
662 if "unsigned" in informations and informations["unsigned"] and "long" not in informations:
667 def isUnsignedLong(informations):
669 Return True if the value is an unsigned long.
671 if "unsigned" in informations and "long" in informations and informations["unsigned"] and informations["long"]:
676 class ParseError(Exception):
677 def __init__(self, line_number, line):
678 Exception.__init__(self)
679 self.line_number = line_number
682 class SupportedException(Exception):
683 def __init__(self, support_string):
684 Exception.__init__(self)
685 self.support_string = support_string