root/libparser/java.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. java

   1 /*
   2  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2005, 2010
   3  *      Tama Communications Corporation
   4  *
   5  * This file is part of GNU GLOBAL.
   6  *
   7  * This program is free software: you can redistribute it and/or modify
   8  * it under the terms of the GNU General Public License as published by
   9  * the Free Software Foundation, either version 3 of the License, or
  10  * (at your option) any later version.
  11  * 
  12  * This program is distributed in the hope that it will be useful,
  13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  * GNU General Public License for more details.
  16  * 
  17  * You should have received a copy of the GNU General Public License
  18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19  */
  20 
  21 #ifdef HAVE_CONFIG_H
  22 #include <config.h>
  23 #endif
  24 #ifdef HAVE_STRING_H
  25 #include <string.h>
  26 #else
  27 #include <strings.h>
  28 #endif
  29 
  30 #include "internal.h"
  31 #include "die.h"
  32 #include "strlimcpy.h"
  33 #include "token.h"
  34 #include "java_res.h"
  35 
  36 #define MAXCOMPLETENAME 1024            /* max size of complete name of class */
  37 #define MAXCLASSSTACK   100             /* max size of class stack */
  38 
  39 /*
  40  * java: read java file and pickup tag entries.
  41  */
  42 void
  43 java(const struct parser_param *param)
  44 {
  45         int c;
  46         int level;                                      /* brace level */
  47         int startclass, startthrows, startequal;
  48         char classname[MAXTOKEN];
  49         char completename[MAXCOMPLETENAME];
  50         int classlevel;
  51         struct {
  52                 char *classname;
  53                 char *terminate;
  54                 int level;
  55         } stack[MAXCLASSSTACK];
  56         const char *interested = "{}=;";
  57 
  58         *classname = *completename = 0;
  59         stack[0].classname = completename;
  60         stack[0].terminate = completename;
  61         stack[0].level = 0;
  62         level = classlevel = 0;
  63         startclass = startthrows = startequal = 0;
  64 
  65         if (!opentoken(param->file))
  66                 die("'%s' cannot open.", param->file);
  67         while ((c = nexttoken(interested, java_reserved_word)) != EOF) {
  68                 switch (c) {
  69                 case SYMBOL:                                    /* symbol */
  70                         for (; c == SYMBOL && peekc(1) == '.'; c = nexttoken(interested, java_reserved_word)) {
  71                                 PUT(PARSER_REF_SYM, token, lineno, sp);
  72                         }
  73                         if (c != SYMBOL)
  74                                 break;
  75                         if (startclass || startthrows) {
  76                                 PUT(PARSER_REF_SYM, token, lineno, sp);
  77                         } else if (peekc(0) == '('/* ) */) {
  78                                 if (level == stack[classlevel].level && !startequal)
  79                                         /* ignore constructor */
  80                                         if (strcmp(stack[classlevel].classname, token))
  81                                                 PUT(PARSER_DEF, token, lineno, sp);
  82                                 if (level > stack[classlevel].level || startequal)
  83                                         PUT(PARSER_REF_SYM, token, lineno, sp);
  84                         } else {
  85                                 PUT(PARSER_REF_SYM, token, lineno, sp);
  86                         }
  87                         break;
  88                 case '{': /* } */
  89                         DBG_PRINT(level, "{");  /* } */
  90 
  91                         ++level;
  92                         if (startclass) {
  93                                 char *p = stack[classlevel].terminate;
  94                                 char *q = classname;
  95 
  96                                 if (++classlevel >= MAXCLASSSTACK)
  97                                         die("class stack over flow.[%s]", curfile);
  98                                 if (classlevel > 1)
  99                                         *p++ = '.';
 100                                 stack[classlevel].classname = p;
 101                                 while (*q)
 102                                         *p++ = *q++;
 103                                 stack[classlevel].terminate = p;
 104                                 stack[classlevel].level = level;
 105                                 *p++ = 0;
 106                         }
 107                         startclass = startthrows = 0;
 108                         break;
 109                         /* { */
 110                 case '}':
 111                         if (--level < 0) {
 112                                 if (param->flags & PARSER_WARNING)
 113                                         warning("missing left '{' (at %d).", lineno); /* } */
 114                                 level = 0;
 115                         }
 116                         if (level < stack[classlevel].level)
 117                                 *(stack[--classlevel].terminate) = 0;
 118                         /* { */
 119                         DBG_PRINT(level, "}");
 120                         break;
 121                 case '=':
 122                         startequal = 1;
 123                         break;
 124                 case ';':
 125                         startclass = startthrows = startequal = 0;
 126                         break;
 127                 case JAVA_CLASS:
 128                 case JAVA_INTERFACE:
 129                 case JAVA_ENUM:
 130                         if ((c = nexttoken(interested, java_reserved_word)) == SYMBOL) {
 131                                 strlimcpy(classname, token, sizeof(classname));
 132                                 startclass = 1;
 133                                 PUT(PARSER_DEF, token, lineno, sp);
 134                         }
 135                         break;
 136                 case JAVA_NEW:
 137                 case JAVA_INSTANCEOF:
 138                         while ((c = nexttoken(interested, java_reserved_word)) == SYMBOL && peekc(1) == '.')
 139                                 PUT(PARSER_REF_SYM, token, lineno, sp);
 140                         if (c == SYMBOL)
 141                                 PUT(PARSER_REF_SYM, token, lineno, sp);
 142                         break;
 143                 case JAVA_THROWS:
 144                         startthrows = 1;
 145                         break;
 146                 case JAVA_BOOLEAN:
 147                 case JAVA_BYTE:
 148                 case JAVA_CHAR:
 149                 case JAVA_DOUBLE:
 150                 case JAVA_FLOAT:
 151                 case JAVA_INT:
 152                 case JAVA_LONG:
 153                 case JAVA_SHORT:
 154                 case JAVA_VOID:
 155                         if (peekc(1) == '.' && (c = nexttoken(interested, java_reserved_word)) != JAVA_CLASS)
 156                                 pushbacktoken();
 157                         break;
 158                 default:
 159                         break;
 160                 }
 161         }
 162         closetoken();
 163 }

/* [previous][next][first][last][top][bottom][index][help] */