<commit_before>import io/[File, FileWriter, OcWriter], structs/[List, ArrayList]
import text/EscapeSequence

/**
 * Base class for any C node
 */
CNode: abstract class {
    
    seed := static 0
    
    /**
     * Generate a unique name that contains 'base'.
     * 
     * Subclasses should override this to provide better/shorter names
     * that are still unique.
     */
    genName: func (base: String) -> String {
        seed += 1
        "__%s_%d" format(base, seed)
    }
    
}

/**
 * A source is a combination of .c/.h file
 */
CSource: class extends CNode {

    name: String

    includes := ArrayList<String> new()

    functions := ArrayList<CFunction> new()
    types := ArrayList<CTypeDecl> new()

    init: func (=name) {}

    write: func (basePath: String) {
        baseFile := File new(basePath)
        if(!baseFile exists?()) baseFile mkdirs()
        hw := OcWriter new(FileWriter new(File new(baseFile, name + ".h")))

	    define := "__" + name map(|c| c alphaNumeric?() ? c toUpper() : '_') + "__define__"
	    hw nl(). app("#ifndef "). app(define)
	    hw nl(). app("#define "). app(define)

	    includes each(|i| hw nl(). app("#include "). app(i))
        
        functions each(|f|
            hw nl()
            f writePrototype(hw)
            hw app(';')
        )

	    hw nl(). app("#endif")

        hw close()
        
        cw := OcWriter new(FileWriter new(File new(baseFile, name + ".c")))
        cw nl(). app("#include \""). app(name). app(".h\"")

        types     each(|t| t write(cw))
        functions each(|f| f write(cw))
        cw close()
    }

}

CFunction: class extends CNode {

    returnType: CType
    name: String
    args := ArrayList<CVariable> new()
    body := ArrayList<CStatement> new()

    init: func (=returnType, =name) {}

    writePrototype: func (w: OcWriter) {
        returnType write(w, |w|
            w app(' '). app(name)
            w writeEach(args, "(", ", ", ")", |arg| arg write(w))
        )
    }

    write: func (w: OcWriter) {<commit_msg>Actually create correct directories for modules in C89Ast<commit_after>import io/[File, FileWriter, OcWriter], structs/[List, ArrayList]
import text/EscapeSequence

/**
 * Base class for any C node
 */
CNode: abstract class {
    
    seed := static 0
    
    /**
     * Generate a unique name that contains 'base'.
     * 
     * Subclasses should override this to provide better/shorter names
     * that are still unique.
     */
    genName: func (base: String) -> String {
        seed += 1
        "__%s_%d" format(base, seed)
    }
    
}

/**
 * A source is a combination of .c/.h file
 */
CSource: class extends CNode {

    name: String

    includes := ArrayList<String> new()

    functions := ArrayList<CFunction> new()
    types := ArrayList<CTypeDecl> new()

    init: func (=name) {}

    write: func (basePath: String) {
        baseFile := File new(basePath, name) parent()
        if(!baseFile exists?()) baseFile mkdirs()
        
        hw := OcWriter new(FileWriter new(File new(basePath, name + ".h")))

	    define := "__" + name map(|c| c alphaNumeric?() ? c toUpper() : '_') + "__define__"
	    hw nl(). app("#ifndef "). app(define)
	    hw nl(). app("#define "). app(define)

	    includes each(|i| hw nl(). app("#include "). app(i))
        
        functions each(|f|
            hw nl()
            f writePrototype(hw)
            hw app(';')
        )

	    hw nl(). app("#endif")

        hw close()
        
        cw := OcWriter new(FileWriter new(File new(basePath, name + ".c")))
        cw nl(). app("#include \""). app(name). app(".h\"")

        types     each(|t| t write(cw))
        functions each(|f| f write(cw))
        cw close()
    }

}

CFunction: class extends CNode {

    returnType: CType
    name: String
    args := ArrayList<CVariable> new()
    body := ArrayList<CStatement> new()

    init: func (=returnType, =name) {}

    writePrototype: func (w: OcWriter) {
        returnType write(w, |w|
            w app(' '). app(name)
            w writeEach(args, "(", ", ", ")", |arg| arg write(w))
        )
    }

    write: func (w: OcWriter) {
{'fraction_non_alphanumeric': 0.15483091787439612, 'fraction_numerical': 0.0014492753623188406, 'mean_word_length': 2.18293620292083, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6513944', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1299, 'n_words': 383}