public static TypeSymbol MakeClassTemplateInstance(Root root, IReadOnlyList<GenericsInstance> inst, TypeSymbol baseType)
 {
     var g = baseType as GenericSymbol;
     if(g != null)
     {
         var i = FindGenericIndex(inst, g);
         if (i == -1)
         {
             return baseType;
         }
         return inst[i].Type;
     }
     else if (baseType.Generics.Count > 0 || baseType.TacitGeneric.Count > 0)
     {
         var prm = new List<TypeSymbol>();
         foreach (var v in baseType.Generics)
         {
             var t = MakeClassTemplateInstance(root, inst, v);
             prm.Add(t);
         }
         var tprm = new List<TypeSymbol>();
         foreach (var v in baseType.TacitGeneric)
         {
             var t = MakeClassTemplateInstance(root, inst, v);
             tprm.Add(t);
         }
         return root.ClassManager.Issue(baseType, prm, tprm);
     }
     else
     {
         return baseType;
     }
 }
 public DyadicOperatorSymbol(TokenType type, TypeSymbol left, TypeSymbol right, TypeSymbol ret)
     : base(RoutineType.FunctionOperator, type)
 {
     Name = GetOperatorName(type);
     CalculateType = type;
     _Arguments = ArgumentSymbol.MakeParameters(left, right);
     _CallReturnType = ret;
 }
