All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jon Loeliger <jdl-CYoMK+44s/E@public.gmane.org>
To: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A@public.gmane.org
Subject: [PATCH 3/9 V3] Enhance source position implementation.
Date: Fri, 26 Sep 2008 15:25:42 -0500	[thread overview]
Message-ID: <1222460748-20127-4-git-send-email-jdl@jdl.com> (raw)
In-Reply-To: <1222460748-20127-3-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>

Implemented some print and copy routines.
Made empty srcpos objects that will be used later.
Protected .h file from multiple #include's.

Signed-off-by: Jon Loeliger <jdl-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 srcpos.c |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 srcpos.h |   19 ++++++++++++
 2 files changed, 107 insertions(+), 7 deletions(-)

diff --git a/srcpos.c b/srcpos.c
index 9641b76..59d1835 100644
--- a/srcpos.c
+++ b/srcpos.c
@@ -23,12 +23,29 @@
 /*
  * Like yylineno, this is the current open file pos.
  */
-
 struct dtc_file *srcpos_file;
 
-static int dtc_open_one(struct dtc_file *file,
-                        const char *search,
-                        const char *fname)
+/*
+ * The empty source position.
+ */
+
+struct dtc_file dtc_empty_file = {
+	.dir = NULL,
+	.name = "<no file>",
+	.file = NULL
+};
+
+srcpos srcpos_empty = {
+	.first_line = 0,
+	.first_column = 0,
+	.last_line = 0,
+	.last_column = 0,
+	.file = &dtc_empty_file
+};
+
+
+static int
+dtc_open_one(struct dtc_file *file, const char *search, const char *fname)
 {
 	char *fullname;
 
@@ -53,8 +70,8 @@ static int dtc_open_one(struct dtc_file *file,
 }
 
 
-struct dtc_file *dtc_open_file(const char *fname,
-                               const struct search_path *search)
+struct dtc_file *
+dtc_open_file(const char *fname, const struct search_path *search)
 {
 	static const struct search_path default_search = { NULL, NULL, NULL };
 
@@ -106,7 +123,9 @@ fail:
 	die("Couldn't open \"%s\": %s\n", fname, strerror(errno));
 }
 
-void dtc_close_file(struct dtc_file *file)
+
+void
+dtc_close_file(struct dtc_file *file)
 {
 	if (fclose(file->file))
 		die("Error closing \"%s\": %s\n", file->name, strerror(errno));
@@ -114,3 +133,65 @@ void dtc_close_file(struct dtc_file *file)
 	free(file->dir);
 	free(file);
 }
+
+
+srcpos *
+srcpos_copy(srcpos *pos)
+{
+	srcpos *pos_new;
+
+	pos_new = xmalloc(sizeof(srcpos));
+	memcpy(pos_new, pos, sizeof(srcpos));
+
+	return pos_new;
+}
+
+
+
+void
+srcpos_dump(srcpos *pos)
+{
+	printf("file        : \"%s\"\n",
+	       pos->file ? (char *) pos->file : "<no file>");
+	printf("first_line  : %d\n", pos->first_line);
+	printf("first_column: %d\n", pos->first_column);
+	printf("last_line   : %d\n", pos->last_line);
+	printf("last_column : %d\n", pos->last_column);
+	printf("file        : %s\n", pos->file->name);
+}
+
+
+char *
+srcpos_string(srcpos *pos)
+{
+#	define POS_BUF_SIZE	(100)
+
+	const char *fname;
+	char buf[POS_BUF_SIZE];
+
+	if (pos->file && pos->file->name)
+		fname = pos->file->name;
+	else
+		fname = "<no-file>";
+
+	if (pos->first_line == pos->last_line) {
+		if (pos->first_column == pos->last_column) {
+			snprintf(buf, POS_BUF_SIZE, "%s %d:%d",
+				 fname, pos->first_line, pos->first_column);
+		} else {
+			snprintf(buf, POS_BUF_SIZE, "%s %d:%d-%d",
+				 fname, pos->first_line,
+				 pos->first_column, pos->last_column);
+		}
+
+	} else {
+		snprintf(buf, POS_BUF_SIZE, "%s %d:%d - %d:%d",
+			 fname,
+			 pos->first_line, pos->first_column,
+			 pos->last_line, pos->last_column);
+	}
+
+	return strdup(buf);
+
+#	undef POS_BUF_SIZE
+}
diff --git a/srcpos.h b/srcpos.h
index e17c7c0..3c39dd0 100644
--- a/srcpos.h
+++ b/srcpos.h
@@ -17,6 +17,9 @@
  *                                                                   USA
  */
 
+#ifndef _SRCPOS_H_
+#define _SRCPOS_H_
+
 /*
  * Augment the standard YYLTYPE with a filenum index into an
  * array of all opened filenames.
@@ -69,6 +72,16 @@ typedef struct YYLTYPE {
     while (YYID (0))
 
 
+typedef YYLTYPE srcpos;
+
+/*
+ * Fictional source position used for IR nodes that are
+ * created without otherwise knowing a true source position.
+ * For example,constant definitions from the command line.
+ */
+extern srcpos srcpos_empty;
+
+
 
 extern void yyerror(char const *);
 extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));
