Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public EnumSymbol(string name, ProgramContext block, IReadOnlyList<AttributeSymbol> attr, TypeSymbol bt)
 {
     Name = name;
     Block = block;
     _Attribute = attr;
     _BaseType = bt;
     AppendChild(Block);
 }
Ejemplo n.º 4
0
 public PropertySymbol(string name, TypeSymbol type, bool isSet)
     : base(RoutineType.Routine, TokenType.Unknoun)
 {
     Name = name;
     Type = type;
     IsSet = isSet;
     _Attribute = null;
     _Arguments = null;
 }
Ejemplo n.º 5
0
 private static bool ContainSubType(TypeSymbol from, TypeSymbol to)
 {
     foreach(var v in from.EnumSubType())
     {
         if(v == to)
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 6
0
 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();
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 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;
         }
     }
 }
Ejemplo n.º 10
0
 public new void Initialize(string name, VariantType type, IReadOnlyList<AttributeSymbol> attr, TypeSymbol dt, Element def)
 {
     base.Initialize(name, type, attr, dt, def);
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 internal static OverLoadTypeMatch MakeUnknown(TypeSymbol type)
 {
     return new OverLoadTypeMatch { Type = type, Result = TypeMatchResult.Unknown };
 }
Ejemplo n.º 13
0
 internal static OverLoadTypeMatch MakeNotType(TypeSymbol type)
 {
     return new OverLoadTypeMatch { Type = type, Result = TypeMatchResult.NotType };
 }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
 private static TypeSymbol GetCommonSubType(TypeSymbol t1, TypeSymbol t2)
 {
     return t1; //todo 処理の順序で結果が変わるバグに対処する。共通のサブタイプを返すようにする。
 }
Ejemplo n.º 18
0
 public DefaultSymbol(string name, TypeSymbol parent)
     : base(RoutineType.Routine, TokenType.Unknoun)
 {
     Name = name;
     _CallReturnType = parent;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 20
0
 public IEnumerable<RoutineSymbol> GetAllInitializer(TypeSymbol type)
 {
     return ConvList.FindAll(v => v.CallReturnType == type);
 }