Просмотр исходного кода

First draft of new type system implementation

Andreas Mülder 11 лет назад
Родитель
Сommit
4e934047a6

+ 11 - 18
plugins/org.yakindu.base.expressions/src/org/yakindu/base/expressions/inferrer/ExpressionsTypeInferrerMessages.java

@@ -1,3 +1,13 @@
+/**
+ * Copyright (c) 2014 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
 package org.yakindu.base.expressions.inferrer;
 
 public interface ExpressionsTypeInferrerMessages {
@@ -13,22 +23,5 @@ public interface ExpressionsTypeInferrerMessages {
 	public static final String COMMON_TYPE = "Could not determine a common type for %s and %s.";
 	public static final String CONDITIONAL_BOOLEAN = "conditional expression must be of type boolean.";
 	public static final String CAST_OPERATORS = "Cannot cast from %s to %s.";
-	
-//	public static final String COULD_NOT_INFER_A_TYPE_FOR_THE_OPERATION_NO_TYPE = "Could not infer a type for the operation %s, because no type was inferred for its operand.";
-//	public static final String COULD_NOT_INFER_A_TYPE_FOR_THE_OPERATION_NOT_INFERRED = "Could not infer a type for the operation %s, because types were not inferred for all of its operands.";
-//
-//	public static final String OPERATOR_MAY_ONLY_BE_APPLIED_ON_A_PRIMITIVE_TYPE = "Operator %s may only be applied on a primitive type.";
-//
-//	public static final String BITWISE_OPERATOR_MAY_ONLY_BE_APPLIED_ON_INTEGER_TYPES = "Bitwise operator '%s' may only be applied on integer types, not on %s.";
-//
-//	public static final String ARITHMETIC_OPERATORS_MAY_ONLY_BE_APPLIED_ON_NUMERIC_TYPES_2 = "Arithmetic operator '%s' may only be applied on numeric types, not on %s and %s.";
-//
-//	public static final String LOGICAL_OPERATORS_MAY_ONLY_BE_APPLIED_ON_BOOLEAN_TYPES = "Logical operator '%s' may only be applied on boolean types, not on %s.";
-//
-//	public static final String COMPARSION_OPERATOR_MAY_ONLY_BE_APPLIED_ON_COMPATIBLE_TYPES = "Comparison operator '%s' may only be applied on compatible types, not on %s and %s.";
-//
-//	public static final String ASSIGNMENT_AND_EQUALITY_OPERATIONS_MAY_ONLY_BE_APPLIED_ON_TYPES_OF_THE_SAME_KIND = "Assignment and equality operations may only be applied on types of the same kind, not on %s and %s.";
-//
-//
-//	
+
 }

+ 1 - 0
plugins/org.yakindu.base.expressions/src/org/yakindu/base/expressions/scoping/ExpressionsScopeProvider.xtend

@@ -12,4 +12,5 @@ package org.yakindu.base.expressions.scoping
  */
 class ExpressionsScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {
 
+
 }

+ 18 - 0
plugins/org.yakindu.base.types/src/org/yakindu/base/types/inferrer/AbstractTypeSystemInferrer.java

@@ -105,6 +105,8 @@ public abstract class AbstractTypeSystemInferrer implements ITypeSystemInferrer
 	}
 
 	protected void assertType(Type type1, String msg, Type... types) {
+		if (type1 == null)
+			return;
 		boolean same = false;
 		for (Type type : types) {
 			if (typeSystem.isSame(type1, type)) {
@@ -116,19 +118,35 @@ public abstract class AbstractTypeSystemInferrer implements ITypeSystemInferrer
 		}
 	}
 
+	protected void assertNotType(Type type1, String msg, Type... types) {
+		if(type1 == null)
+			return;
+		for (Type type : types) {
+			if (typeSystem.isSame(type1, type)) {
+				error(msg != null ? msg : "Expected one of " + Arrays.toString(types) + " but was " + type1);
+			}
+		}
+	}
+
 	protected void assertSame(Type type1, Type type2, String msg) {
+		if(type1 == null || type2 == null)
+			return;
 		if (!typeSystem.isSame(type1, type2)) {
 			error(msg != null ? msg : "Types not the same : " + type1 + " and " + type2);
 		}
 	}
 
 	protected void assertCompatibleType(Type type1, Type type2, String msg) {
+		if(type1 == null || type2 == null)
+			return;
 		if (!typeSystem.haveCommonType(type1, type2)) {
 			error(msg != null ? msg : "Incompatible types " + type1 + " and " + type2);
 		}
 	}
 
 	protected void assertIsSuperType(Type subType, Type superType, String msg) {
+		if(subType == null || superType == null)
+			return;
 		if (!typeSystem.isSuperType(subType, superType)) {
 			error(msg != null ? msg : "Incompatible types " + subType + " and " + superType);
 		}