Mercurial > hg > CbC > old > CbC_scripts
changeset 24:569b28c699d9
create stub
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 01 Nov 2015 04:33:51 +0900 |
parents | e22a82d584c6 |
children | 9a1cce532f29 |
files | meta_connector/meta_connector.py |
diffstat | 1 files changed, 24 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/meta_connector/meta_connector.py Sat Oct 31 17:43:39 2015 +0900 +++ b/meta_connector/meta_connector.py Sun Nov 01 04:33:51 2015 +0900 @@ -41,23 +41,25 @@ for i,l in enumerate(lines): regexed_l = re.search(r"[a-zA-Z0-9_]+ *\(",l) - # get caller code segment name - if re.search(r"^ *__code",l) is not None: + if re.search(r"^ *__code",l) is not None: # code segment declarations. isMetaOrStub = False caller_name = regexed_l.group(0).rstrip('(') + args = get_args_from_line(l) if caller_name == 'meta': defaultMetaIsNotExist = False - if re.search(r"^ *meta_*|stub$",caller_name) is not None: # meta code segment or stub + if re.search(r"^ *meta_*|stub$",caller_name) is not None: # meta code segments or stubs isMetaOrStub = True - file.write(l) - elif re.search(r"struct Context\* context",l) is None: + elif not cs_search(lines, caller_name+'_stub'): # normal code segments which do not have a stub. + create_stub(file, caller_name, args.strip(',')) + + if re.search(r"struct Context\* context",l) is None: # add context to arguments list if it didn't have. file.write("/*-- generated by script */\n") file.write('// '+l) - file.write('__code {0:s}(struct Context* context{1:s}) {{\n'.format(caller_name,get_args_from_line(l))) + file.write('__code {0:s}(struct Context* context{1:s}) {{\n'.format(caller_name, args)) else: file.write(l) - elif not isMetaOrStub and regexed_l is not None and re.search(r"^ *goto",l): + elif not isMetaOrStub and regexed_l is not None and re.search(r"^ *goto",l): # code segment transition. callee_name = regexed_l.group(0).rstrip('(') if callee_name == 'start_code' or re.match('meta_|meta$',callee_name): file.write(l) @@ -65,7 +67,7 @@ file.write("/*-- connected by script */\n") file.write('// '+l) meta_name = 'meta_'+caller_name if cs_search(lines, 'meta_'+callee_name) else 'meta' - file.write("goto {0:s}(context{1:s}, {2:s});\n".format(meta_name, get_args_from_line(l),\ + file.write("goto {0:s}(context{1:s}, {2:s});\n".format(meta_name, args,\ callee_name.capitalize())) else: file.write(l) @@ -87,13 +89,25 @@ return args -def create_stub(file,name): +def create_stub(file, name, args): file.write('''__code {0:s}_stub(struct Context* context) {{ goto {0:s}(context'''.format(name)) - + for arg in args_str2args_list(args): + file.write(', &context->data['+arg.capitalize()+']->'+arg) file.write(');\n}\n') +def args_str2args_list(args_str): + args_list = [] + temporary_list = args_str.split() + for i,arg in enumerate(temporary_list): + if re.search(r"context,*", arg) is not None: + continue + if arg.endswith(',') or i == len(temporary_list)-1: + args_list.append(arg.strip(',')) + return args_list + # search meta code segment. +# It returns true when cs was found. # Find it : __code meta_'name' def cs_search(lines, name): for l in lines: