diff options
| author | John (J5) Palmieri <johnp@redhat.com> | 2005-03-21 21:13:56 +0000 | 
|---|---|---|
| committer | John (J5) Palmieri <johnp@redhat.com> | 2005-03-21 21:13:56 +0000 | 
| commit | 11519c46c42e1dc65614ad9ba214604561b9788e (patch) | |
| tree | d4d879d2209aa8a9d0df29e1cecebac5698d044b /python/lvalue_cast_post_process.py | |
| parent | 5edf8099634762a2be515de4410d732e7202c6a8 (diff) | |
* python/lvalue_cast_post_process.py - added post processor to fix Pyrex
  code so that it compiles with gcc4.0
* python/Makefile.am: Added lvalue_cast_post_process.py to EXTRA_DIST
  run dbus_bindings.c through lvalue_cast_post_process.py and copy the
  results back to dbus_binding.c
Diffstat (limited to 'python/lvalue_cast_post_process.py')
| -rwxr-xr-x | python/lvalue_cast_post_process.py | 80 | 
1 files changed, 80 insertions, 0 deletions
diff --git a/python/lvalue_cast_post_process.py b/python/lvalue_cast_post_process.py new file mode 100755 index 00000000..66129004 --- /dev/null +++ b/python/lvalue_cast_post_process.py @@ -0,0 +1,80 @@ +#!/bin/env python + +import re +import sys + +exp_pattern = re.compile('(.*)=(.*);') +lval_pyobject_pattern = re.compile('\s*\(\((PyObject[ ]?\*)\)([A-Za-z0-9_ ]+)\)') +lval_structcast_pattern = re.compile('\s*\((struct [A-Za-z0-9_]+ \*)\)([A-Za-z0-9_]+)\-\>([A-Za-z0-9_]+)') + +def parse_expression(exp): +	exp_match = exp_pattern.match(exp) +	if exp_match: +		lvalue = exp_match.group(1) +		rvalue = exp_match.group(2) + +		lval_match = lval_pyobject_pattern.match(lvalue) + +		if lval_match: +			cast = lval_match.group(1) +			lvar = lval_match.group(2) + +			return "%s = (%s)(%s);" % (lvar, cast, rvalue) +		else: +			lval_match = lval_structcast_pattern.match(lvalue) +			if lval_match: +				cast = lval_match.group(1) +				casted_var = lval_match.group(2) +				member_var = lval_match.group(3) + +				result = "%s->%s = ((%s)%s);" % ( +					    casted_var,  +					    member_var,  +					    cast, +					    rvalue) + +				return result + +	return None + +def main(): +	if len(sys.argv) != 2: +		print "USAGE: " + sys.argv[0] + " <file name>"  +		return(-1)	 + +	file = sys.argv[1] +	f = open(file) +	gcc4fix_filename = file + ".gcc4fix" +	outputf = open(gcc4fix_filename, 'w') + +	lines = f.readlines() +	f.close() +	for line in lines: +		c = line.count(";") +		if c == 0: +			outputf.write(line) +			continue + +		exprs = line.split(';') +		line = "" +		last = exprs.pop() +		for expr in exprs: +			expr = expr + ";" + +			result = parse_expression(expr) +			if result: +				line = line + result +			else: +				line = line + expr + +		if (last.strip()!=''): +			line = line + last +		else: +			line = line + "\n" +			 +		outputf.write(line) +	 +	outputf.close() + +if __name__ == "__main__": +	sys.exit(main())  | 
