Ejemplo n.º 1
0
 @Override
 public boolean visit(TernaryExpression t) {
   TreeNode tp = t.getThenPart();
   TreeNode ep = t.getElsePart();
   t.setExpressionType(lub(t, tp.getExpressionType(), ep.getExpressionType()));
   return true;
 }
Ejemplo n.º 2
0
 private boolean match(ArgumentList al, MethodInformation mi) {
   Type[] arguments = mi.getArguments();
   if ((al == null || al.size() == 0) && arguments.length == 0) return true;
   if (al.size() != arguments.length) return false;
   int i = 0;
   for (TreeNode tn : al.get()) {
     ExpressionType et = tn.getExpressionType();
     if (!et.match(arguments[i++])) return false;
   }
   return true;
 }
Ejemplo n.º 3
0
 private void testSuccessfulParse(String s, TreeNode tn) {
   SyntaxTree t = TestParseHelper.earleyParseBuildTree(g, s, null, diagnostics);
   assert !diagnostics.hasError()
       : "Got parser errors: " + TestParseHelper.getParseOutput(diagnostics);
   if (tn != null)
     assert tn.equals(t.getRoot()) : "Got unexpected tree: " + t.getRoot() + ", expected: " + tn;
 }
Ejemplo n.º 4
0
 private boolean hasMethods(ExpressionType clzType, TreeNode m) {
   if (clzType.isPrimitiveType()) {
     diagnostics.report(
         SourceDiagnostics.error(
             tree.getOrigin(), m.getParsePosition(), "Primitives have no methods"));
     return false;
   } else if (clzType == ExpressionType.VOID) {
     diagnostics.report(
         SourceDiagnostics.error(tree.getOrigin(), m.getParsePosition(), "Void has no methods"));
     return false;
   } else if (clzType == ExpressionType.NULL) {
     diagnostics.report(
         SourceDiagnostics.error(tree.getOrigin(), m.getParsePosition(), "null has no methods"));
     return false;
   }
   return true;
 }
Ejemplo n.º 5
0
 private ExpressionType getOnType(TreeNode on) {
   if (on != null) {
     return on.getExpressionType();
   } else {
     String fqn = cip.getFullName(containingClasses.getLast());
     return new ExpressionType(fqn);
   }
 }
Ejemplo n.º 6
0
 private ExpressionType lub(TreeNode tn, ExpressionType et1, ExpressionType et2) {
   if (et1.isPrimitiveType()) {
     if (!et2.isPrimitiveType()) {
       diagnostics.report(
           SourceDiagnostics.error(
               tree.getOrigin(),
               tn.getParsePosition(),
               "Unable to find common parent type of %s and %s",
               et1,
               et2));
       return null;
     }
     return ExpressionType.bigger(et1, et2);
   }
   return et1;
 }