-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,202 additions
and
3,655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
monticore-grammar/src/main/java/de/monticore/types3/streams/StreamSymTypeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
monticore-grammar/src/main/java/de/monticore/types3/streams/StreamSymTypeRelations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
monticore-grammar/src/main/java/de/monticore/types3/streams/util/StreamTypeRelations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.