home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / Jikes / Source / src / diagnose.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-24  |  5.1 KB  |  195 lines

  1. // $Id: diagnose.h,v 1.12 2001/01/05 09:13:20 mdejong Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef diagnose_INCLUDED
  11. #define diagnose_INCLUDED
  12.  
  13. #include "platform.h"
  14. #include "parser.h"
  15. #include "jikesapi.h"
  16.  
  17. #ifdef    HAVE_JIKES_NAMESPACE
  18. namespace Jikes {    // Open namespace Jikes block
  19. #endif
  20.  
  21. struct RepairCandidate
  22. {
  23.     int symbol;
  24.     Location location;
  25. };
  26.  
  27. struct StateInfo
  28. {
  29.     int state,
  30.         next;
  31. };
  32.  
  33. class ParseErrorInfo: public JikesError
  34. {
  35.     friend class ParseError;
  36.     
  37.  public:
  38.     
  39.     virtual const wchar_t *getErrorMessage();
  40.     virtual const wchar_t *getErrorReport();
  41.     
  42.     virtual JikesErrorSeverity getSeverity();
  43.     virtual const char *getFileName();
  44.     
  45.     virtual int getLeftLineNo      ();
  46.     virtual int getLeftColumnNo    ();
  47.     virtual int getRightLineNo     ();
  48.     virtual int getRightColumnNo   ();
  49.  
  50.  protected:        
  51.  
  52.  private:
  53.     
  54.     int left_line_no    ;
  55.     int left_column_no  ;
  56.     int right_line_no   ;
  57.     int right_column_no ;
  58.     
  59.     static bool emacs_style_report;
  60.     LexStream *lex_stream;
  61.     
  62.     void Initialize(LexStream *);
  63.  
  64.     wchar_t *regularErrorString ();
  65.     wchar_t *emacsErrorString   ();
  66.     
  67.     LexStream::TokenIndex left_token  ;
  68.     LexStream::TokenIndex right_token ;
  69.     
  70.     int                   name_index;   
  71.     int                   right_string_length;
  72.     int                   num;
  73.     unsigned char         msg_level;
  74.     ParseErrorCode        msg_code;
  75.     unsigned              scope_name_index;
  76. };
  77.  
  78.  
  79. class ParseError : public javaprs_table
  80. {
  81.  public:
  82.  
  83.     void Report(int msg_level, ParseErrorCode, int name_index,
  84.                 LexStream::TokenIndex left_token, LexStream::TokenIndex right_token,
  85.                 int scope_name_index = 0);
  86.  
  87.     void SortMessages();
  88.  
  89.     ParseError(Control &control_, LexStream *lex_stream_);
  90.     void PrintMessages();
  91.  
  92. private:
  93.  
  94.     Control &control;
  95.     LexStream *lex_stream;
  96.  
  97.     Tuple<ParseErrorInfo> errors;
  98.  
  99.     void PrintPrimaryMessage   (int k);
  100.     void PrintSecondaryMessage (int k);
  101.     
  102. };
  103.  
  104.  
  105. class DiagnoseParser : public Parser
  106. {
  107. public:
  108.  
  109.     DiagnoseParser(Control &control_, LexStream *lex_stream_) : next_stack(NULL),
  110.                                                                 prev_stack(NULL),
  111.                                                                 scope_index(NULL),
  112.                                                                 scope_position(NULL),
  113.                                                                 state_pool(256),
  114.                                                                 error(control_, lex_stream_)
  115.     {
  116.         lex_stream = lex_stream_;
  117.         memset(list, 0, NUM_SYMBOLS * sizeof(int));
  118.         DiagnoseParse();
  119.  
  120.         return;
  121.     }
  122.  
  123.     ~DiagnoseParser()
  124.     {
  125.         delete [] next_stack;
  126.         delete [] prev_stack;
  127.         delete [] scope_index;
  128.         delete [] scope_position;
  129.     }
  130.  
  131. private:
  132.  
  133.     int next_stack_top,
  134.         *next_stack,
  135.  
  136.         prev_stack_top,
  137.         *prev_stack,
  138.  
  139.         scope_stack_top,
  140.         *scope_index,
  141.         *scope_position;
  142.  
  143.     int list[NUM_SYMBOLS + 1];
  144.  
  145.     enum { NIL = -1 };
  146.     Tuple<StateInfo> state_pool;
  147.     int *state_seen; // this variable is managed entirely by the function "scope_trial"
  148.  
  149.     ParseError error;
  150.  
  151.     void DiagnoseParse();
  152.  
  153.     void ReallocateStacks();
  154.  
  155.     RepairCandidate ErrorRecovery(TokenObject error_token);
  156.     RepairCandidate PrimaryPhase(TokenObject error_token);
  157.     int MergeCandidate(int state, int buffer_position);
  158.     PrimaryRepairInfo CheckPrimaryDistance(int stack[],
  159.                                            int stack_top,
  160.                                            PrimaryRepairInfo repair);
  161.     RepairCandidate PrimaryDiagnosis(PrimaryRepairInfo repair);
  162.     int GetTermIndex(int stack[], int stack_top,
  163.                      int tok, int buffer_position);
  164.     int GetNtermIndex(int start, int sym, int buffer_position);
  165.     int Misspell(int sym, TokenObject tok);
  166.     RepairCandidate SecondaryPhase(TokenObject error_token);
  167.     SecondaryRepairInfo MisplacementRecovery
  168.              (int stack[],
  169.               int stack_top,
  170.               int last_index,
  171.               SecondaryRepairInfo misplaced, bool stack_flag);
  172.     SecondaryRepairInfo SecondaryRecovery
  173.              (int stack[],
  174.               int stack_top,
  175.               int last_index,
  176.               SecondaryRepairInfo repair, bool stack_flag);
  177.     void SecondaryDiagnosis(SecondaryRepairInfo repair);
  178.  
  179.     void RepairParse(TokenObject);
  180.  
  181.     PrimaryRepairInfo ScopeTrial(int stack[], int stack_top,
  182.                                  PrimaryRepairInfo repair);
  183.     void ScopeTrialCheck(int stack[], int stack_top,
  184.                          PrimaryRepairInfo& repair, int indx);
  185.     bool SecondaryCheck(int stack[], int stack_top,
  186.                         int buffer_position, int distance);
  187. };
  188.  
  189. #ifdef    HAVE_JIKES_NAMESPACE
  190. }            // Close namespace Jikes block
  191. #endif
  192.  
  193. #endif
  194.  
  195.