Browse Source

improve debug dump of compiled templates.

avoid duplicate entries in ast info.

add trace message on includes.
Andreas Stenius 11 years ago
parent
commit
04595cf319
2 changed files with 12 additions and 9 deletions
  1. 9 6
      src/erlydtl_beam_compiler.erl
  2. 3 3
      src/erlydtl_compiler_utils.erl

+ 9 - 6
src/erlydtl_beam_compiler.erl

@@ -276,7 +276,9 @@ maybe_debug_template(Forms, Context) ->
             Options = Context#dtl_context.compiler_options,
             Options = Context#dtl_context.compiler_options,
             ?LOG_DEBUG("Compiler options: ~p~n", [Options], Context),
             ?LOG_DEBUG("Compiler options: ~p~n", [Options], Context),
             try
             try
-                Source = erl_prettypr:format(erl_syntax:form_list(Forms)),
+                Source = erl_prettypr:format(
+                           erl_syntax:form_list(Forms),
+                           [{ribbon, 100}, {paper, 200}]),
                 SourceFile = lists:concat(
                 SourceFile = lists:concat(
                                [proplists:get_value(source, Options),".erl"]),
                                [proplists:get_value(source, Options),".erl"]),
                 File = case proplists:get_value(
                 File = case proplists:get_value(
@@ -740,13 +742,13 @@ extension_ast(Tag, TreeWalker) ->
     end.
     end.
 
 
 
 
-with_dependencies([], Args) ->
-    Args;
-with_dependencies([Dependency | Rest], Args) ->
-    with_dependencies(Rest, with_dependency(Dependency, Args)).
+with_dependencies([], Ast) -> Ast;
+with_dependencies([Dependency | Rest], Ast) ->
+    with_dependencies(Rest, with_dependency(Dependency, Ast)).
 
 
 with_dependency(FilePath, {{Ast, Info}, TreeWalker}) ->
 with_dependency(FilePath, {{Ast, Info}, TreeWalker}) ->
-    {{Ast, Info#ast_info{dependencies = [FilePath | Info#ast_info.dependencies]}}, TreeWalker}.
+    Dependencies = [FilePath | Info#ast_info.dependencies],
+    {{Ast, Info#ast_info{ dependencies = Dependencies }}, TreeWalker}.
 
 
 
 
 empty_ast(TreeWalker) ->
 empty_ast(TreeWalker) ->
@@ -975,6 +977,7 @@ string_ast(Arg, Context) ->
 
 
 include_ast(File, ArgList, Scopes, #treewalker{ context=Context }=TreeWalker) ->
 include_ast(File, ArgList, Scopes, #treewalker{ context=Context }=TreeWalker) ->
     FilePath = full_path(File, Context#dtl_context.doc_root),
     FilePath = full_path(File, Context#dtl_context.doc_root),
+    ?LOG_TRACE("include file: ~s~n", [FilePath], Context),
     case parse_file(FilePath, Context) of
     case parse_file(FilePath, Context) of
         {ok, InclusionParseTree, CheckSum} ->
         {ok, InclusionParseTree, CheckSum} ->
             {NewScope, {ArgInfo, TreeWalker1}}
             {NewScope, {ArgInfo, TreeWalker1}}

+ 3 - 3
src/erlydtl_compiler_utils.erl

@@ -400,9 +400,9 @@ resolve_variable1([Scope|Scopes], VarName) ->
 
 
 merge_info1(1, _, _, Info) -> Info;
 merge_info1(1, _, _, Info) -> Info;
 merge_info1(FieldIdx, Info1, Info2, Info) ->
 merge_info1(FieldIdx, Info1, Info2, Info) ->
-    Value = lists:merge(
-              lists:sort(element(FieldIdx, Info1)),
-              lists:sort(element(FieldIdx, Info2))),
+    Value = lists:umerge(
+              lists:usort(element(FieldIdx, Info1)),
+              lists:usort(element(FieldIdx, Info2))),
     merge_info1(FieldIdx - 1, Info1, Info2, setelement(FieldIdx, Info, Value)).
     merge_info1(FieldIdx - 1, Info1, Info2, setelement(FieldIdx, Info, Value)).
 
 
 get_scope({_Id, Scope, _Values}) -> Scope;
 get_scope({_Id, Scope, _Values}) -> Scope;