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 p72Cjbgv010956 for ; Tue, 2 Aug 2011 14:45:39 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnUDAODwN07RVdQ2kGdsb2JhbABCmByPPggUAQEBAQkJDQcUBCGBQAEBAQEDEgIsARsSCwEDDAYFCw0NISIBEQEFAQoSBhMSEIdOoyYKjC+CVIUnO4htAgMGhjwEknuMTDyDXg X-IronPort-AV: E=Sophos;i="4.67,306,1309730400"; d="scan'208";a="104512416" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Aug 2011 14:45:38 +0200 Received: by vws18 with SMTP id 18so9453488vws.27 for ; Tue, 02 Aug 2011 05:45:37 -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=PdKKFQ3fLjJSdR0iMqN67bLXyX+JD+L6WNI78gHqM4I=; b=CPtwPbRNw5RBgC371ovzt/l/k3ImV2CeaK9odQFNKbabWIPYPoZatFA0qwwf2jstra Cx759X48/m6lBYydHhO0hNzHADSqjm1fiMuVg09WhVNs2UcL171WvoVvPE4aBaA+ijfX VCiFWY0VfLTfbT0h5QK0VF784CxeHXmH6VVbU= Received: by 10.52.98.2 with SMTP id ee2mr5623703vdb.461.1312289137139; Tue, 02 Aug 2011 05:45:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.167.3 with HTTP; Tue, 2 Aug 2011 05:45:17 -0700 (PDT) In-Reply-To: <4E37EBA3.6040800@fugmann.net> References: <4E37EBA3.6040800@fugmann.net> From: Gabriel Scherer Date: Tue, 2 Aug 2011 14:45:17 +0200 Message-ID: To: Anders Fugmann 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 p72Cjbgv010956 Subject: Re: [Caml-list] filename and line number. 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 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 > >