Hacker News new | past | comments | ask | show | jobs | submit login
Automatic compilation of partially available C source code (dcc.ufmg.br)
129 points by vivagn on April 21, 2017 | hide | past | favorite | 17 comments



Aiui Eclipse JDT (and probably other IDEs too) do something similar. It takes code that currently is not valid and tries to massage the AST until it becomes valid so that it can perform type-inference and use the type information to offer valid autocomplete suggestions even at the currently invalid location.


Yes, a few IDEs perform some disambiguation during parse. But notice that the ability to deal with ambiguities and to come up with a proper AST is just step 0 of the pipeline. The challenging part is type inference - as far as I know there are no other tools that can reconstruct sources as we do.


Can somebody in simple but technical terms explain how this works? (I tried to no avail)


It builds the set of type and other constraints that must be fulfilled for the program to be valid. It uses a constraint solver to solve the set of constraints and generate a program that satisfies them.

IE For "List list" to work, there must be a thing named List available as a typedef. For list = 0 to work, tlist must be a pointer or an int. For list->data to work, list must be a pointer to a struct, and that struct must have a member named data. for list->data = val to work, the member named data must be compatible with a double.

It simply generates all of the constraints like this on the program, and then solves the constraint set, which produces a valid program (hopefully. it is possible it may not have enough data in some cases, given how C is parsed)


Exactly. Some programs are inherently ambiguous. In such cases, we cannot do much. - Example 1: `void f(){x * y;}` It's impossible to know whether that is a multiplication or pointer declaration. - Example 2: `void f(){x y = 0;}` We can only know that x is a scalar type (in C terminology), but it could be an int, int * , int * * , etc.


I wish it was called "Psychi-c"


This should've been around in my early days learning C and trying to get my project to compile :)


Neat.


The header code generated contains

typedef int bool;

I am not sure if I want that in my header.


What's the right type then? There is no bool type in C90. It appears in C99.

I've seen this in the wild, including the top answer on a StackOverflow question:

#define bool int

http://stackoverflow.com/questions/4159713/how-to-use-boolea...

Besides, if you want correct code, don't ask a tool to guess it! This tool is for patching up fragments enough to get them through the compiler front end analysis.


Well if you care about space efficiency, char is smaller than int.


Indeed, this can be an arguable choice. But notice the project is still in research, it's not an end-user product yet. Eventually, we'll offer options so the user can specifier whether he/she wants such a thing (or inference of standard/posix library functions, for example).


Why not? C does not have a book type and it is standard to use either char or int, depending on if you're concerned about space or about time.


C does have a bool type as well. I have not seen it used much in the C code that I have encountered. See http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdb...


It's "new" as of C99.

The actual boolean type is called _Bool, but <stdbool.h> provides macros that let bool, true, and false work.


What I find weird is that it's not really used. Why generate bool, true, and false?


You're right, it's not always used. Please notice my other answer above, the project is still a prototype. Eventually, we'll filter what actually goes to the generated header and we'll allow the user to specify whether he/she wants bools, inference of C/POSIX library functions, etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: