From: Reid Spencer Date: Fri, 13 Aug 2004 20:19:14 +0000 (+0000) Subject: Added description of usage of the getPosition() option on cl::opt and X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2c8ab588d5b8ebdee2431df200ce27edc2928174;p=oota-llvm.git Added description of usage of the getPosition() option on cl::opt and cl::list. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15726 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/CommandLine.html b/docs/CommandLine.html index aea3ec843c0..03ffbbdd536 100644 --- a/docs/CommandLine.html +++ b/docs/CommandLine.html @@ -30,6 +30,8 @@
  • Positional Arguments
  • @@ -780,7 +782,7 @@ OPTIONS:

    Positional arguments are sorted by their order of construction. This means that command line options will be ordered according to how they are listed in a -.cpp file, but will not have an ordering defined if they positional arguments +.cpp file, but will not have an ordering defined if the positional arguments are defined in multiple .cpp files. The fix for this problem is simply to define all of your positional arguments in one .cpp file.

    @@ -824,6 +826,62 @@ can use it like this:

    + +
    + Determining absolute position with getPosition() +
    +
    +

    Sometimes an option can affect or modify the meaning of another option. For + example, consider gcc's -x LANG option. This tells + gcc to ignore the suffix of subsequent positional arguments and force + the file to be interpreted as if it contained source code in language + LANG. In order to handle this properly , you need to know the + absolute position of each argument, especially those in lists, so their + interaction(s) can be applied correctly. This is also useful for options like + -llibname which is actually a positional argument that starts with + a dash.

    +

    So, generally, the problem is that you have two cl::list variables + that interact in some way. To ensure the correct interaction, you can use the + cl::list::getPosition(optnum) method. This method returns the + absolute position (as found on the command line) of the optnum + item in the cl::list.

    +

    The idiom for usage is like this:

    
    +  static cl::list<std::string> Files(cl::Positional, cl::OneOrMore);
    +  static cl::listlt;std::string> Libraries("l", cl::ZeroOrMore);
    +
    +  int main(int argc, char**argv) {
    +    // ...
    +    std::vector<std::string>::iterator fileIt = Files.begin();
    +    std::vector<std::string>::iterator libIt  = Libraries.begin();
    +    unsigned libPos = 0, filePos = 0;
    +    while ( 1 ) {
    +      if ( libIt != Libraries.end() )
    +        libPos = Libraries.getPosition( libIt - Libraries.begin() );
    +      else
    +        libPos = 0;
    +      if ( fileIt != Files.end() )
    +        filePos = Files.getPosition( fileIt - Files.begin() );
    +      else
    +        filePos = 0;
    +
    +      if ( filePos != 0 && (libPos == 0 || filePos < libPos) ) {
    +        // Source File Is next
    +        ++fileIt;
    +      }
    +      else if ( libPos != 0 && (filePos == 0 || libPos < filePos) ) {
    +        // Library is next
    +        ++libIt;
    +      }
    +      else
    +        break; // we're done with the list
    +    }
    +  }

    +

    Note that, for compatibility reasons, the cl::opt also supports an + unsigned getPosition() option that will provide the absolute position + of that option. You can apply the same approach as above with a + cl::opt and a cl::list option as you can with two lists.

    +
    +
    The cl::ConsumeAfter modifier