Commit cb0aa7df authored by gourne_o's avatar gourne_o
Browse files

from Olivier Gournet <gourne_o@lrde.epita.fr>

	* src/disamb/sslext/ScopedFiniteMap.str: New file.
	* src/disamb/specifier/Makefile.am: Add path in include.
	* src/disamb/specifier/afcxx-specifier.str,
	* src/disamb/namespace/afcxx-namespace.str,
	* src/disamb/disambiguate/afcxx-disambiguate.str: 
	Save and reload symbol tables.
	* src/disamb/disambiguate/ClassDefinition.str,
	* src/disamb/disambiguate/BaseTraverse.str,
	* src/disamb/disambiguate/NamespaceDefinition.str,
	* src/disamb/disambiguate/LocalOrGlobal.str,
	* src/disamb/disambiguate/EnumDefinition.str,
	* src/disamb/disambiguate/ClassTraverse.str,
	* src/disamb/disambiguate/VariableDeclarator.str,
	* src/disamb/disambiguate/TemplateClassDefinition.str,
	* src/disamb/disambiguate/TypeDeclarator.str,
	* src/disamb/disambiguate/TemplateFunctionDefinition.str,
	* src/disamb/disambiguate/Lookup.str,
	* src/disamb/disambiguate/TemplateTraverse.str,
	* src/disamb/disambiguate/GetKey.str,
	* src/disamb/disambiguate/NamespaceTraverse.str,
	* src/disamb/disambiguate/TemplateClassTraverse.str,
	* src/disamb/disambiguate/TemplateFunctionTraverse.str,
	* src/disamb/disambiguate/ClassOrNamespaceTraverse.str,
	* src/disamb/disambiguate/TemplateDefinition.str: Use map wrapper strategies.
	* src/parser/ParsePPDirective.str,
	* src/parser/parse-cxx.str: Rewrite with context dump and less temporary files.