@@ -83,3 +96,9 @@ struct search_path {
 extern struct dtc_file *dtc_open_file(const char *fname,
                                       const struct search_path *search);
 extern void dtc_close_file(struct dtc_file *file);
+
+extern srcpos *srcpos_copy(srcpos *pos);
+extern char *srcpos_string(srcpos *pos);
+extern void srcpos_dump(srcpos *pos);
+
+#endif /* _SRCPOS_H_ */
-- 
1.6.0.90.g436ed

  parent reply	other threads:[~2008-09-26 20:25 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-26 20:25 [PATCH 0/9 V3] Implement a new DTS Source Language Jon Loeliger
     [not found] ` <1222460748-20127-1-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25   ` [PATCH 1/9 V3] Remove support for the legacy DTS source file format Jon Loeliger
     [not found]     ` <1222460748-20127-2-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25       ` [PATCH 2/9 V3] Add conditionalized debug() print macro Jon Loeliger
     [not found]         ` <1222460748-20127-3-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25           ` Jon Loeliger [this message]
     [not found]             ` <1222460748-20127-4-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25               ` [PATCH 4/9 V3] Add header files for new Internal Representation form Jon Loeliger
     [not found]                 ` <1222460748-20127-5-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25                   ` [PATCH 5/9 V3] Add most of the new IR implementation files Jon Loeliger
     [not found]                     ` <1222460748-20127-6-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25                       ` [PATCH 6/9 V3] Add the main IR evaluation implementation Jon Loeliger
     [not found]                         ` <1222460748-20127-7-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25                           ` [PATCH 7/9 V3] Introduce new DTS language Jon Loeliger
     [not found]                             ` <1222460748-20127-8-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25                               ` [PATCH 8/9 V3] Add documentation for the " Jon Loeliger
     [not found]                                 ` <1222460748-20127-9-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-26 20:25                                   ` [PATCH 9/9 V3] Test constant expressions in cell contexts Jon Loeliger
     [not found]                                     ` <1222460748-20127-10-git-send-email-jdl-CYoMK+44s/E@public.gmane.org>
2008-09-30  6:04                                       ` David Gibson
     [not found]                                         ` <20080930060418.GD18695-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-09-30 15:46                                           ` Jon Loeliger
2008-09-30 14:55                                   ` [PATCH 8/9 V3] Add documentation for the new DTS language Grant Likely
     [not found]                                     ` <20080930145537.GJ18313-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
2008-10-01  3:46                                       ` David Gibson
     [not found]                                         ` <20081001034656.GF30810-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-10-01  4:01                                           ` Warner Losh
     [not found]                                             ` <20080930.220151.41675821.imp-uzTCJ5RojNnQT0dZR+AlfA@public.gmane.org>
2008-10-01  4:22                                               ` David Gibson
2008-10-01 15:26                                           ` Scott Wood
     [not found]                                             ` <48E396A3.809-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2008-10-01 15:43                                               ` Warner Losh
     [not found]                                                 ` <20081001.094306.71131107.imp-uzTCJ5RojNnQT0dZR+AlfA@public.gmane.org>
2008-10-02  1:20                                                   ` David Gibson
2008-10-02  1:18                                               ` David Gibson
     [not found]                                                 ` <20081002011800.GI25598-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-10-02 15:22                                                   ` Scott Wood
     [not found]                                                     ` <20081002152242.GB22258-VKaLA/mbEU932VTgPCOETVjVikpgYyvb5NbjCUgZEJk@public.gmane.org>
2008-10-02 16:11                                                       ` David Gibson
     [not found]                                                         ` <20081002161150.GA14351-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-10-02 17:22                                                           ` Scott Wood
     [not found]                                                             ` <48E5036D.9040509-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2008-10-03  2:24                                                               ` David Gibson
     [not found]                                                                 ` <20081003022424.GG3002-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-10-03 15:27                                                                   ` Scott Wood
     [not found]                                                                     ` <20081003152700.GA9115-VKaLA/mbEU932VTgPCOETVjVikpgYyvb5NbjCUgZEJk@public.gmane.org>
2008-10-04  4:52                                                                       ` David Gibson
2008-10-02 19:50                                                       ` M. Warner Losh
     [not found]                                                         ` <20081002.135004.1723231860.imp-uzTCJ5RojNnQT0dZR+AlfA@public.gmane.org>
2008-10-02 20:46                                                           ` Jon Loeliger
2008-10-03  0:23                                                             ` David Gibson
2008-10-03  0:23                                                           ` David Gibson
     [not found]                                                             ` <20081003002337.GB3002-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-10-03  1:17                                                               ` M. Warner Losh
     [not found]                                                                 ` <20081002.191705.-108805802.imp-uzTCJ5RojNnQT0dZR+AlfA@public.gmane.org>
2008-10-03  4:38                                                                   ` David Gibson
2010-02-20 16:13                                           ` Grant Likely
     [not found]                                             ` <fa686aa41002200813o3fea9a34s198be367ad81b367-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-21  6:30                                               ` John Williams
2010-02-22  1:30                                               ` David Gibson
2010-02-22  6:26                                                 ` Grant Likely
     [not found]                                                   ` <fa686aa41002212226i4c83376cn8d88a045dd13fe00-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-22 16:13                                                     ` Yoder Stuart-B08248
     [not found]                                                       ` <9696D7A991D0824DBA8DFAC74A9C5FA305B2021A-ofAVchDyotYzzZk0BCvKg5jmvxFtTJ+o0e7PPNI6Mm0@public.gmane.org>
2010-02-22 21:59                                                         ` Grant Likely
     [not found]                                                           ` <fa686aa41002221359m4d857e4cn3a1c56c32a24d21d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-22 22:52                                                             ` Scott Wood
2010-02-23  2:04                                                             ` David Gibson
2010-03-01 19:15                                                             ` Grant Likely
     [not found]                                                               ` <fa686aa41003011115m1bb0b644g5014340f6c312ee9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-01 19:38                                                                 ` Scott Wood
2010-03-01 20:30                                                                 ` Stephen Neuendorffer
     [not found]                                                                   ` <4B8C2C4C.8070901@freescale <4B8C44C8.6000105@freescale.com>
     [not found]                                                                     ` <4B8C44C8.6000105-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2010-03-01 22:56                                                                       ` Stephen Neuendorffer
     [not found]                                                                         ` <7c070166-6cd5-48e4-ab8e-cb062e3dbb00-RaUQJvECHiusiP+nND6G/7jjLBE8jN/0@public.gmane.org>
2010-03-02  1:22                                                                           ` David Gibson
2010-03-02  0:10                                                                       ` Grant Likely
2010-03-02  1:19                                                                       ` David Gibson
2010-03-02  2:10                                                                         ` Grant Likely
     [not found]                                                                           ` <fa686aa41003011810w2e7b6278t6aaaf192f8d7c8c1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-02  2:16                                                                             ` Grant Likely
     [not found]                                                                               ` <fa686aa41003011816j534bf335o6fafe6f1c4a63436-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-02  4:20                                                                                 ` David Gibson
     [not found]                                                       ` <fa686aa41002221359m4d857e4cn3a1c56c32a24d21d@mail <4288fc0b-79a4-42fd-9e77-573dbad79210@SG2EHSMHS004.ehs.local>
     [not found]                                                         ` <4288fc0b-79a4-42fd-9e77-573dbad79210-RaUQJvECHiuXHCJdrdq+zrjjLBE8jN/0@public.gmane.org>
2010-03-01 21:06                                                           ` Scott Wood
     [not found]                                                             ` <4B8C2C4C.8070901-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2010-03-01 22:03                                                               ` Stephen Neuendorffer
     [not found]                                                                 ` <4d16ecf4-27b2-4c73-a3be-5b2a8ff95820-+Ck8Kgl/v0+J1bAq5m18RLjjLBE8jN/0@public.gmane.org>
2010-03-01 22:25                                                                   ` Grant Likely
     [not found]                                                                     ` <fa686aa41003011425i734ee434m95b62d57a271bd1f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-02  1:11                                                                       ` David Gibson
2010-03-01 22:18                                                               ` Grant Likely
     [not found]                                                                 ` <fa686aa41003011418x339884c9md61c49948b31a8d1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-01 22:26                                                                   ` Stephen Neuendorffer
     [not found]                                                                     ` <1012f9aa-1642-41ab-b8cd-a4ab4a7b269e-+Ck8Kgl/v0989VwWyyPjfbjjLBE8jN/0@public.gmane.org>
2010-03-02  0:03                                                                       ` Grant Likely
     [not found]                                                                         ` <fa686aa41003011603w12c0a7f1y88b5fc7a008af1d5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-02  0:13                                                                           ` Stephen Neuendorffer
     [not found]                                                                             ` <f9885aa5-5c11-4118-9980-f17378d7cbd5-RaUQJvECHiuXHCJdrdq+zrjjLBE8jN/0@public.gmane.org>
2010-03-02  1:25                                                                               ` David Gibson
2010-03-02  2:08                                                                               ` Grant Likely
     [not found]                                                                                 ` <fa686aa41003011808h586e3dc3x11ef14af9c6e5fb8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-02 17:06                                                                                   ` Scott Wood
2010-03-01 22:50                                                                   ` Scott Wood
2010-03-01 21:49                                                           ` Grant Likely
     [not found]                                                             ` <fa686aa41003011349i367a423cx2c59953e6afc9b75-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-01 22:15                                                               ` Mitch Bradley
     [not found]                                                                 ` <4B8C3C78.5010206-D5eQfiDGL7eakBO8gow8eQ@public.gmane.org>
2010-03-01 23:33                                                                   ` Grant Likely
     [not found]                                                                     ` <fa686aa41003011533x3d2d00abyb8d7cf33344a3bde-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-02  3:59                                                                       ` David Gibson
2010-03-01 22:17                                                               ` Stephen Neuendorffer
     [not found]                                                                 ` <72f497af-412c-4a05-90c2-5df0be00d93f-+Ck8Kgl/v09CYczPSvLbDrjjLBE8jN/0@public.gmane.org>
2010-03-01 23:42                                                                   ` Grant Likely
2010-03-02 23:12                                                                   ` David Gibson
2010-03-03 16:18                                                                     ` Grant Likely
2010-02-23  1:47                                                     ` David Gibson
2010-02-23  2:17                                                       ` Grant Likely
     [not found]                                                         ` <fa686aa41002221817s5f15dc4cy5ab873a61de2cb2f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-23  4:10                                                           ` David Gibson
2008-10-02  8:25                               ` [PATCH 7/9 V3] Introduce " David Gibson
2008-09-30  6:03                   ` [PATCH 4/9 V3] Add header files for new Internal Representation form David Gibson
2008-09-30  6:00               ` [PATCH 3/9 V3] Enhance source position implementation David Gibson
2008-09-30  5:57       ` [PATCH 1/9 V3] Remove support for the legacy DTS source file format David Gibson
     [not found]         ` <20080930055716.GA18695-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-09-30 16:30           ` Scott Wood
     [not found]             ` <48E2541B.1000801-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2008-10-01  1:26               ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1222460748-20127-4-git-send-email-jdl@jdl.com \
    --to=jdl-cyomk+44s/e@public.gmane.org \
    --cc=devicetree-discuss-mnsaURCQ41sdnm+yROfE0A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.