Ejemplo n.º 1
0
  /** Checks there is not more than one default. */
  private void checkNotMultipleDefaults() {
    for (int numDefaults = 0, i = 0; i < originalCaseList.size(); i++) {
      Case c = originalCaseList.get(i);

      if (c.isDefault()) {
        numDefaults++;

        if (numDefaults > 1) {
          ToolError.reportError(ErrorMessage.MULTIPLE_DEFAULTS, matchingOver);
        }
      }
    }
  }
Ejemplo n.º 2
0
  public Match(TypedAST matchingOver, List<Case> cases, FileLocation location) {
    // clone original list so we have a canonical copy
    this.originalCaseList = new ArrayList<Case>(cases);

    this.matchingOver = matchingOver;
    this.cases = cases;

    // find the default case and remove it from the typed cases
    for (Case c : cases) {
      if (c.isDefault()) {
        defaultCase = c;
        break;
      }
    }

    cases.remove(defaultCase);

    this.location = location;
  }
Ejemplo n.º 3
0
  private void checkAllCasesAreTagged(Environment env) {
    // All things we match over must be tagged types
    for (Case c : cases) {
      if (c.isDefault()) continue;

      Type tagName = c.getTaggedTypeMatch();

      if (tagName instanceof UnresolvedType) {
        UnresolvedType ut = (UnresolvedType) tagName;
        // System.out.println("ut = " + ut.resolve(env));
      }

      if (tagName instanceof TypeInv) {
        // TypeInv ti = (TypeInv) tagName;
        // System.out.println("ti = " + ti.resolve(env));
        // tagName = ti.resolve(env);
        // if (tagName instanceof UnresolvedType) {
        // tagName = ((UnresolvedType) tagName).resolve(env);
        // } DO NOT UNCOMMENT THIS AS BREAKS CASES
        return; // FIXME: Assume TypeInv will sort itself out during runtime.
      }

      // System.out.println(tagName);

      // check type exists
      // TypeBinding type = env.lookupType(tagName.toString()); // FIXME:

      // if (type == null) {
      //	ToolError.reportError(ErrorMessage.TYPE_NOT_DECLARED, this, tagName.toString());
      // }

      // check it is tagged
      TaggedInfo info = TaggedInfo.lookupTagByType(tagName); // FIXME:

      if (info == null) {
        ToolError.reportError(ErrorMessage.TYPE_NOT_TAGGED, matchingOver, tagName.toString());
      }
    }
  }
Ejemplo n.º 4
0
  private void checkSubtagsPreceedSupertags() {
    // A tag cannot be earlier than one of its subtags
    for (int i = 0; i < cases.size() - 1; i++) {
      Case beforeCase = cases.get(i);
      TaggedInfo beforeTag = TaggedInfo.lookupTagByType(beforeCase.getTaggedTypeMatch()); // FIXME:

      for (int j = i + 1; j < cases.size(); j++) {
        Case afterCase = cases.get(j);

        if (afterCase.isDefault()) break;

        TaggedInfo afterTag = TaggedInfo.lookupTagByType(afterCase.getTaggedTypeMatch()); // FIXME:
        // TagBinding afterBinding = TagBinding.get(afterCase.getTaggedTypeMatch());

        if (afterTag != null && beforeTag != null && isSubtag(afterTag, beforeTag)) {
          ToolError.reportError(
              ErrorMessage.SUPERTAG_PRECEEDS_SUBTAG,
              matchingOver,
              beforeTag.getTagName(),
              afterTag.getTagName());
        }
      }
    }
  }