2004-05-14  Olivier Gournet  <gourne_o@lrde.epita.fr>
parent 3947519c
/*
* afcxx-namespace.str:
* this file is a part of CxxGrammar from the Transformers project.
* Copyright (C) 2003 EPITA Research and Development Laboratory.
* Copyright (C) 2003, 2004 EPITA Research and Development Laboratory.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -27,6 +27,7 @@ imports
imports
NamespaceDefinition
ScopedFiniteMap
rules
......@@ -41,14 +42,29 @@ strategies
init = Init
finish = Finish
afcxx-namespace = iowrap (init-name-space (!"$");
init-name-space (!"table");
begin-scope (!"$");
begin-scope (!"table");
init;
namespace-definition;
finish;
end-scope (!"table");
end-scope (!"$");
exit-name-space (!"table");
exit-name-space (!"$"))
afcxx-namespace = io-wrap (symbtable-option,
where (< get-config > ("--symtable")
; ( restore-maplist
<+ (
my-init-name-space (!"$")
; my-init-name-space (!"table")
; begin-scope (!"$")
; begin-scope (!"table")
; init
)
)
)
; namespace-definition
; where (< get-config > ("--symtable"); save-maplist)
; finish
; end-scope (!"table")
; end-scope (!"$")
; exit-name-space (!"table")
; exit-name-space (!"$")
)
symbtable-option =
ArgOption("--symtable"
, where(<set-config> ("--symtable", <id>))
, !"--symtable Specify the symbol file to load"
)
......@@ -23,6 +23,7 @@ SCFLAGS = --main $* --verbose 0
STRINCLUDES = -I $(ASFIX_TOOLS)/share/asfix-tools \
-I $(top_srcdir)/lib/cxx \
-I $(top_builddir)/src/sig \
-I $(top_builddir)/src/disamb/sslext \
-I $(top_builddir)/src/strategocxx \
--asfix
libexec_PROGRAMS= afcxx-specifier
......
......@@ -27,6 +27,7 @@ imports
imports
Specifier
ScopedFiniteMap
rules
......@@ -41,10 +42,23 @@ strategies
init = Init
finish = Finish
afcxx-specifier = iowrap (init-name-space (!"$count");
begin-scope (!"$count");
init;
topdown (try (specifier));
finish;
end-scope (!"$count");
exit-name-space (!"$count"))
afcxx-specifier = io-wrap (symbtable-option,
where (< get-config > ("--symtable")
; ( restore-maplist
<+ my-init-name-space (!"$count")
; begin-scope (!"$count")
; init
)
)
; topdown (try (specifier))
; finish
; where (< get-config > ("--symtable"); save-maplist)
; end-scope (!"$count")
; exit-name-space (!"$count")
)
symbtable-option =
ArgOption("--symtable"
, where(<set-config> ("--symtable", <id>))
, !"--symtable Specify the symbol file to load"
)
/*
* ScopedFiniteMap.str:
* this file is a part of CxxGrammar from the Transformers project.
* Copyright (C) 2004 EPITA Research and Development Laboratory.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
module ScopedFiniteMap
imports
lib
xtc-lib
strategies
my-init-name-space(ns) =
where (< table-push > ("$maplist", <ns>, ""))
; init-name-space (ns)
my-exit-name-space(ns) =
where (< table-remove > ("$maplist", <ns>))
; exit-name-space (ns)
my-assert(ns) = where ( < rewrite (!"$maplist") > (<ns>)
<+ < assert (!"$maplist") > (<ns>, "")
)
; assert(ns)
my-table-create =
where (< table-push > ("$maplist", <id>, ""))
; table-create
(*
** Dump all memorized symbol tables on a file.
*)
save-maplist = ?filename
; < table-getlist > "$maplist"
; !(<id>, [ <id> ])
; foldl ({x, y, z:
?((x, y), z)
; <table-getlist> (x)
; <conc> (z, [[ x | <id> ]])
})
; write-to
; rename-to (!filename)
(*
** To avoid nasty error from 'read-from', when reading an empty file.
*)
check-empty-file = <fopen> (<id>, "r") => s
; (fgetc < <fclose> s + <fclose> s; fail)
(*
** Restore a previous context.
*)
restore-maplist = ?filename
; check-empty-file
; <read-from> FILE(filename)
; ?[ symtab | content ]
; < table-putlist > ("$maplist", symtab)
; < map ({x, y:
?[x | y]; < table-putlist > (x, y)
})
> content
......@@ -35,7 +35,7 @@ strategies
(*
** xtc-cat is unuseable because it writes output file on
** current directory, we better want it in /tmp
** current directory, we better want it in /tmp.
*)
xtc-my-cat:
in-files -> FILE(file)
......@@ -45,59 +45,46 @@ strategies
; <map(File-as-fd(<fdcopy> (<id>, fdout)))> in-files
; <xtc-close-fd> fdout
(*
** write the parse tree of a 0-byte file size
*)
new-empty-file = xtc-new-file => f
; !parsetree(|TranslationUnit[ ]|, 0)
; !(<open-stream> (f, "w"), <id>)
; write-to-stream
; fclose
; !FILE(f)
create-symb-file =
< new-temp-file > () => (f1, _)
; < new-temp-file > () => (f2, _)
; < new-temp-file > () => (f3, _)
; < assert (!TempFiles) > (f1, ())
; < assert (!TempFiles) > (f2, ())
; < assert (!TempFiles) > (f3, ())
; !(f1, f2, f3)
rules
(*
** keep the interesting part of the first aterm
*)
Asfix-get : |TranslationUnit[ ~Declaration+: a ~ ]| -> 0
Asfix-get : a @ |TranslationUnit[ ]| -> a
where
rules ( GetPiece : _ -> a )
Asfix-get : a @ |TranslationUnit[ ~Declaration+: b ~ ]| -> a
where
rules (GetFirst : _ -> a )
rules ( GetPiece : _ -> a )
strategies
(*
** concatenate the two aterm
** Concatenate two aterm.
*)
Asfix-cat : |TranslationUnit[ ~Declaration+: a ~ ]|
Asfix-cat : (|TranslationUnit[ ~Declaration+: a ~ ]|, |TranslationUnit[ ~Declaration+: b ~ ]|)
-> |TranslationUnit[
~Declaration+: c ~
~Declaration+: a ~ ]|
where
<GetFirst> () => c
~Declaration+: a ~
~Declaration+: b ~ ]|
Asfix-cat : |TranslationUnit[ ]|
-> |TranslationUnit[ Declaration61-iter ]|
where
<GetFirst> () => Declaration61-iter
Asfix-cat : (|TranslationUnit[ ]|, |TranslationUnit[ ~Declaration+: b ~ ]|)
-> |TranslationUnit[ ~Declaration+: b ~ ]|
Asfix-cat : |TranslationUnit[ ~Declaration+: a ~ ]|
Asfix-cat : (|TranslationUnit[ ~Declaration+: a ~ ]|, |TranslationUnit[ ]|)
-> |TranslationUnit[ ~Declaration+: a ~ ]|
where
<not(GetFirst)> ()
Asfix-cat : |TranslationUnit[ ]|
Asfix-cat : (|TranslationUnit[ ]|, |TranslationUnit[ ]|)
-> |TranslationUnit[ ]|
where
<not(GetFirst)> ()
strategies
sglrize-files = !(<id>, []); rec x (
\ ([f1], l) -> [<sglr-cmd> f1 | l] \
<+ \ ([f1 | r], l) -> <x> (r, [<sglr-cmd> f1 | l]) \
<+ \ ([f1, f2 | r], l) -> <x> ([<xtc-my-cat> [f1, f2] | r], l) \
<+ giving-up
)
(*
** Run cpp and split its output into a list of files.
*)
......@@ -117,20 +104,32 @@ strategies
; read-from
; where (map (FILE(<assert(!TempFiles)> (<id>, ()))))
inside(s) = {| GetFirst :
?(b, a)
; xtc-new-file => outf
; <read-from> a
sglrize-files = !(<id>, []); rec x (
\ ([f1], l) -> [<sglr-cmd> f1 | l] \
<+ \ ([f1 | r], l) -> <x> (r, [<sglr-cmd> f1 | l]) \
<+ \ ([f1, f2 | r], l) -> <x> ([<xtc-my-cat> [f1, f2] | r], l) \
<+ giving-up
)
parse-chunk(s, symbfiles) = {| GetPiece :
?(currfile, parsedterm)
; if-verbose1 (< debug (!"\n====== process ") > currfile)
; < read-from > currfile
; < s > (< id >, < symbfiles>)
; alltd (Asfix-get)
; <read-from> b
; alltd (Asfix-cat)
; s
; !(parsedterm, < GetPiece >)
; Asfix-cat
|}
preproc-parse(s) =
where ( create-symb-file => symbfiles
; xtc-new-file => outf )
; preproc-cmd => ppfilelist
; sglrize-files
; foldr (!|TranslationUnit[ ]|, parse-chunk(s, !symbfiles))
; !parsetree(<id>, 0)
; !(<open-stream> (outf, "w"), <id>)
; write-to-stream
; fclose
; !FILE(outf)
|}
preproc-parse(s) = preproc-cmd => ppfilelist
; sglrize-files
; foldr (<new-empty-file> (), inside(s))
......@@ -70,20 +70,22 @@ strategies
; <xtc-exit> 1
parse = xtc-transform(!"ambdown", pass-verbose)
parse = ?(file, (symbol-file-disamb, symbol-file-ns, symbol-file-spec))
; !file
; xtc-transform(!"ambdown", pass-verbose)
; xtc-transform(!"afcxx-desugar", pass-verbose)
; xtc-transform(!"afcxx-anonymous", pass-verbose)
; xtc-transform(!"afcxx-simpledeclaration", pass-verbose)
; xtc-transform(!"afcxx-purespecifier", pass-verbose)
; xtc-transform(!"afcxx-namespace", pass-verbose)
; xtc-transform(!"afcxx-namespace", <conc> (["--symtable", symbol-file-ns], <pass-verbose>))
; xtc-transform(!"afcxx-declaration", pass-verbose)
; xtc-transform(!"afcxx-resolve", pass-verbose)
; xtc-transform(!"afcxx-classparam", pass-verbose)
; xtc-transform(!"afcxx-resolve", pass-verbose)
; xtc-transform(!"afcxx-specifier", pass-verbose)
; xtc-transform(!"afcxx-specifier", <conc> (["--symtable", symbol-file-spec], <pass-verbose>))
; xtc-transform(!"afcxx-validtypes", pass-verbose)
; xtc-transform(!"afcxx-resolve", pass-verbose)
; xtc-transform(!"afcxx-disambiguate", pass-verbose)
; xtc-transform(!"afcxx-disambiguate", <conc> (["--symtable", symbol-file-disamb], <pass-verbose>))
; xtc-transform(!"afcxx-anonymous", <conc> (["--unset"], <pass-verbose>))
io-parse-cxx =
......@@ -91,12 +93,12 @@ strategies
if-dxx("strict") < parse-dxx
+(
( test (<get-config> "--skip-pp")
< sglr-cmd; parse
< sglr-cmd; <parse> (<id>, <create-symb-file> ())
+ preproc-parse (parse)
)
; where(<get-config> "--amb" <+
(read-from; topdown(try(amb(id); !1; xtc-exit))));
(if-out("asfix") <+
; where (<get-config> "--amb" <+
(read-from; topdown(try(amb(id); !1; xtc-exit))))
; (if-out("asfix") <+
(if-out("dxx") <
( xtc-transform(!"afcxx2afdxx", pass-verbose)
; xtc-asfix-yield)
......@@ -119,9 +121,9 @@ strategies
)
pp-option =
Option("-p" + "--skip-pp"
Option("--skip-pp"
, where(<set-config> ("--skip-pp", <id>))
, !"-p | --skip-pp Skip pre-processor pass"
, !"--skip-pp Skip pre-processor pass"
)
out-option =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment