From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p73Jvtxl014282 for ; Wed, 3 Aug 2011 21:57:55 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AogDADKnOU7RVdQ2kGdsb2JhbABChEeTT49DCBQBAQEBCQkNBxQEIYFAAQEBAQMSAg8dAS0LAQMMAQUDAgsNAgIJHQICIQESAQUBChIGExIQh06jXQqLcYMUhQOJKAIDBoElhAeBEASSe4lrgmE8gT+COQ X-IronPort-AV: E=Sophos;i="4.67,312,1309730400"; d="scan'208";a="104627764" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Aug 2011 21:57:49 +0200 Received: by vws18 with SMTP id 18so1559442vws.27 for ; Wed, 03 Aug 2011 12:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=y3Oyg8gz9xOH9U8/yP91drmlD3dTeKroEe7lmm2TIlY=; b=bz80Uf9nv0b8ff5NFljOP7b4Jye5lGF29I2Xl7QJo0Ciwi+kiFjC/2d7nvZ15Ua/F7 cysgkrmHsqzay3rb/dRigx/FmZ0ZvCbYJpDuCVw5yi+aQuiUoL+O7WxOaTHF3//leiac 50Q6DTJXAq6BLxgQI3rixVfKlRm6Sj4iZLHUs= MIME-Version: 1.0 Received: by 10.52.173.210 with SMTP id bm18mr184210vdc.404.1312401468258; Wed, 03 Aug 2011 12:57:48 -0700 (PDT) Sender: till.varoquaux@gmail.com Received: by 10.52.181.1 with HTTP; Wed, 3 Aug 2011 12:57:48 -0700 (PDT) In-Reply-To: References: <4E37EBA3.6040800@fugmann.net> Date: Wed, 3 Aug 2011 15:57:48 -0400 X-Google-Sender-Auth: hmQQd6olHZC8V-8DccpQRHRAXvA Message-ID: From: Till Varoquaux To: Gabriel Scherer Cc: caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p73Jvtxl014282 X-Validation-by: till@pps.jussieu.fr Subject: Re: [Caml-list] filename and line number. On Tue, Aug 2, 2011 at 8:45 AM, Gabriel Scherer wrote: > There is a "macro" syntax extension that is distributed with Camlp4, > and can do basic cpp-like stuff, including __FILE__ and a __LOCATION__ > macros. > > For example, the following content, named test.ml: > >  let test = >    __LOCATION__ > > When processed through 'camlp4o pa_macro.cmo', will result in: > >  let test = Loc.of_tuple ("test.ml", 2, 13, 17, 2, 13, 29, false) > > (To compile:  ocamlc -pp 'camlp4o pa_macro.cmo' ...) > > The "Loc.of_tuple" call is a reference to a function implemented in > Camlp4 Loc module; if you make you project depend (at runtime, not > camlp4-time) on Camlp4 loc-handling libraries, you'll get functions to > manipulate the location and its information. You can also define your > own Loc module in test.ml: > >  module Loc = struct >    let of_tuple >      ((file_name, start_line, start_bol, start_off, stop_line, > stop_bol, stop_off, is_ghost) as loc) = >        loc >  end > >  let test = >    __LOCATION__ > > The source code (and some documentation in the head comment) for the > "macro" camlp4 extension is in > camlp4/Camlp4Parsers/Camlp4MacroParser.ml in the ocaml source tree. > > The meaning of the weird tuple arguments can be found in the Camlp4 > documentation. I have a not exactly up-to-date (I guess ocaml 3.11) > version of the documentation on my website, see: >  http://bluestorm.info/camlp4//camlp4-doc/Sig.Loc.html Having camlp4's ocamldoc is pretty nice. How did you generate those? Is there a makefile target? Till > > Finally, Martin Jambon also has its own "cppo" tools mimicking cpp, > which I suppose doesn't rely on camlp4, and has __FILE__ and __LINE__ > macros which may be in a more directly exploitable format. I have > never tried it though. See: >  http://martin.jambon.free.fr/cppo.html > > On Tue, Aug 2, 2011 at 2:20 PM, Anders Fugmann wrote: >> Hi, >> >> Do there exist a way to get filename and linenumber of the calling function >> - Or at least the of the current filename and line number? >> >> I guess this would involve a syntax camlp4 syntax extension, but I'm not a >> camlp4 wizard and google did not come up with any suggestions. >> >> Regards >> Anders Fugmann >> >> >> -- >> Caml-list mailing list.  Subscription management and archives: >> https://sympa-roc.inria.fr/wws/info/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> >> > > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >