Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Core/Action.py
1| # $Id: Action.py,v 1.4 2002/11/19 03:44:08 chalky Exp $
2| #
3| # This file is a part of Synopsis.
4| # Copyright (C) 2000, 2001 Stefan Seefeld
5| # Copyright (C) 2000, 2001 Stephen Davies
6| #
7| # Synopsis is free software; you can redistribute it and/or modify it
8| # under the terms of the GNU General Public License as published by
9| # the Free Software Foundation; either version 2 of the License, or
10| # (at your option) any later version.
11| #
12| # This program is distributed in the hope that it will be useful,
13| # but WITHOUT ANY WARRANTY; without even the implied warranty of
14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15| # General Public License for more details.
16| #
17| # You should have received a copy of the GNU General Public License
18| # along with this program; if not, write to the Free Software
19| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20| # 02111-1307, USA.
21| #
22| # $Log: Action.py,v $
23| # Revision 1.4 2002/11/19 03:44:08 chalky
24| # Changed SourcePath to SourceRule, included an Exclude rule
25| #
26| # Revision 1.3 2002/04/26 01:21:13 chalky
27| # Bugs and cleanups
28| #
29| # Revision 1.2 2001/11/07 05:58:21 chalky
30| # Reorganised UI, opening a .syn file now builds a simple project to view it
31| #
32| # Revision 1.1 2001/11/05 06:52:11 chalky
33| # Major backside ui changes
34| #
35|
36| """Actions control the functionality of the stand-alone Synopsis. The
37| functionality is divided into Actions, which are responsible for different
38| steps such as checking source files, parsing, linking, formatting and
39| caching.
40|
41| The actual Action objects only contain the information needed to perform the
42| actions, but are as lightweight as possible otherwise. This is because there
43| is potentially a lot of memory associated with each stage, which should be
44| allocated as late as possible and freed as soon as possible."""
45|
46| import os, stat, string, re
47|
48| class Action:
49| """A Synopsis Action, ie: parsing, linking, formatting etc"""
50| def __init__(self, x, y, name):
51| self.__x = x
52| self.__y = y
53| self.__name = name
54| self.__inputs = []
55| self.__outputs = []
56|
57| # These are to do with the GUI, and may be moved out at some stage...
58| def x(self): return self.__x
59| def y(self): return self.__y
60| def pos(self): return self.__x, self.__y
61| def move_to(self, x, y): self.__x = x; self.__y = y
62| def move_by(self, dx, dy): self.__x = self.__x+dx; self.__y = self.__y+dy
63|
64| # Proper action methods
65| def name(self): return self.__name
66| def set_name(self, name): self.__name = name
67| def inputs(self): return self.__inputs
68| def outputs(self): return self.__outputs
69| def accept(self, visitor): visitor.visitAction(self)
70|
71| class ActionVisitor:
72| """A visitor for the Action hierarchy"""
73| def visitAction(self, action): pass
74| def visitSource(self, action): pass
75| def visitParser(self, action): pass
76| def visitLinker(self, action): pass
77| def visitCacher(self, action): pass
78| def visitFormat(self, action): pass
79|
80| class SourceRule:
81| """Base class for a source path"""
82| def __init__(self, pathtype, dir, glob=None):
83| if pathtype not in ('Simple', 'Dir', 'Base'):
84| raise ValueError, 'pathtype not valid'
85| self.type = pathtype
86| self.dir = dir
87| self.glob = glob
88| def clone(self):
89| """Returns a clone of this sourcepath."""
90| pass
91|
92| class SimpleSourceRule (SourceRule):
93| def __init__(self, files):
94| """Creates a Simple source rule with a copy of the files list, which
95| is a list of filenames to include"""
96| self.type = 'Simple'
97| self.files = list(files)
98| def clone(self):
99| return SimpleSourceRule(self.files)
100|
101| class GlobSourceRule (SourceRule):
102| def __init__(self, dirs, glob, recursive):
103| """Creates a Glob source rule with a copy of the dirs list which is a
104| list of base directories. The glob is a glob expression (string) for
105| files to match in each directory. If the boolean recursive is set,
106| then subdirectories are also searched."""
107| self.type = 'Glob'
108| self.dirs = list(dirs)
109| self.glob = glob
110| self.recursive = recursive
111| def clone(self):
112| return GlobSourceRule(self.dirs, self.glob, self.recursive)
113|
114| class ExcludeSourceRule (SourceRule):
115| def __init__(self, glob):
116| """Creates an Exclude source rule with the given glob expression.
117| Existing filenames which match the glob will be removed."""
118| self.type = 'Exclude'
119| self.glob = glob
120| def clone(self):
121| return ExcludeSourceRule(self.glob)
122|
123| class SourceAction (Action):
124| """A Synopsis Action that loads source files"""
125| def __init__(self, x, y, name):
126| Action.__init__(self, x, y, name)
127| self.__rules = []
128| def rules(self):
129| """Returns a list of rules. Each rule is a subclass of a SourceRule
130| object with at least a 'type' attribute to determine the type of rule"""
131| return self.__rules
132| def accept(self, visitor): return visitor.visitSource(self)
133|
134| class ParserAction (Action):
135| """A Synopsis Action that parses source files.
136|
137| Each parser object has a config object, which is passed to the Parser
138| module. For a default config object, use Synopsis.Config.Base.xxx where
139| xxx is the Parser module."""
140| def __init__(self, x, y, name):
141| Action.__init__(self, x, y, name)
142| self.__config = None
143| def config(self):
144| """Returns the config object for this Parser"""
145| return self.__config
146| def set_config(self, config):
147| """Sets the config object for this Parser."""
148| self.__config = config
149| def accept(self, visitor): return visitor.visitParser(self)
150|
151| class LinkerAction (Action):
152| """A Synopsis Action that links ASTs"""
153| def __init__(self, x, y, name):
154| Action.__init__(self, x, y, name)
155| self.__config = None
156| def config(self):
157| """Returns the config object for this Linker"""
158| return self.__config
159| def set_config(self, config):
160| """Sets the config object for this Linker."""
161| self.__config = config
162| def accept(self, visitor): return visitor.visitLinker(self)
163|
164| class CacherAction (Action):
165| """A Synopsis Action that caches ASTs to disk. It can optionally be used
166| to load from a .syn file on disk, by setting the file attribute."""
167| def __init__(self, x, y, name):
168| Action.__init__(self, x, y, name)
169| self.dir = '.'
170| self.file = None
171| def accept(self, visitor): return visitor.visitCacher(self)
172|
173| class FormatAction (Action):
174| """A Synopsis Action that formats ASTs into other media"""
175| def __init__(self, x, y, name):
176| Action.__init__(self, x, y, name)
177| self.__config = None
178| def config(self):
179| """Returns the config object for this Formatter"""
180| return self.__config
181| def set_config(self, config):
182| """Sets the config object for this Formatter."""
183| self.__config = config
184| def accept(self, visitor): return visitor.visitFormat(self)
185|
186|