|
|
@ -61,8 +61,8 @@ formsStr(CodeStr, CompileFormsOpts) -> |
|
|
|
|
|
|
|
IncludePath = ["." | reverse([Dir || {i, Dir} <- CompileFormsOpts])], |
|
|
|
case scanAndParse(CodeStr, Filename, 1, [], [], #{}, IncludePath) of |
|
|
|
{ok, RevForms, _OutMacroDict} -> |
|
|
|
Forms = [{attribute, 0, file, {"compiled_from_string", 0}} | reverse([{eof, 0} | RevForms])], |
|
|
|
{ok, RevForms, _OutMacroMap} -> |
|
|
|
Forms = reverse(RevForms), |
|
|
|
|
|
|
|
%% note: 'binary' is forced as an implicit option, whether it is provided or not. |
|
|
|
case compile:forms(Forms, CompileFormsOpts) of |
|
|
@ -73,7 +73,7 @@ formsStr(CodeStr, CompileFormsOpts) -> |
|
|
|
{error, [{_, Errors}], Warnings} -> |
|
|
|
{error, Errors, Warnings}; |
|
|
|
Other -> |
|
|
|
{error, Other, []} |
|
|
|
{error, {bat_return, Other}} |
|
|
|
end; |
|
|
|
{error, Errors} -> |
|
|
|
{error, Errors, []} |
|
|
@ -98,12 +98,12 @@ scanAndParse(RemainingText, CurrFilename, CurrLine, RevForms, Errors, MacroMap, |
|
|
|
{error, E} -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, [E | Errors], MacroMap, IncludeSearchPath) |
|
|
|
end; |
|
|
|
{macro, NLine, NRemainingText, NMacroDict} -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroDict, IncludeSearchPath); |
|
|
|
{Def, NLine, NRemainingText, NMacroDict} when Def =:= def; Def =:= endif; Def =:= else;Def =:= undef; Def =:= attribute; Def =:= vsn -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroDict, IncludeSearchPath); |
|
|
|
{vsn, NLine, NRemainingText, NMacroDict} -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroDict, IncludeSearchPath); |
|
|
|
{macro, NLine, NRemainingText, NMacroMap} -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroMap, IncludeSearchPath); |
|
|
|
{Def, NLine, NRemainingText, NMacroMap} when Def =:= def; Def =:= endif; Def =:= else;Def =:= undef; Def =:= attribute; Def =:= vsn -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroMap, IncludeSearchPath); |
|
|
|
{vsn, NLine, NRemainingText, NMacroMap} -> |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroMap, IncludeSearchPath); |
|
|
|
{Include, NLine, NRemainingText, IncludeFilename} when Include =:= include; Include =:= include_lib -> |
|
|
|
{IncludeCurrentFile, IncludeFileRemainingTextents} = |
|
|
|
case Include of |
|
|
@ -115,17 +115,15 @@ scanAndParse(RemainingText, CurrFilename, CurrLine, RevForms, Errors, MacroMap, |
|
|
|
|
|
|
|
%%io:format("include file ~p contents: ~n~p~nRemainingText = ~p~n", [IncludeFilename,IncludeFileRemainingTextents, RemainingText]), |
|
|
|
%% Modify the FILE macro to reflect the filename |
|
|
|
%%IncludeMacroDict = dict:store('FILE', {[],IncludeFilename}, MacroMap), |
|
|
|
IncludeMacroDict = MacroMap, |
|
|
|
IncludeMacroMap = MacroMap, |
|
|
|
|
|
|
|
%% Process the header file (inc. any nested header files) |
|
|
|
{ok, RevIncludeForms, IncludedMacroDict} = scanAndParse(IncludeFileRemainingTextents, IncludeCurrentFile, 1, [], Errors, IncludeMacroDict, IncludeSearchPath), |
|
|
|
{ok, RevIncludeForms, IncludedMacroMap} = scanAndParse(IncludeFileRemainingTextents, IncludeCurrentFile, 1, [], Errors, IncludeMacroMap, IncludeSearchPath), |
|
|
|
%io:format("include file results = ~p~n", [R]), |
|
|
|
%% Restore the FILE macro in the NEW MacroMap (so we keep any macros defined in the header file) |
|
|
|
%%NMacroDict = dict:store('FILE', {[],CurrFilename}, IncludedMacroDict), |
|
|
|
NMacroDict = IncludedMacroDict, |
|
|
|
NMacroMap = IncludedMacroMap, |
|
|
|
%% Continue with the original file |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevIncludeForms ++ RevForms, Errors, NMacroDict, IncludeSearchPath); |
|
|
|
scanAndParse(NRemainingText, CurrFilename, NLine, RevIncludeForms ++ RevForms, Errors, NMacroMap, IncludeSearchPath); |
|
|
|
{continue, Continuation} -> |
|
|
|
scanAndParse([], CurrFilename, CurrLine, [Continuation | RevForms], Errors, MacroMap, IncludeSearchPath); |
|
|
|
done -> |
|
|
@ -138,8 +136,8 @@ scanner(Text, Line, MacroMap) -> |
|
|
|
case preProc(Tokens, MacroMap) of |
|
|
|
{tokens, NToks} -> |
|
|
|
{tokens, NLine, LeftOverChars, NToks}; |
|
|
|
{macro, NMacroDict} -> |
|
|
|
{macro, NLine, LeftOverChars, NMacroDict}; |
|
|
|
{macro, NMacroMap} -> |
|
|
|
{macro, NLine, LeftOverChars, NMacroMap}; |
|
|
|
{include, Filename} -> |
|
|
|
{include, NLine, LeftOverChars, Filename}; |
|
|
|
{include_lib, Filename} -> |
|
|
@ -168,7 +166,7 @@ scanner(Text, Line, MacroMap) -> |
|
|
|
|
|
|
|
case preProc(lists:reverse(lists:concat([Header, Tokens])), MacroMap) of |
|
|
|
{tokens, NToks} -> {tokens, NLine, [], NToks}; |
|
|
|
{macro, NMacroDict} -> {macro, NLine, [], NMacroDict}; |
|
|
|
{macro, NMacroMap} -> {macro, NLine, [], NMacroMap}; |
|
|
|
{include, Filename} -> {include, NLine, [], Filename}; |
|
|
|
{include_lib, Filename} -> {include_lib, NLine, [], Filename}; |
|
|
|
Def when Def =:= def; Def =:= endif; Def =:= else; Def =:= undef; Def =:= attribute; Def =:= vsn -> |
|
|
@ -253,8 +251,6 @@ preProc([{'-', _}, {atom, _, copyright}, {'(', _}, _, {')', _}, {dot, _}], _Macr |
|
|
|
attribute; |
|
|
|
preProc([{'-', _}, {atom, _, description}, {'(', _}, _, {')', _}, {dot, _}], _MacroMap) -> |
|
|
|
attribute; |
|
|
|
preProc([{'-', _}, {atom, _, module}, {'(', _}, _, {')', _}, {dot, _}], _MacroMap) -> |
|
|
|
attribute; |
|
|
|
preProc(Tokens, MacroMap) -> |
|
|
|
{tokens, substMacros(Tokens, MacroMap)}. |
|
|
|
|
|
|
@ -317,9 +313,9 @@ substMacrosRev([{'?', _}, {_, _, Name}, {'(', _} = Paren | Tokens], MacroMap, Re |
|
|
|
substMacrosRev([{'?', _}, {_, _, Name} | Toks], MacroMap, RevOutToks) -> |
|
|
|
%% This macro invocation does not have arguments. |
|
|
|
%% Therefore the definition should not have parameters |
|
|
|
case dict:is_key(Name, MacroMap) of |
|
|
|
case maps:is_key(Name, MacroMap) of |
|
|
|
true -> |
|
|
|
{[], MacroValue} = dict:fetch(Name, MacroMap), |
|
|
|
{[], MacroValue} = maps:get(Name, MacroMap), |
|
|
|
|
|
|
|
%% Recursively expand any macro calls inside this macro's value |
|
|
|
%% TODO: avoid infinite expansion due to circular references (even indirect ones) |
|
|
@ -331,7 +327,7 @@ substMacrosRev([{'?', _}, {_, _, Name} | Toks], MacroMap, RevOutToks) -> |
|
|
|
|
|
|
|
substMacrosRev([Tok | Toks], MacroMap, RevOutToks) -> |
|
|
|
substMacrosRev(Toks, MacroMap, [Tok | RevOutToks]); |
|
|
|
substMacrosRev([], _MacroDict, RevOutToks) -> RevOutToks. |
|
|
|
substMacrosRev([], _MacroMap, RevOutToks) -> RevOutToks. |
|
|
|
|
|
|
|
substMacrosArgsExpress([{var, _, ArgsName}, {')', Line} | Toks], RevArgs) -> |
|
|
|
{Toks, reverse([ArgsName | RevArgs]), Line}; |
|
|
|