Doc/message fixes.
[bpt/emacs.git] / lisp / cedet / ede / source.el
CommitLineData
acc33231
CY
1;; ede/source.el --- EDE source code object
2
cb758101 3;; Copyright (C) 2000, 2008, 2009 Free Software Foundation, Inc.
acc33231
CY
4
5;; Author: Eric M. Ludlam <zappo@gnu.org>
6;; Keywords: project, make
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;; Manage different types of source code. A master list of source code types
26;; will be maintained, and used to track target objects, what they accept,
27;; and what compilers can be used.
28
29(require 'eieio-base)
30
31;;; Code:
32(defclass ede-sourcecode (eieio-instance-inheritor)
33 ((name :initarg :name
34 :type string
35 :documentation
36 "The name of this type of source code.
37Such as \"C\" or \"Emacs Lisp\"")
38 (sourcepattern :initarg :sourcepattern
39 :initform ".*"
40 :type string
41 :documentation
42 "Emacs regexp matching sourcecode this target accepts.")
43 (auxsourcepattern :initarg :auxsourcepattern
44 :initform nil
45 :type (or null string)
46 :documentation
47 "Emacs regexp matching auxiliary source code this target accepts.
48Aux source are source code files needed for compilation, which are not compiled
49themselves.")
50 (enable-subdirectories :initarg :enable-subdirectories
51 :initform nil
52 :type boolean
53 :documentation
54 "Non nil if this sourcecode type uses subdirectories.
55If sourcecode always lives near the target creating it, this should be nil.
56If sourcecode can, or typically lives in a subdirectory of the owning
57target, set this to t.")
58 (garbagepattern :initarg :garbagepattern
59 :initform nil
60 :type list
61 :documentation
62 "Shell file regexp matching files considered as garbage.
63This is a list of items added to an `rm' command when executing a `clean'
64type directive.")
65 )
66 "Description of some type of source code.
67Objects will use sourcecode objects to define the types of source
68that they are willing to use.")
69
70(defvar ede-sourcecode-list nil
71 "The master list of all EDE compilers.")
72
73;;; Methods
74;;
75(defmethod initialize-instance :AFTER ((this ede-sourcecode) &rest fields)
76 "Make sure that all ede compiler objects are cached in
77`ede-compiler-list'."
78 (let ((lst ede-sourcecode-list))
79 ;; Find an object of the same name.
80 (while (and lst (not (string= (oref this name) (oref (car lst) name))))
81 (setq lst (cdr lst)))
82 (if lst
83 ;; Replace old definition
84 (setcar lst this)
85 ;; Add to the beginning of the list.
86 (setq ede-sourcecode-list (cons this ede-sourcecode-list)))))
87
88(defmethod ede-want-file-p ((this ede-sourcecode) filename)
89 "Return non-nil if sourcecode definition THIS will take FILENAME."
90 (or (ede-want-file-source-p this filename)
91 (ede-want-file-auxiliary-p this filename)))
92
93(defmethod ede-want-file-source-p ((this ede-sourcecode) filename)
94 "Return non-nil if THIS will take FILENAME as an auxiliary ."
95 (let ((case-fold-search nil))
96 (string-match (oref this sourcepattern) filename)))
97
98(defmethod ede-want-file-auxiliary-p ((this ede-sourcecode) filename)
99 "Return non-nil if THIS will take FILENAME as an auxiliary ."
100 (let ((case-fold-search nil))
101 (and (slot-boundp this 'auxsourcepattern)
102 (oref this auxsourcepattern)
103 (string-match (oref this auxsourcepattern) filename))))
104
105(defmethod ede-want-any-source-files-p ((this ede-sourcecode) filenames)
106 "Return non-nil if THIS will accept any source files in FILENAMES."
107 (let (found)
108 (while (and (not found) filenames)
109 (setq found (ede-want-file-source-p this (pop filenames))))))
110
111(defmethod ede-want-any-auxiliary-files-p ((this ede-sourcecode) filenames)
112 "Return non-nil if THIS will accept any aux files in FILENAMES."
113 (let (found)
114 (while (and (not found) filenames)
115 (setq found (ede-want-file-auxiliary-p this (pop filenames))))))
116
117(defmethod ede-want-any-files-p ((this ede-sourcecode) filenames)
118 "Return non-nil if THIS will accept any files in FILENAMES."
119 (let (found)
120 (while (and (not found) filenames)
121 (setq found (ede-want-file-p this (pop filenames))))))
122
123(defmethod ede-buffer-header-file ((this ede-sourcecode) filename)
124 "Return a list of file names of header files for THIS with FILENAME.
125Used to guess header files, but uses the auxsource regular expression."
126 (let ((dn (file-name-directory filename))
127 (ts (file-name-sans-extension (file-name-nondirectory filename)))
128 (ae (oref this auxsourcepattern)))
129 (if (not ae)
130 nil
131 (directory-files dn t (concat (regexp-quote ts) ae)))))
132
133;;; Utility functions
134;;
135(when nil
136 ;; not used at the moment.
137(defun ede-source-find (name)
138 "Find the sourcecode object based on NAME."
139 (object-assoc name :name ede-sourcecode-list))
140
141(defun ede-source-match (file)
a785b776 142 "Find the list of sourcecode objects which matches FILE."
acc33231
CY
143 (let ((lst ede-sourcecode-list)
144 (match nil))
145 (while lst
146 ;; ede-file-mine doesn't exist yet
147 (if (ede-file-mine (car lst) file)
148 (setq match (cons (car lst) match)))
149 (setq lst (cdr lst)))
150 match))
151)
152;;; Master list of source code types
153;;
154;; This must appear at the end so that the init method will work.
155(defvar ede-source-scheme
156 (ede-sourcecode "ede-source-scheme"
157 :name "Scheme"
158 :sourcepattern "\\.scm$")
159 "Scheme source code definition.")
160
161;;(defvar ede-source-
162;; (ede-sourcecode "ede-source-"
163;; :name ""
164;; :sourcepattern "\\.$"
165;; :garbagepattern '("*."))
166;; " source code definition.")
167
168(provide 'ede/source)
169
170;;; ede/source.el ends here