<commit_before>import ../../middle/[FunctionDecl, FunctionCall, TypeDecl, Argument, Type, Expression, InterfaceDecl, VariableAccess, VariableDecl]
import Skeleton, FunctionDeclWriter

FunctionCallWriter: abstract class extends Skeleton {
    
    /** @see FunctionDeclWriter */
    write: static func ~functionCall (this: Skeleton, fCall: FunctionCall) {
        //"|| Writing function call %s (expr = %s)" format(fCall name, fCall expr ? fCall expr toString() : "(nil)") println()

        if(!fCall ref) {
            Exception new(This, "Trying to write unresolved function %s\n" format(fCall toString())) throw()
        }
        fDecl : FunctionDecl = fCall ref
        
        shouldCastThis := false
        
        // write the function name
        if(fDecl vDecl != null) {
            if(fCall expr != null) {
                current app(fCall expr). app("->")
            }
            if(fDecl vDecl == null) {
                current app(fCall getName())
            } else {
                current app(fDecl vDecl getFullName())
            }
        } else {
            FunctionDeclWriter writeFullName(this, fDecl)
            if(fDecl isFinal) {
                shouldCastThis = true
            } else if(fCall getName() == "super") {
                // if super call to a non-final method, add _impl
                // and still need casting
                current app("_impl")
                shouldCastThis = true
            }
        }
        
        current app('(')
        isFirst := true
        
        /* Step 1: write this, if any
         * for example, call to member function pointers (fDecl vDecl != null) don't need a this */
        if(!fDecl isStatic() && fCall isMember() && fDecl vDecl == null) {
            isFirst = false
            callType := fCall expr getType()
            declType := fDecl owner getInstanceType()
            
            // TODO maybe check there's some kind of inheritance/compatibility here?
            // or in the tinker phase?
            if(shouldCastThis || !(callType equals(declType))) {
                current app("("). app(declType). app(") ")
            }<commit_msg>Fixed func@ by knowing when to cast. Also, gcc is *really* being stupid, because casting from a struct type to.. the same struct type, shouldn't be an error.<commit_after>
import ../../middle/[FunctionDecl, FunctionCall, TypeDecl, Argument,
        Type, Expression, InterfaceDecl, VariableAccess, VariableDecl,
        ClassDecl]
import Skeleton, FunctionDeclWriter

FunctionCallWriter: abstract class extends Skeleton {
    
    /** @see FunctionDeclWriter */
    write: static func ~functionCall (this: Skeleton, fCall: FunctionCall) {
        //"|| Writing function call %s (expr = %s)" format(fCall name, fCall expr ? fCall expr toString() : "(nil)") println()

        if(!fCall ref) {
            Exception new(This, "Trying to write unresolved function %s\n" format(fCall toString())) throw()
        }
        fDecl : FunctionDecl = fCall ref
        
        shouldCastThis := false
        
        // write the function name
        if(fDecl vDecl != null) {
            if(fCall expr != null) {
                current app(fCall expr). app("->")
            }
            if(fDecl vDecl == null) {
                current app(fCall getName())
            } else {
                current app(fDecl vDecl getFullName())
            }
        } else {
            FunctionDeclWriter writeFullName(this, fDecl)
            if(fDecl isFinal && fDecl owner != null && fDecl owner getNonMeta() instanceOf(ClassDecl)) {
                shouldCastThis = true
            } else if(fCall getName() == "super") {
                // if super call to a non-final method, add _impl
                // and still need casting
                current app("_impl")
                shouldCastThis = true
            }
        }
        
        current app('(')
        isFirst := true
        
        /* Step 1: write this, if any
         * for example, call to member function pointers (fDecl vDecl != null) don't need a this */
        if(!fDecl isStatic() && fCall isMember() && fDecl vDecl == null) {
            isFirst = false
            callType := fCall expr getType()
            declType := fDecl owner getInstanceType()
            
            // TODO maybe check there's some kind of inheritance/compatibility here?
            // or in the tinker phase?
            if(shouldCastThis || !(callType equals(declType))) {
                current app("("). app(declType). app(") ")
            }
{'fraction_non_alphanumeric': 0.1051939513477975, 'fraction_numerical': 0.00043830813061582295, 'mean_word_length': 1.7965686274509804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3013142', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1158, 'n_words': 392}