# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)


import re
import progSpec
import codeDogParser
from progSpec import cdlog, cdErr
            else:
                ruleIdxStr = fetchOrWriteTerminalParseRule(modelName, field, logLvl)

            partIndexes.append(ruleIdxStr)
        else: pass; # These fields probably have corresponding cofactuals

    nameOut=appendRule(nameIn, "nonterm", SeqOrAlt, partIndexes)
    return nameOut

#######################################################   E x t r a c t i o n   F u n c t i o n s

def getFunctionName(fromName, toName):
    if len(fromName)>=5 and fromName[-5:-3]=='::': fromName=fromName[:-5]
    if len(toName)>=5 and toName[-5:-3]=='::': toName=toName[:-5]
    S='Extract_'+fromName.replace('::', '_')+'_to_'+toName.replace('::', '_')
    return S

def fetchMemVersion(classes, objName):
    if objName=='[' or objName=='{': return [None, None]
    memObj = progSpec.findSpecOf(classes[0], objName, 'struct')
    if memObj==None: return [None, None]
    return [memObj, objName]


def Write_ALT_Extracter(classes, parentStructName, fields, VarTagBase, VarTagSuffix, VarName, indent, level, logLvl):
    # Structname should be the name of the structure being parsed. It will be converted to the mem version to get 'to' fields.
    # Fields is the list of alternates.
    # VarTag is a string used to create local variables.
    # VarName is the LVAL variable name.
    global  globalFieldCount

# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)


# Path: stringStructs.py
import re
import progSpec
import codeDogParser
from progSpec import cdlog, cdErr

            else:
                ruleIdxStr = fetchOrWriteTerminalParseRule(modelName, field, logLvl)

            partIndexes.append(ruleIdxStr)
        else: pass; # These fields probably have corresponding cofactuals

    nameOut=appendRule(nameIn, "nonterm", SeqOrAlt, partIndexes)
    return nameOut

#######################################################   E x t r a c t i o n   F u n c t i o n s

def getFunctionName(fromName, toName):
    if len(fromName)>=5 and fromName[-5:-3]=='::': fromName=fromName[:-5]
    if len(toName)>=5 and toName[-5:-3]=='::': toName=toName[:-5]
    S='Extract_'+fromName.replace('::', '_')+'_to_'+toName.replace('::', '_')
    return S

def fetchMemVersion(classes, objName):
    if objName=='[' or objName=='{': return [None, None]
    memObj = progSpec.findSpecOf(classes[0], objName, 'struct')
    if memObj==None: return [None, None]
    return [memObj, objName]


def Write_ALT_Extracter(classes, parentStructName, fields, VarTagBase, VarTagSuffix, VarName, indent, level, logLvl):
    # Structname should be the name of the structure being parsed. It will be converted to the mem version to get 'to' fields.
    # Fields is the list of alternates.
    # VarTag is a string used to create local variables.
    # VarName is the LVAL variable name.
    global  globalFieldCount

    cdlog(logLvl, "WRITING code to extract one of {} from parse tree...".format(parentStructName))