checkType()

in lib/semantic.js [1299:1375]


  checkType(node) {
    if (node.type === 'array') {
      this.checkType(node.subType);
      return;
    }

    if (node.type === 'map') {
      this.checkType(node.valueType);
      return;
    }

    if (node.type === 'entry') {
      this.checkType(node.valueType);
      return;
    }

    if (node.type === 'iterator' || node.type === 'asyncIterator') {
      this.checkType(node.valueType);
      return;
    }

    if (node.tag === Tag.TYPE) {
      this.usedTypes.set(node.lexeme, true);
      return;
    }

    const modelName = node.lexeme;
    if (node.tag === Tag.ID) {
      const idType = this.getIdType(modelName);
      if (idType) {
        node.idType = idType;
        return;
      }


      this.error(`model "${modelName}" undefined`, node);
    }

    if (node.type === 'subModel_or_moduleModel') {
      const [mainId, ...rest] = node.path;
      const idType = this.getIdType(mainId.lexeme);
      mainId.idType = idType;
      // submodel
      if (idType === 'model') {
        const typeName = node.path.map((item) => {
          return item.lexeme;
        }).join('.');
        if (!this.models.has(typeName)) {
          this.error(`the submodel ${typeName} is inexist`, mainId);
        }
        node.type = 'subModel';
        return;
      }

      if (idType === 'module') {
        const checker = this.dependencies.get(mainId.lexeme);
        const typeName = rest.map((item) => {
          return item.lexeme;
        }).join('.');
        if (checker.models.has(typeName)) {
          node.type = 'moduleModel';
          this.usedExternModel.get(mainId.lexeme).add(typeName);
        } else if (checker.enums.has(typeName)) {
          node.type = 'moduleEnum';
          this.usedExternModel.get(mainId.lexeme).add(typeName);
        } else if (checker.typedefs.has(typeName)) {
          node.type = 'moduleTypedef';
          this.usedExternModel.get(mainId.lexeme).add(typeName);
        } else {
          this.error(`the model ${typeName} is inexist in ${mainId.lexeme}`, mainId);
        }
        
        return;
      }
    }

  }