Domanda

Qualcuno ha esperienza con Sparse ? Non riesco a trovare alcuna documentazione, quindi gli avvisi e gli errori che produce non mi sono chiari. Ho provato a controllare la mailing list e la pagina man ma in realtà non c'è molto.

Ad esempio, utilizzo INT_MAX in uno dei miei file. Questo genera un errore (identificatore indefinito) anche se I #include limits.h.

Esiste un luogo in cui sono stati spiegati gli errori e gli avvisi?

È stato utile?

Soluzione

Sparse non vuole essere un pelucchi, per esempio. Sparse ha lo scopo di produrre un albero di analisi di codice arbitrario in modo che possa essere ulteriormente analizzato.

Nel tuo esempio, o vuoi definire GNU_SOURCE (che credo accenda __GNUC__), che espone i bit di cui hai bisogno nei limiti.h

Eviterei di definire __GNUC__ da solo, poiché diverse cose che si attivano potrebbero comportarsi in modo indefinito senza che tutti gli altri switch che GNU_SOURCE attivano vengano definiti.

Il mio punto non è di aiutarti a eliminare l'errore per errore, ma a ribadire che lo sparse viene usato principalmente come libreria, non come strumento di analisi statica autonomo.

Dalla mia copia di README (non sono sicuro se ho la versione corrente):

This means that a user of the library will literally just need to do

  struct string_list *filelist = NULL;
  char *file;

  action(sparse_initialize(argc, argv, filelist));

  FOR_EACH_PTR_NOTAG(filelist, file) {
    action(sparse(file));
  } END_FOR_EACH_PTR_NOTAG(file);

and he is now done - having a full C parse of the file he opened.  The
library doesn't need any more setup, and once done does not impose any
more requirements.  The user is free to do whatever he wants with the
parse tree that got built up, and needs not worry about the library ever
again.  There is no extra state, there are no parser callbacks, there is
only the parse tree that is described by the header files. The action
function takes a pointer to a symbol_list and does whatever it likes with it.

The library also contains (as an example user) a few clients that do the
preprocessing, parsing and type evaluation and just print out the
results.  These clients were done to verify and debug the library, and
also as trivial examples of what you can do with the parse tree once it
is formed, so that users can see how the tree is organized.

I client inclusi sono più "suite di test funzionali ed esempi" che altro. È uno strumento molto utile, ma potresti prendere in considerazione un altro angolo di utilizzo se vuoi utilizzarlo. Mi piace perché non usa * lex / bison, il che rende notevolmente più facile l'hacking.

Altri suggerimenti

Se guardi limits.h vedrai che INT_MAX è definito all'interno di questo #if

/* If we are not using GNU CC we have to define all the symbols ourself.
 Otherwise use gcc's definitions (see below).  */
#if !defined __GNUC__ || __GNUC__ < 2

quindi per farlo funzionare dovresti definire __GNUC__ prima di includere i limiti.h

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top