Permalink
Browse files

Generated forms fixes.

The most important part is that without certain epp magic typed records
will come out invalid.

Other things are important for correct parse transformations
  • Loading branch information...
1 parent 53e5750 commit 0d4bb741b40d65f2a4752ee981657909c2c64824 @yrashk yrashk committed Feb 3, 2012
Showing with 18 additions and 4 deletions.
  1. +18 −4 src/dynamic_compile.erl
@@ -93,7 +93,7 @@ from_string(CodeStr, CompileFormsOptions) ->
%% In this case, #2 is meaningless.
IncludeSearchPath = ["." | reverse([Dir || {i, Dir} <- CompileFormsOptions])],
{RevForms, _OutMacroDict} = scan_and_parse(CodeStr, Filename, 1, [], InitMD, IncludeSearchPath),
- Forms = reverse(RevForms),
+ Forms = [{attribute, 0, file, {"compiled_from_string", 0}}|reverse([{eof, 0}|RevForms])],
%% note: 'binary' is forced as an implicit option, whether it is provided or not.
case compile:forms(Forms, CompileFormsOptions) of
@@ -124,8 +124,9 @@ scan_and_parse([], _CurrFilename, _CurrLine, RevForms, MacroDict, _IncludeSearch
scan_and_parse(RemainingText, CurrFilename, CurrLine, RevForms, MacroDict, IncludeSearchPath) ->
case scanner(RemainingText, CurrLine, MacroDict) of
{tokens, NLine, NRemainingText, Toks} ->
- {ok, Form} = erl_parse:parse_form(Toks),
- scan_and_parse(NRemainingText, CurrFilename, NLine, [Form | RevForms], MacroDict, IncludeSearchPath);
+ {ok, Form0} = erl_parse:parse_form(Toks),
+ {Form, Forms} = normalize_record(Form0),
+ scan_and_parse(NRemainingText, CurrFilename, NLine, [ Form | Forms ++ RevForms], MacroDict, IncludeSearchPath);
{macro, NLine, NRemainingText, NMacroDict} ->
scan_and_parse(NRemainingText, CurrFilename, NLine, RevForms,NMacroDict, IncludeSearchPath);
{include, NLine, NRemainingText, IncludeFilename} ->
@@ -278,4 +279,17 @@ read_include_file(Filename, IncludeSearchPath) ->
binary_to_list(Data);
{error, Reason} ->
throw({failed_to_read_include_file, Reason, Filename, IncludeSearchPath})
- end.
+ end.
+
+normalize_record({attribute, La, record, {Record, Fields}} = Form) ->
+ case epp:normalize_typed_record_fields(Fields) of
+ {typed, NewFields} ->
+ {{attribute, La, record, {Record, NewFields}},
+ [{attribute, La, type,
+ {{record, Record}, Fields, []}}]};
+ not_typed ->
+ {Form, []}
+ end;
+normalize_record(Form) ->
+ {Form, []}.
+

0 comments on commit 0d4bb74

Please sign in to comment.