Syntax fixes.

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@892 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Greg Watson 2003-06-23 23:52:15 +00:00
parent 826def7e1d
commit 06a927dd68
1 changed files with 42 additions and 32 deletions

View File

@ -108,10 +108,11 @@ class option:
self.loc = 0 # current location self.loc = 0 # current location
self.value = 0 # option value self.value = 0 # option value
self.set = 0 # option has been set self.set = 0 # option has been set
self.used = 0 # option has been set
self.default = 0 # option has default value (otherwise self.default = 0 # option has default value (otherwise
# it is undefined) # it is undefined)
self.comment = '' # description of option self.comment = '' # description of option
self.export = 0 # option is able to be exported self.exportable = 0 # option is able to be exported
self.exported = 0 # option is exported self.exported = 0 # option is exported
self.defined = 0 # option has a value self.defined = 0 # option has a value
self.format = '%s' # option print format self.format = '%s' # option print format
@ -179,15 +180,15 @@ class option:
return return
self.comment = value self.comment = value
def setexport(self): def setexportable(self):
self.export = 1 self.exportable = 1
def setexported(self): def setexported(self):
self.export = 1 self.exportable = 1
self.exported = 1 self.exported = 1
def setnoexport(self): def setnoexport(self):
self.export = 0 self.exportable = 0
self.exported = 0 self.exported = 0
def setformat(self, fmt): def setformat(self, fmt):
@ -196,9 +197,10 @@ class option:
def getformat(self): def getformat(self):
return self.format return self.format
def used(self): def setused(self):
if (self.export): if (self.exportable):
self.exported = 1 self.exported = 1
self.used = 1
def isexported(self): def isexported(self):
return (self.exported and self.defined) return (self.exported and self.defined)
@ -209,6 +211,9 @@ class option:
def isset(self): def isset(self):
return (self.set) return (self.set)
def isused(self):
return (self.used)
class partobj: class partobj:
def __init__ (self, dir, parent, type): def __init__ (self, dir, parent, type):
global partinstance global partinstance
@ -274,7 +279,7 @@ class partobj:
o = getvalue(options, name) o = getvalue(options, name)
if (o == 0): if (o == 0):
fatal("Error: can't use undefined option %s" % name) fatal("Error: can't use undefined option %s" % name)
o.used() o.setused()
setvalue(self.options, name, o) setvalue(self.options, name, o)
if (debug): if (debug):
print "option %s used in %s" % (name, self) print "option %s used in %s" % (name, self)
@ -423,16 +428,16 @@ def setnoexport(name):
fatal("setnoexport: %s not here" % name) fatal("setnoexport: %s not here" % name)
o.setnoexport() o.setnoexport()
def setexport(name): def setexportable(name):
o = getvalue(options, name) o = getvalue(options, name)
if (not o): if (not o):
fatal("setexport: %s not here" % name) fatal("setexportable: %s not here" % name)
o.setexport() o.setexportable()
def setformat(name, fmt): def setformat(name, fmt):
o = getvalue(options, name) o = getvalue(options, name)
if (not o): if (not o):
fatal("setexport: %s not here" % name) fatal("setformat: %s not here" % name)
o.setformat(fmt) o.setformat(fmt)
def getformated(name, part): def getformated(name, part):
@ -474,6 +479,15 @@ def isset(name, part):
return o.isset() return o.isset()
return 0 return 0
def isused(name, part):
if (part):
o = getvalue(part.options, name)
else:
o = getvalue(options, name)
if (o):
return o.isused()
return 0
def usesoption(name): def usesoption(name):
global curpart global curpart
curpart.usesoption(name) curpart.usesoption(name)
@ -583,10 +597,13 @@ def part(name, path, file):
def partpop(): def partpop():
global curpart,curdir global curpart,curdir
print "End PART %s" % curpart.type
# Warn if options are used without being set in this part
for i in curpart.options.keys():
if (not isset(i, curpart)):
print "WARNING: Option %s using default value %s" % (i, getformated(i, curpart))
curpart = pstack.pop() curpart = pstack.pop()
curdir = dirstack.pop() curdir = dirstack.pop()
if (debug):
print "POP PART %s" % curpart.dir
# dodir is like part but there is no new part # dodir is like part but there is no new part
def dodir(path, file): def dodir(path, file):
@ -601,10 +618,11 @@ def dodir(path, file):
if (debug): if (debug):
print "DODIR: path %s, fullpath %s" % (path, fullpath) print "DODIR: path %s, fullpath %s" % (path, fullpath)
print "DODIR: curdis %s treetop %s" % (curdir, treetop) print "DODIR: curdis %s treetop %s" % (curdir, treetop)
print "Configuring DIR %s" % os.path.join(path, file)
dirstack.append(curdir) dirstack.append(curdir)
curdir = fullpath curdir = fullpath
file = os.path.join(fullpath, file) file = os.path.join(fullpath, file)
config_file_list.append(file) config_file_list.append(path)
doconfigfile(fullpath, file) doconfigfile(fullpath, file)
curdir = dirstack.pop() curdir = dirstack.pop()
@ -965,7 +983,7 @@ parser Config:
| unop<<V>> {{ return unop }} | unop<<V>> {{ return unop }}
| "\\(" expr<<V>> "\\)" {{ return expr }} | "\\(" expr<<V>> "\\)" {{ return expr }}
rule partend<<C>>: partstmts<<C>> END rule partend<<C>>: (stmt<<C>>)* END {{ partpop()}}
rule mainboard: MAINBOARD PATH {{ mainboard(PATH) }} rule mainboard: MAINBOARD PATH {{ mainboard(PATH) }}
partend<<1>> partend<<1>>
@ -1050,25 +1068,22 @@ parser Config:
| ldscript<<C>> {{ return ldscript}} | ldscript<<C>> {{ return ldscript}}
| payload<<C>> {{ return payload}} | payload<<C>> {{ return payload}}
rule stmts<<C>>: (stmt<<C>>)* {{ }} # ENTRY for parsing Config.lb file
rule cfgfile: (uses<<1>>)* (stmt<<1>>)*
rule partstmts<<C>>: {{ return 1 }}
(uses<<C>>)*
(stmt<<C>>)* {{ partpop()}}
# need this to get from python to the rules, I think.
rule pstmts: (uses<<1>>)* stmts<<1>> {{ return 1 }}
rule usesid<<C>>: ID {{ if (C): usesoption(ID) }} rule usesid<<C>>: ID {{ if (C): usesoption(ID) }}
rule uses<<C>>: USES (usesid<<C>>)+ rule uses<<C>>: USES (usesid<<C>>)+
# ENTRY for parsing a value
rule value: STR {{ return dequote(STR) }} rule value: STR {{ return dequote(STR) }}
| term<<[]>> {{ return term }} | term<<[]>> {{ return term }}
| DELEXPR {{ return DELEXPR }} | DELEXPR {{ return DELEXPR }}
rule option: OPTION ID EQ value {{ setoptionstmt(ID, value) }} rule option: OPTION ID EQ value {{ setoptionstmt(ID, value) }}
# ENTRY for parsing root part
rule board: LOADOPTIONS {{ loadoptions() }} rule board: LOADOPTIONS {{ loadoptions() }}
TARGET DIRPATH {{ target(DIRPATH) }} TARGET DIRPATH {{ target(DIRPATH) }}
(uses<<1>>)* (uses<<1>>)*
@ -1083,7 +1098,7 @@ parser Config:
| FORMAT STR {{ setformat(ID, dequote(STR)) }} | FORMAT STR {{ setformat(ID, dequote(STR)) }}
| EXPORT | EXPORT
( ALWAYS {{ setexported(ID) }} ( ALWAYS {{ setexported(ID) }}
| USED {{ setexport(ID) }} | USED {{ setexportable(ID) }}
| NEVER {{ setnoexport(ID) }} | NEVER {{ setnoexport(ID) }}
) {{ d |= 2 }} ) {{ d |= 2 }}
| COMMENT STR {{ setcomment(ID, dequote(STR)); d |= 4 }} | COMMENT STR {{ setcomment(ID, dequote(STR)); d |= 4 }}
@ -1092,6 +1107,7 @@ parser Config:
rule define: DEFINE ID {{ newoption(ID) }} rule define: DEFINE ID {{ newoption(ID) }}
defstmts<<ID>> END {{ validdef(ID, defstmts) }} defstmts<<ID>> END {{ validdef(ID, defstmts) }}
# ENTRY for parsing Options.lb file
rule options: (define)* END {{ return 1 }} rule options: (define)* END {{ return 1 }}
%% %%
@ -1124,11 +1140,9 @@ def gencode(part):
def doconfigfile(path, file): def doconfigfile(path, file):
if (debug):
print "DOCONFIGFILE", path, " ", file
filename = os.path.join(path, file) filename = os.path.join(path, file)
loc.push_file(filename) loc.push_file(filename)
if (not parse('pstmts', open(filename, 'r').read())): if (not parse('cfgfile', open(filename, 'r').read())):
fatal("Error: Could not parse file") fatal("Error: Could not parse file")
if __name__=='__main__': if __name__=='__main__':
@ -1152,10 +1166,6 @@ if __name__=='__main__':
gencode(root) gencode(root)
for i in options.keys():
if (isexported(i, 0) and not isset(i, 0)):
print "WARNING: Option %s using default value %s" % (i, getformated(i, 0))
# crt0 includes # crt0 includes
if (debug): if (debug):
for i in crt0includes: for i in crt0includes: