Move createBertosProject as BProject method
[bertos.git] / wizard / bertos_utils.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
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.
10 #
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.
15 #
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
19 #
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.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 import os
37 import fnmatch
38 import glob
39 import re
40 import shutil
41 # Use custom copytree function
42 import copytree
43 import pickle
44
45 import const
46 import plugins
47 import DefineException
48
49 from _wizard_version import WIZARD_VERSION
50
51 from LoadException import VersionException, ToolchainException
52
53 def isBertosDir(directory):
54    return os.path.exists(directory + "/VERSION")
55
56 def bertosVersion(directory):
57    return open(directory + "/VERSION").readline().strip()
58
59 def enabledModules(project_info):
60     enabled_modules = []
61     for name, module in project_info.info("MODULES").items():
62         if module["enabled"]:
63             enabled_modules.append(name)
64     return enabled_modules
65
66 def presetList(directory):
67     """
68     Return the list of the preset found in the selected BeRTOS Version.
69     """
70     abspath = os.path.join(directory, const.PREDEFINED_BOARDS_DIR)
71     preset_list = dict([
72         (os.path.join(abspath, preset_dir), presetInfo(os.path.join(abspath, preset_dir)))
73         for preset_dir in os.listdir(os.path.join(directory, const.PREDEFINED_BOARDS_DIR))
74     ])
75     return preset_list
76
77 def presetInfo(preset_dir):
78     """
79     Return the preset-relevant info contined into the project_file.
80     """
81     preset_info = pickle.loads(open(os.path.join(preset_dir, "project.bertos"), "r").read())
82     try:
83         description = open(os.path.join(preset_dir, "description"), "r").read()
84     except IOError:
85         # No description file found.
86         description = ""
87     relevant_info = {
88         "CPU_NAME": preset_info.get("CPU_NAME"),
89         "SELECTED_FREQ": preset_info.get("SELECTED_FREQ"),
90         "WIZARD_VERSION": preset_info.get("WIZARD_VERSION", None),
91         "PRESET_NAME": preset_info.get("PROJECT_NAME"),
92         "PRESET_DESCRIPTION": description.decode("utf-8"),
93     }
94     return relevant_info
95
96 def mergeSources(srcdir, new_sources, old_sources):
97     # The current mergeSources function provide only a raw copy of the sources in the
98     # created project.
99     #
100     # TODO: implement the three way merge algorithm
101     #
102     shutil.rmtree(srcdir, True)
103     copytree.copytree(os.path.join(new_sources, "bertos"), srcdir, ignore_list=const.IGNORE_LIST)
104
105 def projectFileGenerator(project_info):
106     directory = project_info.info("PROJECT_PATH")
107     project_data = {}
108     enabled_modules = []
109     for module, information in project_info.info("MODULES").items():
110         if information["enabled"]:
111             enabled_modules.append(module)
112     project_data["ENABLED_MODULES"] = enabled_modules
113     # Use the local BeRTOS version instead of the original one
114     # project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH")
115     project_data["SOURCES_PATH"] = directory
116     project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory))
117     project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
118     project_data["CPU_NAME"] = project_info.info("CPU_NAME")
119     project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
120     project_data["OUTPUT"] = project_info.info("OUTPUT")
121     project_data["WIZARD_VERSION"] = WIZARD_VERSION
122     return pickle.dumps(project_data)
123
124 def loadPlugin(plugin):
125     """
126     Returns the given plugin module.
127     """
128     return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
129
130 def versionFileGenerator(project_info, version_file):
131     version = bertosVersion(project_info.info("SOURCES_PATH"))
132     return version_file.replace('$version', version)
133
134 def userMkGenerator(project_info, makefile):
135     mk_data = {}
136     mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
137     mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
138     for key in mk_data:
139         while makefile.find(key) != -1:
140             makefile = makefile.replace(key, mk_data[key])
141     return makefile
142
143 def mkGenerator(project_info, makefile):
144     """
145     Generates the mk file for the current project.
146     """
147     mk_data = {}
148     mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
149     mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
150     cpu_mk_parameters = []
151     for key, value in project_info.info("CPU_INFOS").items():
152         if key.startswith(const.MK_PARAM_ID):
153             cpu_mk_parameters.append("%s = %s" %(key.replace("MK", mk_data["$pname"]), value))
154     mk_data["$cpuparameters"] = "\n".join(cpu_mk_parameters)
155     mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
156     mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
157     mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
158     mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
159     for key in mk_data:
160         while makefile.find(key) != -1:
161             makefile = makefile.replace(key, mk_data[key])
162     return makefile
163
164 def makefileGenerator(project_info, makefile):
165     """
166     Generate the Makefile for the current project.
167     """
168     # TODO write a general function that works for both the mk file and the Makefile
169     while makefile.find("$pname") != -1:
170         makefile = makefile.replace("$pname", os.path.basename(project_info.info("PROJECT_PATH")))
171     return makefile
172
173 def csrcGenerator(project_info):
174     modules = project_info.info("MODULES")
175     files = project_info.info("FILES")
176     if "harvard" in project_info.info("CPU_INFOS")["CPU_TAGS"]:
177         harvard = True
178     else:
179         harvard = False
180     # file to be included in CSRC variable
181     csrc = []
182     # file to be included in PCSRC variable
183     pcsrc = []
184     # files to be included in CPPASRC variable
185     cppasrc = []
186     # files to be included in CXXSRC variable
187     cxxsrc = []
188     # files to be included in ASRC variable
189     asrc = []
190     # constants to be included at the beginning of the makefile
191     constants = {}
192     for module, information in modules.items():
193         module_files = set([])
194         dependency_files = set([])
195         # assembly sources
196         asm_files = set([])
197         hwdir = os.path.basename(project_info.info("PROJECT_PATH")) + "/hw" 
198         if information["enabled"]:
199             if "constants" in information:
200                 constants.update(information["constants"])
201             cfiles, sfiles = findModuleFiles(module, project_info)
202             module_files |= set(cfiles)
203             asm_files |= set(sfiles)
204             for file in information["hw"]:
205                 if file.endswith(".c"):
206                     module_files |= set([hwdir + "/" + os.path.basename(file)])
207             for file_dependency in information["depends"] + tuple(files.keys()):
208                     dependencyCFiles, dependencySFiles = findModuleFiles(file_dependency, project_info)
209                     dependency_files |= set(dependencyCFiles)
210                     asm_files |= set(dependencySFiles)
211             for file in module_files:
212                 if not harvard or information.get("harvard", "both") == "both":
213                     csrc.append(file)
214                 if harvard and "harvard" in information:
215                     pcsrc.append(file)
216             for file in dependency_files:
217                 csrc.append(file)
218             for file in project_info.info("CPU_INFOS")["C_SRC"]:
219                 csrc.append(file)
220             for file in project_info.info("CPU_INFOS")["PC_SRC"]:
221                 pcsrc.append(file)
222             for file in asm_files:
223                 cppasrc.append(file)
224     for file in project_info.info("CPU_INFOS")["CPPA_SRC"]:
225         cppasrc.append(file)
226     for file in project_info.info("CPU_INFOS")["CXX_SRC"]:
227         cxxsrc.append(file)
228     for file in project_info.info("CPU_INFOS")["ASRC"]:
229         asrc.append(file)
230     csrc = set(csrc)
231     csrc = " \\\n\t".join(csrc) + " \\"
232     pcsrc = set(pcsrc)
233     pcsrc = " \\\n\t".join(pcsrc) + " \\"
234     cppasrc = set(cppasrc)
235     cppasrc = " \\\n\t".join(cppasrc) + " \\"
236     cxxsrc = set(cxxsrc)
237     cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
238     asrc = set(asrc)
239     asrc = " \\\n\t".join(asrc) + " \\"
240     constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + unicode(value) for key, value in constants.items()])
241     return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
242
243 def findModuleFiles(module, project_info):
244     # Find the files related to the selected module
245     cfiles = []
246     sfiles = []
247     # .c files related to the module and the cpu architecture
248     for filename, path in project_info.searchFiles(module + ".c"):
249         path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
250         path = replaceSeparators(path)
251         cfiles.append(path + "/" + filename)
252     # .s files related to the module and the cpu architecture
253     for filename, path in project_info.searchFiles(module + ".s") + \
254             project_info.searchFiles(module + ".S"):
255         path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
256         path = replaceSeparators(path)
257         sfiles.append(path + "/" + filename)
258     # .c and .s files related to the module and the cpu tags
259     tags = project_info.info("CPU_INFOS")["CPU_TAGS"]
260
261     # Awful, but secure check for version
262     # TODO: split me in a method/function
263     try:
264         version_string = bertosVersion(project_info.info("SOURCES_PATH"))
265         version_list = [int(i) for i in version_string.split()[-1].split('.')]
266         if version_list < [2, 5]:
267             # For older versions of BeRTOS add the toolchain to the tags
268             tags.append(project_info.info("CPU_INFOS")["TOOLCHAIN"])
269     except ValueError:
270         # If the version file hasn't a valid version number do nothing
271         pass
272
273     for tag in tags:
274         for filename, path in project_info.searchFiles(module + "_" + tag + ".c"):
275             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
276             if os.sep != "/":
277                 path = replaceSeparators(path)
278             cfiles.append(path + "/" + filename)
279         for filename, path in project_info.searchFiles(module + "_" + tag + ".s") + \
280                 project_info.searchFiles(module + "_" + tag + ".S"):
281             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
282             path = replaceSeparators(path)
283             sfiles.append(path + "/" + filename)
284     return cfiles, sfiles
285
286 def replaceSeparators(path):
287     """
288     Replace the separators in the given path with unix standard separator.
289     """
290     if os.sep != "/":
291         while path.find(os.sep) != -1:
292             path = path.replace(os.sep, "/")
293     return path
294
295 def getSystemPath():
296     path = os.environ["PATH"]
297     if os.name == "nt":
298         path = path.split(";")
299     else:
300         path = path.split(":")
301     return path
302
303 def findToolchains(path_list):
304     toolchains = []
305     for element in path_list:
306         for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
307             toolchains.append(toolchain)
308     return list(set(toolchains))
309
310 def getToolchainInfo(output):
311     info = {}
312     expr = re.compile("Target: .*")
313     target = expr.findall(output)
314     if len(target) == 1:
315         info["target"] = target[0].split("Target: ")[1]
316     expr = re.compile("gcc version [0-9,.]*")
317     version = expr.findall(output)
318     if len(version) == 1:
319         info["version"] = version[0].split("gcc version ")[1]
320     expr = re.compile("gcc version [0-9,.]* \(.*\)")
321     build = expr.findall(output)
322     if len(build) == 1:
323         build = build[0].split("gcc version ")[1]
324         build = build[build.find("(") + 1 : build.find(")")]
325         info["build"] = build
326     expr = re.compile("Configured with: .*")
327     configured = expr.findall(output)
328     if len(configured) == 1:
329         info["configured"] = configured[0].split("Configured with: ")[1]
330     expr = re.compile("Thread model: .*")
331     thread = expr.findall(output)
332     if len(thread) == 1:
333         info["thread"] = thread[0].split("Thread model: ")[1]
334     return info
335
336 def getToolchainName(toolchain_info):
337     name = "GCC " + toolchain_info["version"] + " - " + toolchain_info["target"].strip()
338     return name
339
340 def getTagSet(cpu_info):
341     tag_set = set([])
342     for cpu in cpu_info:
343         tag_set |= set([cpu["CPU_NAME"]])
344         tag_set |= set(cpu["CPU_TAGS"])
345         tag_set |= set([cpu["TOOLCHAIN"]])
346     return tag_set
347         
348
349 def getInfos(definition):
350     D = {}
351     D.update(const.CPU_DEF)
352     def include(filename, dict = D, directory=definition[1]):
353         execfile(directory + "/" + filename, {}, D)
354     D["include"] = include
355     include(definition[0], D)
356     D["CPU_NAME"] = definition[0].split(".")[0]
357     D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
358     del D["include"]
359     return D
360
361 def getCommentList(string):
362     comment_list = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
363     comment_list = [re.findall(r"^\s*\* *(.*?)$", comment, re.MULTILINE) for comment in comment_list]
364     return comment_list
365
366 def loadModuleDefinition(first_comment):
367     to_be_parsed = False
368     module_definition = {}
369     for num, line in enumerate(first_comment):
370         index = line.find("$WIZ$")
371         if index != -1:
372             to_be_parsed = True
373             try:
374                 exec line[index + len("$WIZ$ "):] in {}, module_definition
375             except:
376                 raise ParseError(num, line[index:])
377         elif line.find("\\brief") != -1:
378             module_definition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
379     module_dict = {}
380     if "module_name" in module_definition:
381         module_name = module_definition[const.MODULE_DEFINITION["module_name"]]
382         del module_definition[const.MODULE_DEFINITION["module_name"]]
383         module_dict[module_name] = {}
384         if const.MODULE_DEFINITION["module_depends"] in module_definition:
385             depends = module_definition[const.MODULE_DEFINITION["module_depends"]]
386             del module_definition[const.MODULE_DEFINITION["module_depends"]]
387             if type(depends) == str:
388                 depends = (depends,)
389             module_dict[module_name]["depends"] = depends
390         else:
391             module_dict[module_name]["depends"] = ()
392         if const.MODULE_DEFINITION["module_configuration"] in module_definition:
393             module_dict[module_name]["configuration"] = module_definition[const.MODULE_DEFINITION["module_configuration"]]
394             del module_definition[const.MODULE_DEFINITION["module_configuration"]]
395         else:
396             module_dict[module_name]["configuration"] = ""
397         if "module_description" in module_definition:
398             module_dict[module_name]["description"] = module_definition["module_description"]
399             del module_definition["module_description"]
400         if const.MODULE_DEFINITION["module_harvard"] in module_definition:
401             harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
402             module_dict[module_name]["harvard"] = harvard
403             del module_definition[const.MODULE_DEFINITION["module_harvard"]]
404         if const.MODULE_DEFINITION["module_hw"] in module_definition:
405             hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
406             del module_definition[const.MODULE_DEFINITION["module_hw"]]
407             if type(hw) == str:
408                 hw = (hw, )
409             module_dict[module_name]["hw"] = hw
410         else:
411             module_dict[module_name]["hw"] = ()
412         if const.MODULE_DEFINITION["module_supports"] in module_definition:
413             supports = module_definition[const.MODULE_DEFINITION["module_supports"]]
414             del module_definition[const.MODULE_DEFINITION["module_supports"]]
415             module_dict[module_name]["supports"] = supports
416         module_dict[module_name]["constants"] = module_definition
417         module_dict[module_name]["enabled"] = False
418     return to_be_parsed, module_dict
419
420 def isSupported(project, module=None, property_id=None):
421     if not module and property_id:
422         item = project.info("CONFIGURATIONS")[property_id[0]][property_id[1]]["informations"]
423     else:
424         item = project.info("MODULES")[module]
425     tag_dict = project.info("ALL_CPU_TAGS")
426     if "supports" in item:
427         support_string = item["supports"]
428         supported = {}
429         try:
430             exec "supported = " + support_string in tag_dict, supported
431         except:
432             raise SupportedException(support_string)
433         return supported["supported"]
434     else:
435         return True
436
437 def loadDefineLists(comment_list):
438     define_list = {}
439     for comment in comment_list:
440         for num, line in enumerate(comment):
441             index = line.find("$WIZ$")
442             if index != -1:
443                 try:
444                     exec line[index + len("$WIZ$ "):] in {}, define_list
445                 except:
446                     raise ParseError(num, line[index:])
447     for key, value in define_list.items():
448         if type(value) == str:
449             define_list[key] = (value,)
450     return define_list
451
452 def getDescriptionInformations(comment):
453     """
454     Take the doxygen comment and strip the wizard informations, returning the tuple
455     (comment, wizard_information)
456     """
457     brief = ""
458     description = ""
459     information = {}
460     for num, line in enumerate(comment):
461         index = line.find("$WIZ$")
462         if index != -1:
463             if len(brief) == 0:
464                 brief += line[:index].strip()
465             else:
466                 description += " " + line[:index]
467             try:
468                 exec line[index + len("$WIZ$ "):] in {}, information
469             except:
470                 raise ParseError(num, line[index:])
471         else:
472             if len(brief) == 0:
473                 brief += line.strip()
474             else:
475                 description += " " + line
476                 description = description.strip()
477     return brief.strip(), description.strip(), information
478
479 def getDefinitionBlocks(text):
480     """
481     Take a text and return a list of tuple (description, name-value).
482     """
483     block = []
484     block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
485     for match in block_tmp:
486         # Only the first element is needed
487         comment = match.group(1)
488         define = match.group(2)
489         start = match.start()
490         block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
491     for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
492         comment = match.group(1)
493         define = match.group(2)
494         start = match.start()
495         block.append(([comment], define, start))
496     for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
497         comment = match.group(2)
498         define = match.group(1)
499         start = match.start()
500         block.append(([comment], define, start))
501     return block
502
503 def formatParamNameValue(text):
504     """
505     Take the given string and return a tuple with the name of the parameter in the first position
506     and the value in the second.
507     """
508     block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
509     return block[0]
510
511 def loadConfigurationInfos(path):
512     """
513     Return the module configurations found in the given file as a dict with the
514     parameter name as key and a dict containig the fields above as value:
515         "value": the value of the parameter
516         "description": the description of the parameter
517         "informations": a dict containig optional informations:
518             "type": "int" | "boolean" | "enum"
519             "min": the minimum value for integer parameters
520             "max": the maximum value for integer parameters
521             "long": boolean indicating if the num is a long
522             "unsigned": boolean indicating if the num is an unsigned
523             "value_list": the name of the enum for enum parameters
524             "conditional_deps": the list of conditional dependencies for boolean parameters
525     """
526     configuration_infos = {}
527     configuration_infos["paramlist"] = []
528     for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
529         name, value = formatParamNameValue(define)
530         brief, description, informations = getDescriptionInformations(comment)
531         configuration_infos["paramlist"].append((start, name))
532         configuration_infos[name] = {}
533         configuration_infos[name]["value"] = value
534         configuration_infos[name]["informations"] = informations
535         if not "type" in configuration_infos[name]["informations"]:
536             configuration_infos[name]["informations"]["type"] = findParameterType(configuration_infos[name])
537         if ("type" in configuration_infos[name]["informations"] and
538                 configuration_infos[name]["informations"]["type"] == "int" and
539                 configuration_infos[name]["value"].find("L") != -1):
540             configuration_infos[name]["informations"]["long"] = True
541             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("L", "")
542         if ("type" in configuration_infos[name]["informations"] and
543                 configuration_infos[name]["informations"]["type"] == "int" and
544                 configuration_infos[name]["value"].find("U") != -1):
545             configuration_infos[name]["informations"]["unsigned"] = True
546             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("U", "")
547         if "conditional_deps" in configuration_infos[name]["informations"]:
548             if (type(configuration_infos[name]["informations"]["conditional_deps"]) == str or
549                     type(configuration_infos[name]["informations"]["conditional_deps"]) == unicode):
550                 configuration_infos[name]["informations"]["conditional_deps"] = (configuration_infos[name]["informations"]["conditional_deps"], )
551             elif type(configuration_infos[name]["informations"]["conditional_deps"]) == tuple:
552                 pass
553             else:
554                 configuration_infos[name]["informations"]["conditional_deps"] = ()
555         configuration_infos[name]["description"] = description
556         configuration_infos[name]["brief"] = brief
557     return configuration_infos
558
559 def updateConfigurationValues(def_conf, user_conf):
560     for param in def_conf["paramlist"]:
561         if param[1] in user_conf and "value" in user_conf[param[1]]:
562             def_conf[param[1]]["value"] = user_conf[param[1]]["value"]
563     return def_conf
564
565 def findParameterType(parameter):
566     if "value_list" in parameter["informations"]:
567         return "enum"
568     if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
569         return "int"
570
571 def sub(string, parameter, value):
572     """
573     Substitute the given value at the given parameter define in the given string
574     """
575     return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)
576
577 def isInt(informations):
578     """
579     Return True if the value is a simple int.
580     """
581     if ("long" not in informatios or not informations["long"]) and ("unsigned" not in informations or informations["unsigned"]):
582         return True
583     else:
584         return False
585
586 def isLong(informations):
587     """
588     Return True if the value is a long.
589     """
590     if "long" in informations and informations["long"] and "unsigned" not in informations:
591         return True
592     else:
593         return False
594
595 def isUnsigned(informations):
596     """
597     Return True if the value is an unsigned.
598     """
599     if "unsigned" in informations and informations["unsigned"] and "long" not in informations:
600         return True
601     else:
602         return False
603
604 def isUnsignedLong(informations):
605     """
606     Return True if the value is an unsigned long.
607     """
608     if "unsigned" in informations and "long" in informations and informations["unsigned"] and informations["long"]:
609         return True
610     else:
611         return False
612
613 class ParseError(Exception):
614     def __init__(self, line_number, line):
615         Exception.__init__(self)
616         self.line_number = line_number
617         self.line = line
618
619 class SupportedException(Exception):
620     def __init__(self, support_string):
621         Exception.__init__(self)
622         self.support_string = support_string