Exemple #3
0
 public EnumSymbol(string name, ProgramContext block, IReadOnlyList<AttributeSymbol> attr, TypeSymbol bt)
 {
     Name = name;
     Block = block;
     _Attribute = attr;
     _BaseType = bt;
     AppendChild(Block);
 }
 public PropertySymbol(string name, TypeSymbol type, bool isSet)
     : base(RoutineType.Routine, TokenType.Unknoun)
 {
     Name = name;
     Type = type;
     IsSet = isSet;
     _Attribute = null;
     _Arguments = null;
 }
 private static bool ContainSubType(TypeSymbol from, TypeSymbol to)
 {
     foreach(var v in from.EnumSubType())
     {
         if(v == to)
         {
             return true;
         }
     }
     return false;
 }
 public RoutineSymbol FindMonadic(TokenType op, TypeSymbol expt)
 {
     var s = OpList[op].FindAll(v => v.Arguments[0].ReturnType == expt);
     if (s.Count == 1)
     {
         return s[0];
     }
     else
     {
         return Root.ErrorRoutine;
     }
 }
 public ClassTemplateInstance(TypeSymbol type, IReadOnlyList<TypeSymbol> parameters, IReadOnlyList<TypeSymbol> tacitParameters)
     : base(ClassType.Unknown)
 {
     //if (type.Generics.Count != parameters.Count || type.TacitGeneric.Count != tacitParameters.Count)
     //{
     //    throw new ArgumentException("parameter count");
     //}
     Type = type;
     Parameters = parameters;
     TacitParameters = tacitParameters;
     InitializeChildSymbols();
 }
 public RoutineSymbol FindDyadic(TokenType op, TypeSymbol left, TypeSymbol right)
 {
     var s = OpList[op].FindAll(v => v.Arguments[0].ReturnType == left && v.Arguments[1].ReturnType == right);
     if (s.Count > 0)
     {
         return s[0];
     }
     else if(left == right)
     {
         return new DyadicOperatorSymbol(op, left, right, left);
     }
     else
     {
         return Root.ErrorRoutine;
     }
 }
 public RoutineSymbol Find(TypeSymbol from, TypeSymbol to)
 {
     var s = ConvList.FindAll(v => v.CallReturnType == to && v.Arguments[0].ReturnType == from);
     if(s.Count == 1)
     {
         return s[0];
     }
     else if(s.Count > 1)
     {
         return Root.ErrorRoutine;
     }
     else
     {
         if (ContainSubType(from, to))
         {
             return Root.Default;
         }
         else
         {
             return Root.ErrorRoutine;
         }
     }
 }
 public new void Initialize(string name, VariantType type, IReadOnlyList<AttributeSymbol> attr, TypeSymbol dt, Element def)
 {
     base.Initialize(name, type, attr, dt, def);
 }
 internal static OverLoadTypeMatch MakeMatch(Root root, TypeSymbol type, IReadOnlyList<GenericSymbol> fg, IReadOnlyList<GenericsInstance> inst, IReadOnlyList<TypeSymbol> ag)
 {
     var ig = new List<TypeSymbol>();
     var result = new OverLoadTypeMatch()
     {
         Type = type,
         FormalGenerics = fg,
         ScopeInstance = inst,
         ActualGenerics = ag,
         InstanceGenerics = ig,
     };
     if (TypeSymbol.HasAnyErrorType(fg))
     {
         result.Result = TypeMatchResult.Unknown;
         return result;
     }
     if (!ContainGenericCount(fg, ag))
     {
         result.Result = TypeMatchResult.UnmatchGenericCount;
         return result;
     }
     InitInstance(fg, ag, ig);
     var tgi = InferInstance(root, inst, ag, ig);
     if (TypeSymbol.HasAnyErrorType(tgi))
     {
         result.Result = TypeMatchResult.UnmatchGenericType;
         return result;
     }
     result.Result = TypeMatchResult.PerfectMatch;
     result.Type = GenericsInstance.MakeClassTemplateInstance(root, tgi, type);
     return result;
 }
 internal static OverLoadTypeMatch MakeUnknown(TypeSymbol type)
 {
     return new OverLoadTypeMatch { Type = type, Result = TypeMatchResult.Unknown };
 }
 internal static OverLoadTypeMatch MakeNotType(TypeSymbol type)
 {
     return new OverLoadTypeMatch { Type = type, Result = TypeMatchResult.NotType };
 }
 public void Initialize(string name, RoutineType type, TokenType opType, IReadOnlyList<AttributeSymbol> attr, IReadOnlyList<GenericSymbol> gnr, IReadOnlyList<ArgumentSymbol> arg, TypeSymbol rt)
 {
     if (IsInitialize)
     {
         throw new InvalidOperationException();
     }
     IsInitialize = true;
     Name = name;
     RoutineType = type;
     OperatorType = opType;
     Block = new ProgramContext();
     _Attribute = attr;
     _Generics = gnr;
     _Arguments = arg;
     _CallReturnType = rt;
     AppendChild(Block);
 }
 public void Initialize(string name, VariantType type, IReadOnlyList<AttributeSymbol> attr, TypeSymbol dt, Element def = null)
 {
     if(IsInitialize)
     {
         throw new InvalidOperationException();
     }
     IsInitialize = true;
     Name = name;
     VariantType = type;
     DefaultValue = def;
     AppendChild(DefaultValue);
     _Attribute = attr;
     _DataType = dt;
 }
 internal static IReadOnlyList<TypeSymbol> MakeArgument(int count, TypeSymbol scope)
 {
     if (count < 0)
     {
         throw new ArgumentException("count");
     }
     var ret = new List<TypeSymbol>();
     for (var i = 0; i < count; ++i)
     {
         ret.Add(scope);
     }
     return ret;
 }
 private static TypeSymbol GetCommonSubType(TypeSymbol t1, TypeSymbol t2)
 {
     return t1; //todo 処理の順序で結果が変わるバグに対処する。共通のサブタイプを返すようにする。
 }
 public DefaultSymbol(string name, TypeSymbol parent)
     : base(RoutineType.Routine, TokenType.Unknoun)
 {
     Name = name;
     _CallReturnType = parent;
 }
Exemple #19
0
 internal static bool HasAnyErrorType(TypeSymbol scope)
 {
     var cti = scope as ClassTemplateInstance;
     if(cti != null)
     {
         if (HasAnyErrorType(cti.Parameters) || HasAnyErrorType(cti.TacitGeneric))
         {
             return true;
         }
     }
     else if (scope is VoidSymbol || scope is UnknownSymbol || scope is ErrorTypeSymbol)
     {
         return true;
     }
     return false;
 }
 public IEnumerable<RoutineSymbol> GetAllInitializer(TypeSymbol type)
 {
     return ConvList.FindAll(v => v.CallReturnType == type);
 }