示例#1
0
def rebuildTree(tree):
    dka.checkTree(tree)
    try:
        st.buildSymtab(tree)
    except common.ProgramError as err:
        print('----')
        print(dha.genSyntax(tree))
        print('----')
        raise err
示例#2
0
文件: main.py 项目: sadboy/AsdlPy
def main():
    
    # Parse arguments.
    args = parseArgs(sys.argv)
    py_inname, dh_outname, dl_outname, pat_outname, py_outname, complocs = args
    
    dar_tree = readDARhi(py_inname)
    
    # Preprocess comprehensions.
    preprocessComprehensions(dar_tree)
    
    # Expand bulk updates.
    du.rewriteBulkUpdates(dar_tree)
    
    # Make set updates strict.
    du.rewriteSetUpdates(dar_tree)
    
    # TODO: rewrite fields
    
    print(dha.genSyntax(dar_tree))
    sys.exit()
    
#    if dks.DOMAIN is dks.OBJECT_DOMAIN:
#        enterPairDomain(dar_tree)
    
#    if dks.TAG:
#        for comp in incrcomps:
#            alttag.tagify(dar_tree, comp)
#        
#        rebuildTree(dar_tree)
#        
#        incrcomps[:0] = [tc.id for c in incrcomps
#                         if hasattr(c.info, 'taginfo')
#                         for tc in c.info.taginfo.tagcomps]
    
#    # The tag comprehensions should be handled *after* the query.
#    # This follows the chain rule, provided we understand tags as
#    # incrementalizable expressions introduced by maintenance code,
#    # rather than as subexpressions of the query.
#    incrcomps.extend(tc.id for c in incrcomps
#                     if hasattr(c.info, 'taginfo')
#                     for tc in c.info.taginfo.tagcomps)
    
    writeDARhi(dl_outname, dar_tree)
    
    # Rewrite wildcards.
    ### TODO: equalcard rewriting as well.
    cu.rewriteWildcards(dar_tree)
    
    # Incrementalize.
    incrementalizeComprehensions(dar_tree)
    
#    writeDARhi(dl_outname, dar_tree)
    
    # Handle wildcards.
    
#    du.WildcardRewriter().run(dar_tree)
#    rebuildTree(dar_tree)
#    
#    wildcomps = cu.liftComprehensions(dar_tree, True, False)
#    rebuildTree(dar_tree)
#    
#    incrementalizeComprehensions(dar_tree, wildcomps, verbose = False)
    
    
    # Split dh tree from patton tree.
    dh_tree = dar_tree
    
    auxmaskmap = depatternize1(dh_tree)
    
    if dks.LEAVE_PD:
#        print(dha.genSyntax(dh_tree))
        leavePairDomain(dh_tree)
    
    depatternize2(dh_tree, auxmaskmap)
    
    # Output DARhi.
    writeDARhi(dh_outname, dh_tree)
    
    # Output Python
#    writePython(py_outname, py_tree)
    writePython(py_outname, dh_tree)
        
    print('Finished!')
示例#3
0
文件: main.py 项目: sadboy/AsdlPy
def writeDARhi(filename, tree):
    printTask('Writing ' + filename)
    dar_out = open(filename, 'wt')
    dar_out.write(dha.genSyntax(tree))
    dar_out.close()
    printDone()