Example #1
0
  // fills collections with of imported languages and devkits.
  // Languages include directly imported and coming immediately through devkits; listed devkits are
  // imported directly, without those they extend (why?).
  public LangAndDevkits collectLanguagesAndDevkits() {
    Set<SLanguage> usedLanguages = new LinkedHashSet<>();
    Set<SModuleReference> devkits = new LinkedHashSet<>();

    // perhaps, shall introduce ModuleImports similar to ModelImports to accomplish this?
    for (SModel m : getModels()) {
      final SModelInternal modelInternal = (SModelInternal) m;
      usedLanguages.addAll(modelInternal.importedLanguageIds());
      devkits.addAll(modelInternal.importedDevkits());
    }
    // XXX why don't we respect extended devkits here?
    final SRepository repository = getRepository();
    if (repository != null) {
      for (SModuleReference devkitRef : devkits) {
        final SModule module = devkitRef.resolve(repository);
        if (module instanceof DevKit) {
          for (SLanguage l : ((DevKit) module).getAllExportedLanguageIds()) {
            usedLanguages.add(l);
          }
        }
      }
    }
    usedLanguages.add(BootstrapLanguages.getLangCore());
    return new LangAndDevkits(usedLanguages, devkits);
  }
Example #2
0
  public static boolean checkCyclicInheritance(Language lang) {

    List<Language> frontier = ModuleUtil.refsToLanguages(lang.getExtendedLanguageRefs());
    ArrayList<Language> passed = new ArrayList<Language>();
    while (!frontier.isEmpty()) {
      List<Language> newFrontier = new ArrayList<Language>();
      for (Language extendedLang : frontier) {
        if (extendedLang == lang && lang != BootstrapLanguages.coreLanguage()) {
          return false;
        }
        if (!passed.contains(extendedLang)) {

          newFrontier.addAll(ModuleUtil.refsToLanguages(extendedLang.getExtendedLanguageRefs()));
        }
        passed.add(extendedLang);
      }
      frontier = newFrontier;
    }
    return true;
  }
Example #3
0
 @Override
 protected Set<Language> getInitialUsedLanguages() {
   HashSet<Language> result = new HashSet<Language>();
   for (SLanguage l : AbstractModule.this.getUsedLanguages()) {
     SModule langModule = l.getSourceModule();
     if (langModule instanceof Language) {
       result.add((Language) langModule);
     }
   }
   if (AbstractModule.this instanceof Language) {
     result.add((Language) AbstractModule.this);
     // XXX why Language(SModule)#getUsedLanguages doesn't care about descriptor language being
     // used?
     result.add(
         ModuleRepositoryFacade.getInstance()
             .getModule(BootstrapLanguages.descriptorLanguageRef(), Language.class));
   }
   if (AbstractModule.this instanceof Generator) {
     result.add(((Generator) AbstractModule.this).getSourceLanguage());
   }
   return result;
 }