Example #1
0
 public void Bind(string op, IType returnType, IType inputType)
 {
     dict.TryGetValue(op, out var innerDict);
     if (innerDict == null)
     {
         innerDict = new Dictionary <IType, IType>();
         dict.Add(op, innerDict);
     }
     innerDict.TryGetValue(returnType, out var value);
     if (value != null)
     {
         throw new TranspilationException($"Operator '{op}' for type '{returnType.AsNativeName()}' already exists");
     }
     innerDict[returnType] = inputType;
 }
Example #2
0
            public IType Get(string op, IType inputType, TokenLocation loc = null)
            {
                dict.TryGetValue(op, out var innerDict);
                if (innerDict == null)
                {
                    throw new TranspilationException(
                              $"Attempting to use undeclared unary operator '{op}'",
                              loc
                              );
                }

                innerDict.TryGetValue(inputType, out var returnType);

                if (returnType == null)
                {
                    throw new TranspilationException(
                              $"Operator '{op}' is not applicable to expression of type '{inputType.AsNativeName()}'",
                              loc
                              );
                }

                return(returnType);
            }