home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / EXAMPLES / SUPERLIN / C_PUBLIC.LF < prev    next >
Text File  |  1996-06-04  |  13KB  |  594 lines

  1. %
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %
  4. %
  5. %              INTERFACE MODULE FOR THE SCANNING OF THE TREE
  6. %              ---------------------------------------------
  7. %
  8. %
  9. %  AUTHOR : Arnaud Venet                        CREATION : September 20th 1993
  10. %  ------                                       --------
  11. %
  12. %
  13. %                            ---------------                        
  14. %                    
  15. %                   Last modification : March 3rd 1994 
  16. %
  17. %
  18. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19. %
  20. %  (C) Digital Equipment Corporation 1993 - 1994
  21. %
  22. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  23. %
  24.  
  25.  
  26.  
  27. module("c_public_terms") ?
  28.  
  29.  
  30. %
  31. % ------------------------------------------------------------------------------
  32. %
  33.  
  34.  
  35. public(nothing, first, next, previous, last) ?
  36.  
  37.  
  38. public(identifier, number, integer, characters, characters_string, 
  39.        id, white_spaces, file, line, column, octal, decimal,
  40.        hexadecimal, float, long, double) ?
  41.  
  42.  
  43. public(
  44.   toplevel,
  45.   top_declarations,
  46.   block_declarations,
  47.   first_declaration,
  48.   external_declarations,
  49.   type_definitions,
  50.   struct_definitions,
  51.   union_definitions,
  52.   enum_definitions,
  53.   struct_declarations,
  54.   union_declarations,
  55.   enum_declarations,
  56.   struct_declaration,
  57.   union_declaration,
  58.   enum_declaration,
  59.   function_definitions,
  60.   external_declaration,
  61.   local_declarations,
  62.   local_declaration,
  63.   files,
  64.   files_number,
  65.   file_info,
  66.   first_token,
  67.   scope,
  68.   function_head,
  69.   function_body,
  70.   function_name,
  71.   type,
  72.   name,
  73.   initialization,
  74.   separator,
  75.   type_definition,
  76.   keyword,
  77.   struct_definition,
  78.   struct,
  79.   enum_definition,
  80.   enum,
  81.   union_definition,
  82.   union,
  83.   body,
  84.   left_brace,
  85.   right_brace,
  86.   left_parenthesis,
  87.   right_parenthesis,
  88.   left_bracket,
  89.   right_bracket,
  90.   struct_body,
  91.   union_body,
  92.   enum_body,
  93.   type_alias,
  94.   store_class,
  95.   qualification,
  96.   fields,
  97.   field,
  98.   enumerators,
  99.   enumerator,
  100.   first_member,
  101.   first_argument,
  102.   protected_type,
  103.   protected_expression,
  104.   pointer,
  105.   to,
  106.   star,
  107.   qualification,
  108.   array,
  109.   of,
  110.   dimensions,
  111.   dimensions_number,
  112.   dimension,
  113.   size,
  114.   tag,
  115.   anonymous_tag,
  116.   colon,
  117.   function,
  118.   return_type,
  119.   parameters,
  120.   vararg,
  121.   suspension_points,
  122.   parameter,
  123.   label_parameter,
  124.   label,
  125.   function_definition,
  126.   old,
  127.   modern,
  128.   parameters_declarations,
  129.   parameter_declaration,
  130.   parameter,
  131.   struct_name,
  132.   union_name,
  133.   enum_name,
  134.   block,
  135.   local_declarations,
  136.   instructions,
  137.   expression,
  138.   expression_instruction,
  139.   semi_colon,
  140.   labeled_instruction,
  141.   case,
  142.   condition,
  143.   default,
  144.   if,
  145.   then_body,
  146.   then_keyword,
  147.   else_body,
  148.   switch,
  149.   while,
  150.   switch,
  151.   do_while,
  152.   do_keyword,
  153.   while_keyword,
  154.   for,
  155.   step,
  156.   first_semi_colon,
  157.   second_semi_colon,
  158.   continue,
  159.   break,
  160.   goto,
  161.   return,
  162.   value,
  163.   void_instruction,
  164.   setting,
  165.   postfix,
  166.   infix,
  167.   prefix,
  168.   special,
  169.   then,
  170.   else,
  171.   array_reference,
  172.   index,
  173.   cast,
  174.   function_call,
  175.   call,
  176.   argument,
  177.   arguments,
  178.   arguments_number,
  179.   operator,
  180.   mode,
  181.   left_expression,
  182.   right_expression,
  183.   sequence,
  184.   complex_initialization,
  185.   parent_declarations,
  186.   first_element,
  187.   tail) ?
  188.  
  189.  
  190. public(extern, const, volatile, static, auto, pointer, void, int, float,
  191.        double, long_int, long_double, typedef, short_int, short, long, char) ?
  192.  
  193.  
  194. %
  195. % ------------------------------------------------------------------------------
  196. %
  197.  
  198.  
  199. public('*protected_project*', '*protected_has_feature*') ?
  200.  
  201.  
  202. %
  203. % ------------------------------------------------------------------------------
  204. %
  205.  
  206.  
  207. public(syntactic_tree) ?
  208.  
  209.  
  210. persistent(syntactic_tree) ?
  211.  
  212.  
  213. %
  214. % ------------------------------------------------------------------------------
  215. %
  216.  
  217.  
  218. '*protected_project*'(Feature, Node) -> TheContent
  219.   | (
  220.       has_feature(Feature, Node, What),
  221.       !
  222.     ;
  223.       Feature :== first_element,
  224.       Node :=< list,
  225.       Node :\== [],
  226.       !,
  227.       What = Node.1
  228.     ;
  229.       Feature :== tail,
  230.       Node :=< list,
  231.       Node :\== [],
  232.       !,
  233.       What = Node.2
  234.     ;
  235.       Feature :== first_declaration,
  236.       !,
  237.       (
  238.         has_feature(external_declarations, Node, Declarations),
  239.         LNames = features(Declarations, current_module),
  240.         LNames :\== [],
  241.         !,
  242.         LNames = [Name | @],
  243.         What = search_first_from(Declarations.Name)
  244.       ;
  245.         has_feature(local_declarations, Node, Declarations),
  246.         LNames = features(Declarations, current_module),
  247.         LNames :\== [],
  248.         !,
  249.         LNames = [Name | @],
  250.         What = search_first_from(Declarations.Name)
  251.       ;
  252.         Node :== external_declarations,
  253.         LNames = features(Node, current_module),
  254.         LNames :\== [],
  255.         !,
  256.         LNames = [Name | @],
  257.         What = search_first_from(Node.Name)
  258.       ;
  259.         Node :== local_declarations,
  260.         LNames = features(Node, current_module),
  261.         LNames :\== [],
  262.         !,
  263.         LNames = [Name | @],
  264.         What = search_first_from(Node.Name)
  265.       ;
  266.         Node :== parameters_declarations,
  267.         LNames = features(Node, current_module),
  268.         LNames :\== [],
  269.         !,
  270.         LNames = [Name | @],
  271.         What = search_first_from(Node.Name)
  272.       ;
  273.         has_feature(type_definitions, Node, TypeDefinitions),
  274.         LNames = features(TypeDefinitions, current_module),
  275.         LNames :\== [],
  276.         !,
  277.         LNames = [Name | @],
  278.         What = search_first_from(Node.type_definitions.Name)
  279.       ;
  280.         has_feature(struct_definitions, Node, Structures),
  281.         LNames = features(Structures, current_module),
  282.         LNames :\== [],
  283.         !,
  284.         LNames = [Name | @],
  285.         What = search_first_from(Node.struct_definitions.Name)
  286.       ;
  287.         has_feature(union_definitions, Node, Unions),
  288.         LNames = features(Unions, current_module),
  289.         LNames :\== [],
  290.         !,
  291.         LNames = [Name | @],
  292.         What = search_first_from(Node.union_definitions.Name)
  293.       ;
  294.         has_feature(enum_definitions, Node, Enumerations),
  295.         LNames = features(Enumerations, current_module),
  296.         LNames :\== [],
  297.         !,
  298.         LNames = [Name | @],
  299.         What = search_first_from(Node.enum_definitions.Name)
  300.       ;
  301.         has_feature(struct_declarations, Node, Structures),
  302.         LNames = features(Structures, current_module),
  303.         LNames :\== [],
  304.         !,
  305.         LNames = [Name | @],
  306.         What = search_first_from(Node.struct_declarations.Name)
  307.       ;
  308.         has_feature(union_declarations, Node, Unions),
  309.         LNames = features(Unions, current_module),
  310.         LNames :\== [],
  311.         !,
  312.         LNames = [Name | @],
  313.         What = search_first_from(Node.union_declarations.Name)
  314.       ;
  315.         has_feature(enum_declarations, Node, Enumerations),
  316.         LNames = features(Enumerations, current_module),
  317.         LNames :\== [],
  318.         !,
  319.         LNames = [Name | @],
  320.         What = search_first_from(Node.enum_declarations.Name)
  321.       ;
  322.         has_feature(function_definitions, Node, FunctionDefinitions),
  323.         LNames = features(FunctionDefinitions, current_module),
  324.         LNames :\== [],
  325.         !,
  326.         LNames = [Name | @],
  327.         What = search_first_from(Node.function_definitions.Name)
  328.       ;
  329.         What = nothing
  330.       )
  331.     ;
  332.       Feature :== function_name,
  333.       Node :== {function_head; function_body},
  334.       !,
  335.       What :== Node.1
  336.     ;
  337.       Feature :== parent_declarations,
  338.       Node :== parameters_declarations,
  339.       !,
  340.       What = top_declarations
  341.     ;
  342.       Feature :== {left_expression; right_expression},
  343.       has_feature(mode, Node),
  344.       !,
  345.       cond(Feature :== left_expression,
  346.         What = Node.1,
  347.         What = Node.2
  348.       )
  349.     ;
  350.       Feature :== expression,
  351.       has_feature(mode, Node, Mode),
  352.       Mode :== {postfix; prefix},
  353.       !,
  354.       What = Node.1
  355.     ;
  356.       Feature :== expression,
  357.       Node :== {protected_expression; argument},
  358.       !,
  359.       What = Node.1
  360.     ;
  361.       Node :== pointer,
  362.       Feature :== store_class,
  363.       !,
  364.       What = '*protected_project*'(Feature, Node.to)
  365.     ;
  366.       Node :== array,
  367.       Feature :== {store_class; qualification},
  368.       !,
  369.       What = '*protected_project*'(Feature, Node.of)
  370.     ;
  371.       Node :== protected_type,
  372.       Feature :== {store_class; qualification},
  373.       !,
  374.       What = '*protected_project*'(Feature, Node.1)
  375.     ;
  376.       Node :== function,
  377.       Feature :== {store_class; qualification},
  378.       !,
  379.       What = '*protected_project*'(Feature, Node.return_type)
  380.     ;
  381.       Node :== {fields; enumerators},
  382.       Feature :== first_member,
  383.       !,
  384.       LNames = features(Node, current_module),
  385.       LNames = [Name | @],
  386.       What = search_first_from(Node.Name)
  387.     ;
  388.       Node :== arguments,
  389.       Feature :== first_argument,
  390.       !,
  391.       cond(Node.arguments_number > 0,
  392.         What = Node.1,
  393.         What = nothing
  394.       )
  395.     ;
  396.       Feature :== id,
  397.       Node :== identifier,
  398.       !,
  399.       What = Node.1
  400.     ;
  401.       Feature :== value,
  402.       Node :== integer,
  403.       !,
  404.       What = Node.1
  405.     ;
  406.       Feature :== string,
  407.       Node :== characters_string,
  408.       !,
  409.       What = Node.1
  410.     ;
  411.       Feature :== char,
  412.       Node :== character,
  413.       !,
  414.       What = Node.1
  415.     ;
  416.       Feature :== num,
  417.       Node :== number,
  418.       !,
  419.       What = Node.1
  420.     ;
  421.       Feature :== first,
  422.       !,
  423.       has_feature(previous, Node),
  424.       What = search_first_from(Node)
  425.     ;
  426.       Feature :== last,
  427.       !,
  428.       has_feature(next, Node),
  429.       What = search_last_from(Node)
  430.     ;
  431.       Node :== protected_type,
  432.       Feature :== type,
  433.       !,
  434.       What = Node.1
  435.     ;
  436.       Node :== parameter_declaration,
  437.       Feature :== parameter,
  438.       !,
  439.       What = Node.1
  440.     ;
  441.       Node :== expression_instruction,
  442.       Feature :== expression,
  443.       !,
  444.       What = Node.1
  445.     ;
  446.       Feature :== name,
  447.       Node :== {struct_name; union_name; enum_name},
  448.       !,
  449.       What = Node.1
  450.     ;
  451.       Feature :== body,
  452.       Node :== {struct; union; enum},
  453.       !,
  454.       What = Node.1
  455.     ;
  456.       write_err(">>> superlint : feature '", Feature, 
  457.                 "' does not exist for node '", root_sort(Node), "'"),
  458.       nl_err,
  459.       halt
  460.     ),
  461.     (
  462.       is_symbolic(What),
  463.       !,
  464.       copy_and_convert_token(What, in => TheContent)
  465.     ;
  466.       TheContent = What
  467.     ).
  468.  
  469.  
  470. %
  471. % ------------------------------------------------------------------------------
  472. %
  473.  
  474.  
  475. %%%'*protected_has_feature*'(Feature, What, Content) :-
  476. %%%  has_feature(Feature, What, Content, current_module).
  477.  
  478.  
  479. %
  480. % ------------------------------------------------------------------------------
  481. %
  482.  
  483.  
  484. key_words -> ['auto', 'break', 'case', 'char', 'const', 'continue', 'default',
  485.               'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'goto',
  486.               'if', 'int', 'long', 'register', 'return', 'short', 'signed',
  487.               'sizeof', 'static', 'struct', 'switch', 'typedef', 'union',
  488.               'unsigned', 'void', 'volatile', 'while',
  489.               identifier, number, integer, characters, characters_string].
  490.  
  491.  
  492. %
  493. % ------------------------------------------------------------------------------
  494. %
  495.  
  496.  
  497. persistent(keywords_table) ?
  498.  
  499.  
  500.  
  501. init_keywords_table([Keyword | Keywords]) :-
  502.   !,
  503.   keywords_table.Keyword <<- true,
  504.   init_keywords_table(Keywords).
  505.  
  506.  
  507. init_keywords_table([]).
  508.  
  509.  
  510. %
  511. % ------------------------------------------------------------------------------
  512. %
  513.  
  514.  
  515. init_keywords_table(key_words) ?
  516.  
  517.  
  518. %
  519. % ------------------------------------------------------------------------------
  520. %
  521.  
  522.  
  523. is_symbolic(What) :-
  524.   What :\>< string,
  525.   What :\== nothing,
  526.   has_feature(file, What),
  527.   (
  528.     has_feature(What, keywords_table),
  529.     !,
  530.     fail
  531.   ;
  532.     succeed
  533.   ).
  534.  
  535.  
  536. %
  537. % ------------------------------------------------------------------------------
  538. %
  539.  
  540.  
  541. copy_and_convert_token(What, in => Copy) :-
  542.   Copy <<- psi2str(What),
  543.   Copy.file <<- What.file,
  544.   Copy.line <<- What.line,
  545.   Copy.column <<- What.column,
  546.   Copy.white_spaces <<- What.white_spaces,
  547.   Copy.previous <<- What.previous,
  548.   Copy.next <<- What.next.
  549.  
  550.  
  551. %
  552. % ------------------------------------------------------------------------------
  553. %
  554.  
  555.  
  556. search_first_from(What) -> TheFirst
  557.   | (
  558.       What.previous :== nothing,
  559.       !,
  560.       TheFirst = What
  561.     ; 
  562.       TheFirst = search_first_from(What.previous)
  563.     ).
  564.  
  565.  
  566. %
  567. % ------------------------------------------------------------------------------
  568. %
  569.  
  570.  
  571. search_last_from(What) -> TheLast
  572.   | (
  573.       What.next :== nothing,
  574.       !,
  575.       TheLast = What
  576.     ; 
  577.       TheLast = search_last_from(What.next)
  578.     ).
  579.  
  580.  
  581. %
  582. % ------------------------------------------------------------------------------
  583. %
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.