AST_VISITOR.process_WHICH_as ???

13 views
Skip to first unread message

Jimmy Johnson

unread,
Aug 17, 2015, 3:17:16 PM8/17/15
to eiffelstudio-dev
In the month and a half since my last [unanswered] post, I have devised a partial answer to my own question, but I still have a problem.  In the following I describe my objective, show [some of] my working code so far, and then as my real question. 

OBJECTIVE:  Using SYNTAX_UPDATER_VISITOR as a model, I want to process a class, inserting some code after a qualified call that is not: 1) in the condition of an "if" or "elseif" statement, 2) not in an assertion, 3) not in an assignment statement, 4) not in a loop condition, 5) not an argument to another call, and 6) in other constructs I have not thought about yet.

The code:
     do
          object.qualified_call               -- visitor should insert code after this line
          call (object.qualified_call)      -- BUT NOT AFTER THIS LINE (case 5)
     end
becomes:
     do
          object.qualified_call
          object.encode                       -- New text inserted by visitor
          call (object.qualified_call)
     end

WORKING CODE:  The code below shows some of what I do so far.  Feature `process_access_id_as' sets `target_text' whenever an identifier is encountered; `target_text' is used in `process_access_feature_as' to generate the string to be inserted.  In order to handle case number 5 (result of qualified call used as argument to a call), `process_parameter_list_as' sets `is_processing_parameter_list' to true and then when then `process_access_feature_as' can check `is_processing_parameter_list'.  (The if statement checks other cases as well, which are handled similarly.)


process_access_id_as (l_as: ACCESS_ID_AS)
-- Redefined to capture the `target' of a feature call for use
-- in `process_access_feat_as'.
do
Precursor (l_as)
-- This could be in a feature call or in an assignment statement
target_text := l_as.access_name_8
end

is_processing_parameter_list: BOOLEAN
-- Is a parameter list being processed?

process_parameter_list_as (l_as: PARAMETER_LIST_AS)
do
is_processing_parameter_list := true
Precursor (l_as)
is_processing_parameter_list := false
end

process_access_feat_as (l_as: ACCESS_FEAT_AS)
-- Redefined to add code after a qualified feature call
local
s: STRING_8
do
Precursor (l_as)
if not is_in_condition and
not is_loop_condition and
not is_processing_assignment and
not is_processing_check and
not is_processing_parameter_list and
l_as.is_qualified and attached target then
targets.extend (target.access_name_8)
s := target.access_name_8
if s.as_lower /~ "result" then
context.add_string ("%N")
context.add_string (s + ".on_encode")
end
end
target := Void
end


QUESTION:  How do I make this work for a qualified call on Current?

     do
          Current.call          -- Visitor should insert code after this line
     end

I tried:
process_keyword_as (l_as: KEYWORD_AS)
-- Redefined to capture the `target' of a qualified feature call when
-- the target is "Current"; for use in `process_access_feature_as'.
-- (e.g.  Current.do_something)
do
Precursor (l_as)
if l_as.is_note_keyword then
target_text := "note"
end
if l_as.is_current_keyword then
target_text := "Current"
end
end

In the above the "note" keyword, as an example, is processed but the "Current" keyword is not (ie. the if statement, "if l_as.is_current_keyword" is always false).  Why?

Thanks,
Jimmy J. Johnson



Jimmy Johnson

unread,
Aug 17, 2015, 5:15:04 PM8/17/15
to eiffelstudio-dev
Okay, the WORKING_CODE does not work for:     object.qualified_call (arg)
I should follow this line with:   object.encode
but I get:   arg.encode.
Reply all
Reply to author
Forward
0 new messages