5

Sparseの経験がある人はいますか? ドキュメントが見つからないように見えるため、生成される警告とエラーは不明です。メーリングリストとマニュアルページをチェックしてみましたが、どちらにもあまりありません。

たとえば、ファイルの 1 つで INT_MAX を使用しています。これにより、limits.h を #include してもエラー (未定義の識別子) が生成されます。

エラーと警告が説明されている場所はありますか?

4

2 に答える 2

6

スパースは、言うまでもなく、リントになることを意図したものではありません。スパースは、さらに分析できるように、任意のコードの解析ツリーを生成することを目的としています。

あなたの例では、GNU_SOURCE(__GNUC__をオンにすると私は信じています)を定義する必要があります。これにより、limits.hで必要なビットが公開されます。

__GNUC__を単独で定義することは避けます。これは、GNU_SOURCEがオンにする他のすべてのスイッチが定義されていないと、アクティブ化されるいくつかのものが未定義の方法で動作する可能性があるためです。

私のポイントは、エラーごとにエラーを潰すのを助けることではありません。スパースは、スタンドアロンの静的分析ツールとしてではなく、主にライブラリとして使用されることを繰り返します。

READMEのコピーから(現在のバージョンがあるかどうかはわかりません):

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.

含まれているクライアントは、何よりも「機能的なテストスイートと例」です。これは非常に便利なツールですが、使用したい場合は別の使用方法を検討することもできます。* lex / bisonを使用していないため、ハッキングが非常に簡単です。

于 2009-11-30T08:27:35.360 に答える
2

limits.h を見ると、この #if 内で INT_MAX が定義されていることがわかります。

/* 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

__GNUC__したがって、動作させるには、limits.h を含める前に未定義にする必要があります。

于 2009-11-30T08:24:05.930 に答える