From mboxrd@z Thu Jan 1 00:00:00 1970 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 p73KrEE5015561 for ; Wed, 3 Aug 2011 22:53:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnQCACS0OU7RVdy2mGdsb2JhbABCmBaPQwgUAQEBAQEICQ0HFCWBQAEBAQEDEgIsARsSCwEDDAYFCw0NISEBAREBBQEKEgYTEhCHTqNuCowxglSEfjuIbQIDBoY8BJJ7iWuCYTyDXg X-IronPort-AV: E=Sophos;i="4.67,312,1309730400"; d="scan'208";a="104629937" Received: from mail-vx0-f182.google.com ([209.85.220.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Aug 2011 22:53:08 +0200 Received: by mail-vx0-f182.google.com with SMTP id 10so1310197vxh.27 for ; Wed, 03 Aug 2011 13:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=yo94sMYdUU5gX+UpazRRxX0jCoZgcSu6A7KkYgerYW4=; b=J6K9b7Cqs24ODeSWldwp/dzXv1GQ5bNMOIiro6WzI+gvh6/+8fCvZHMBCBo+6Ez6Gp iO9HxKWDOZx+C9i8Z95V2JmJjbbGdMZWkRD41hHyk7MRHXl9MAaxzFM1wKZqtO5P9Lkr ng7Eyl0rAbl0gINTeCHnBnPuIvJ5JqUgbhW8Q= Received: by 10.52.98.197 with SMTP id ek5mr7227926vdb.298.1312404788130; Wed, 03 Aug 2011 13:53:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.159.10 with HTTP; Wed, 3 Aug 2011 13:52:48 -0700 (PDT) In-Reply-To: References: <4E37EBA3.6040800@fugmann.net> From: Gabriel Scherer Date: Wed, 3 Aug 2011 22:52:48 +0200 Message-ID: To: Till Varoquaux Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p73KrEE5015561 Subject: Re: [Caml-list] filename and line number. I called ocamldoc by hand, the signatures I was interested in are actually all contained in camlp4/Camlp4/Sig.ml so there is not much to do. On Wed, Aug 3, 2011 at 9:57 PM, Till Varoquaux wrote: > 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 >> >> >