cayhorstmann / codecheck2

Merging CodeCheck checker and Play server
GNU Affero General Public License v3.0
11 stars 29 forks source link

Implement CALL for C #41

Open cayhorstmann opened 1 year ago

cayhorstmann commented 1 year ago

Make a progfileCodeCheck.c with the contents

// Student/instructor code

extern int atoi(const char*);
int main(int argc, char *argv[]) {
    int arg = atoi(argv[1]);
    if (arg == 1) print_T(FUN(ARGS));
    ...
}

where T is derived from the return type (print_int, print_double, print_char_pointer, print_bool, print_char, ...). If the return type is something else, the instructor/student code must contain a function print_T.

cayhorstmann commented 10 months ago

We need to capture the type of the C function, not just its name. Right now, Language.java has a functionName method that finds the name. We'd like functionType. But not all functions have types (e.g. in Python, JavaScript, etc.) So the default in Language should return null, but in CLanguage override to produce a type. The type is everything before the name, with spaces and modifiers (const, static, extern) removed, e.g. int, double, bool, char, char*.

Modify Calls.Call to have a String type field. Set it in addCall to the result of calling functionName. It will be null for all languages other than C. That's ok.

In CLanguage.writeTester, ask for the type of the Call object and produce calls to print_int, print_double, print_char_pointer, print_bool, print_char. Those are the only supported ones. Otherwise call print_unsupported.

Define those functions in a file codecheck_c.h that you include like the C++ language does. They just call printf. Or skip the functions and call printf directly.