Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
SE-FDr committed Nov 18, 2024
1 parent cfa18fc commit 743836f
Show file tree
Hide file tree
Showing 18 changed files with 1,202 additions and 3,655 deletions.
7 changes: 0 additions & 7 deletions monticore-grammar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@ group = "de.monticore"

def grammarOutDir = "$buildDir/generated-sources/monticore/sourcecode"
def taggingOutDir = "$buildDir/generated-sources/monticore/tagging"
def symbolsDir = 'src/main/resources'

sourceSets {
// Add mlc files to grammars source set (resulting in them being included in the grammars-jar)
main.grammars.include(["**/*.mlc", "**/*.mc4"])

symbols {
resources {
srcDirs(symbolsDir)
include "**/*.sym"
}
}
// The following is required as we still publish a Feature-variant (with usingSourceSet(grammarsForVariant))
grammarsForVariant {
java.srcDirs = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// (c) https://github.com/MontiCore/monticore
package de.monticore.types3.streams;

import de.monticore.symbols.basicsymbols.BasicSymbolsMill;
import de.monticore.symbols.basicsymbols._symboltable.IBasicSymbolsGlobalScope;
import de.monticore.symbols.basicsymbols._symboltable.TypeSymbol;
import de.monticore.types.check.SymTypeExpression;
import de.monticore.types.check.SymTypeExpressionFactory;
import de.monticore.types.check.SymTypeOfGenerics;
import de.se_rwth.commons.logging.Log;

import java.util.Optional;

/**
* Factory for StreamTypes
* (ONLY) convenience methods for
* {@link SymTypeExpressionFactory}
*/
public class StreamSymTypeFactory {

public static SymTypeOfGenerics createStream(SymTypeExpression innerType) {
return createStreamType("Stream", innerType);
}

public static SymTypeOfGenerics createEventStream(SymTypeExpression innerType) {
return createStreamType("EventStream", innerType);
}

public static SymTypeOfGenerics createSyncStream(SymTypeExpression innerType) {
return createStreamType("SyncStream", innerType);
}

public static SymTypeOfGenerics createToptStream(SymTypeExpression innerType) {
return createStreamType("ToptStream", innerType);
}

public static SymTypeOfGenerics createUntimedStream(SymTypeExpression innerType) {
return createStreamType("UntimedStream", innerType);
}

// Helper

protected static SymTypeOfGenerics createStreamType(
String name,
SymTypeExpression innerType
) {
IBasicSymbolsGlobalScope gs = BasicSymbolsMill.globalScope();
Optional<TypeSymbol> typeSymbol = gs.resolveType(name);
if (typeSymbol.isPresent()) {
return SymTypeExpressionFactory.createGenerics(typeSymbol.get(), innerType);
}
else {
Log.error("0xFD296 unable to resolve type "
+ name + ", unable to create the stream type.");
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// (c) https://github.com/MontiCore/monticore
package de.monticore.types3.streams;

import de.monticore.types.check.SymTypeExpression;
import de.monticore.types3.SymTypeRelations;
import de.monticore.types3.streams.util.StreamTypeRelations;
import de.se_rwth.commons.logging.Log;

/**
* relations for built-in Collection SymTypes of MCCollectionTypes
* these are List, Set, Optional, Map
* Per default, this does NOT include types that inherit from collection types
*/
public class StreamSymTypeRelations extends SymTypeRelations {

protected static StreamTypeRelations streamTypeRelations;

public static void init() {
Log.trace("init StreamTypeRelations", "TypeCheck setup");
SymTypeRelations.init();
streamTypeRelations = new StreamTypeRelations();
}

public static boolean isStream(SymTypeExpression type) {
return getStreamTypeRelations().isStream(type);
}

public static boolean isEventStream(SymTypeExpression type) {
return getStreamTypeRelations().isEventStream(type);
}

public static boolean isSyncStream(SymTypeExpression type) {
return getStreamTypeRelations().isSyncStream(type);
}

public static boolean isToptStream(SymTypeExpression type) {
return getStreamTypeRelations().isToptStream(type);
}

public static boolean isUntimedStream(SymTypeExpression type) {
return getStreamTypeRelations().isUntimedStream(type);
}

/**
* @return the Element type of a Stream.
*/
public static SymTypeExpression getStreamElementType(SymTypeExpression type) {
return getStreamTypeRelations().getStreamElementType(type);
}

// Helper

protected static StreamTypeRelations getStreamTypeRelations() {
if (streamTypeRelations == null) {
Log.error("0xFD9CB internal error: "
+ "StreamSymTypeRelations was not init()-ialized."
);
}
return streamTypeRelations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// (c) https://github.com/MontiCore/monticore
package de.monticore.types3.streams.util;

import de.monticore.types.check.SymTypeExpression;
import de.monticore.types.check.SymTypeExpressionFactory;
import de.monticore.types.check.SymTypeOfGenerics;
import de.se_rwth.commons.logging.Log;

/**
* relations for built-in Stream SymTypes
* these are Stream, EventStream, SyncStream, ToptStream.
* This does NOT include types deriving from these.
*/
public class StreamTypeRelations {

/**
* whether the type is a Stream
*/
public boolean isStream(SymTypeExpression type) {
return isSpecificStream(type, "Stream") ||
isEventStream(type) ||
isSyncStream(type) ||
isToptStream(type) ||
isUntimedStream(type);
}

public boolean isEventStream(SymTypeExpression type) {
return isSpecificStream(type, "EventStream");
}

public boolean isSyncStream(SymTypeExpression type) {
return isSpecificStream(type, "SyncStream");
}

public boolean isToptStream(SymTypeExpression type) {
return isSpecificStream(type, "ToptStream");
}

public boolean isUntimedStream(SymTypeExpression type) {
return isSpecificStream(type, "UntimedStream");
}

/**
* @return the Element type of a Stream.
*/
public SymTypeExpression getStreamElementType(SymTypeExpression type) {
if (!isStream(type)) {
Log.error("0xFD1C9 internal error: tried to get the type "
+ "of an stream's element of a non stream type");
return SymTypeExpressionFactory.createObscureType();
}
return type.asGenericType().getArgument(0);
}

// Helper

protected boolean isSpecificStream(SymTypeExpression type, String streamName) {
if (!type.isGenericType()) {
return false;
}
SymTypeOfGenerics generic = type.asGenericType();
String name = generic.getTypeConstructorFullName();
if (!name.equals(streamName)) {
return false;
}
if (generic.sizeArguments() != 1) {
Log.warn("0xFD1C3 encountered generic called "
+ name + " with "
+ generic.sizeArguments() + " type arguments, "
+ "but expected 1");
return false;
}
return true;
}

}
Loading

0 comments on commit 743836f

Please sign in to comment.