File: LanguageMapper.py

package info (click to toggle)
synopsis 0.8.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,112 kB
  • ctags: 12,996
  • sloc: cpp: 34,254; ansic: 33,620; python: 10,975; sh: 7,261; xml: 6,369; makefile: 773; asm: 445
file content (33 lines) | stat: -rw-r--r-- 983 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# $Id: LanguageMapper.py,v 1.3 2003/11/11 06:03:59 stefan Exp $
#
# Copyright (C) 2000 Stefan Seefeld
# Copyright (C) 2000 Stephen Davies
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

import string

from Synopsis.Processor import Processor, Parameter
from Synopsis import AST, Type, Util

class LanguageMapper(Processor):

   def execute(self, ast):
      declarations = ast.declarations()
      langs = {}
      for decl in declarations:
         lang = decl.language()
         if langs.has_key(lang):
            scope = langs[lang]
         else:
            scope = AST.Module('',-1,lang,'Language',('%s Namespace'%lang,))
            langs[lang] = scope
         scope.declarations().append(decl)
      keys = langs.keys()
      # TODO: allow user to specify sort order here
      keys.sort()
      declarations[:] = map(lambda key, dict=langs: dict[key], keys)

linkerOperation = LanguageMapper