File: javaparse.cc

package info (click to toggle)
libxtc-rats-java 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 18,580 kB
  • sloc: java: 288,962; ansic: 20,406; ml: 14,775; makefile: 1,358; cpp: 621; sh: 352; xml: 259; perl: 123
file content (114 lines) | stat: -rw-r--r-- 2,684 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// javaparse.cc            see license.txt for copyright and terms of use
// code for javaparse.h

#include "javaparse.h"    // this module
#include "trace.h"        // TRACE

#include <iostream.h>     // cout


// ----------------------- ParseEnv -----------------------
Modifiers ParseEnv::combine(SourceLoc loc, Modifiers m1, Modifiers m2)
{
  // any duplicate flags?
  Modifiers dups = (Modifiers)(m1 & m2);
  if (dups) {
    error(loc, stringc << "duplicate modifier: " << toString(dups));
  }

  // any of public, protected, private at the same time?
  Modifiers result = (Modifiers)(m1 | m2);

  if (result & MOD_PUBLIC) {
    if (result & MOD_PROTECTED) {
      error(loc, "public and protected modifiers");

    } else if (result & MOD_PRIVATE) {
      error(loc, "public and private modifiers");
    }

  } else if (result & MOD_PROTECTED) {
    if (result & MOD_PRIVATE) {
      error(loc, "protected and private modifiers");
    }
  }

  // done
  return result;
}

#define SELECT(higherKind, lowerKind) \
  if ((higherKind == k1) && (lowerKind  == k2)) return e1; \
  if ((lowerKind  == k1) && (higherKind == k2)) return e2

Expression* ParseEnv::mergeUnary(Expression* e1, Expression* e2)
{
  Expression::Kind k1 = e1->kind();
  Expression::Kind k2 = e2->kind();

  // Cast expressions take precedence over invocations.
  SELECT(Expression::CASTEXPRESSION, Expression::INVOCATIONEXPRESSION);

  // There should be no other ambiguities...
  noMerge("unary operations", e1, e2);
}


Expression* ParseEnv::mergePostfix(Expression* e1, Expression* e2)
{
  Expression::Kind k1 = e1->kind();
  Expression::Kind k2 = e2->kind();

  // New array expressions take precedence over subscript expressions
  SELECT(Expression::NEWARRAYEXPRESSION, Expression::SUBSCRIPTEXPRESSION);

  // There should be no other ambiguities...
  noMerge("postfix expressions", e1, e2);
}


void ParseEnv::noMerge(char const* desc, Expression* e1, Expression* e2)
{
  cout << toString(e1->loc)
       << ": error: unable to merge "
       << desc
       << ' '
       << e1->kindName()
       << " and "
       << e2->kindName()
       << endl;
  abort();
}


LocString * /*owner*/ ParseEnv::ls(SourceLoc loc, char const *name)
{
  return new LocString(loc, str(name));
}


void ParseEnv::error(SourceLoc loc, char const *msg)
{
  cout << toString(loc) << ": error: " << msg << endl;
  errors++;
}


void ParseEnv::warning(SourceLoc loc, char const *msg)
{
  cout << toString(loc) << ": warning: " << msg << endl;
  warnings++;
}


void ParseEnv::diagnose3(Bool3 b, SourceLoc loc, char const *msg)
{
  if (!b) {
    error(loc, msg);
  }
  else if (b == B3_WARN) {
    warning(loc, msg);
  }
}

// EOF