public ConstantInfo(IJConstant value, JAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetNamespaceFromObjects(value.Type)) { _value = value; _memberType = value.MemberType; _builtinInfo = ((BuiltinClassInfo)projectState.GetNamespaceFromObjects(value.Type)).Instance; }
public ConstantInfo(object value, JAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetNamespaceFromObjects(projectState.GetTypeFromObject(value))) { _value = value; _memberType = JMemberType.Constant; _builtinInfo = ((BuiltinClassInfo)projectState.GetNamespaceFromObjects(_type)).Instance; }
internal static IAnalysisSet NumericOp(Node node, BuiltinInstanceInfo lhs, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { var res = AnalysisSet.Empty; var lhsType = lhs.TypeId; foreach(var ns in rhs) { var rhsType = ns.TypeId; // First handle string operations if (lhsType == BuiltinTypeId.Bytes || lhsType == BuiltinTypeId.Unicode) { if (operation == PythonOperator.Mod) { res = res.Union(lhs.ClassInfo.Instance); } else if (operation == PythonOperator.Add && (rhsType == BuiltinTypeId.Bytes || rhsType == BuiltinTypeId.Unicode)) { res = res.Union(lhs.ClassInfo.Instance); } else if (operation == PythonOperator.Multiply && (rhsType == BuiltinTypeId.Int || rhsType == BuiltinTypeId.Long)) { res = res.Union(lhs.ClassInfo.Instance); } continue; } else if (operation == PythonOperator.Multiply && (lhsType == BuiltinTypeId.Int || lhsType == BuiltinTypeId.Long)) { if (rhsType == BuiltinTypeId.Str || rhsType == BuiltinTypeId.Bytes || rhsType == BuiltinTypeId.Unicode || rhsType == BuiltinTypeId.Tuple || rhsType == BuiltinTypeId.List) { res = res.Union(unit.ProjectState.ClassInfos[rhsType].Instance); continue; } } // These specializations change rhsType before type promotion // rules are applied. if ((operation == PythonOperator.TrueDivide || (operation == PythonOperator.Divide && unit.ProjectState.LanguageVersion.Is3x())) && (lhsType == BuiltinTypeId.Int || lhsType == BuiltinTypeId.Long) && (rhsType == BuiltinTypeId.Int || rhsType == BuiltinTypeId.Long)) { rhsType = BuiltinTypeId.Float; } // Type promotion rules are applied if (lhsType == BuiltinTypeId.Unknown || lhsType > BuiltinTypeId.Complex || rhsType == BuiltinTypeId.Unknown || rhsType > BuiltinTypeId.Complex) { // Non-numeric types require the reverse operation res = res.Union(ns.ReverseBinaryOperation(node, unit, operation, lhs)); } else if (lhsType == BuiltinTypeId.Complex || rhsType == BuiltinTypeId.Complex) { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Complex].Instance); } else if (lhsType == BuiltinTypeId.Float || rhsType == BuiltinTypeId.Float) { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Float].Instance); } else if (lhsType == BuiltinTypeId.Long || rhsType == BuiltinTypeId.Long) { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Long].Instance); } else { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Int].Instance); } } return res.Count > 0 ? res : null; }
private object GenerateTypeName(AnalysisValue baseClass, bool isRef) { ClassInfo ci = baseClass as ClassInfo; if (ci != null) { return(GetTypeName(((ProjectEntry)ci.DeclaringModule).GetModuleInfo().Name, ci.ClassDefinition.Name)); } BuiltinClassInfo bci = baseClass as BuiltinClassInfo; if (bci != null) { return(GenerateTypeName(bci._type)); } IterableValue iteri = baseClass as IterableValue; if (iteri != null) { return(GenerateTypeName(iteri.PythonType, isRef, iteri.IndexTypes)); } InstanceInfo ii = baseClass as InstanceInfo; if (ii != null) { return(GenerateTypeName(ii.ClassInfo, isRef)); } BuiltinInstanceInfo bii = baseClass as BuiltinInstanceInfo; if (bii != null) { return(GenerateTypeName(bii.ClassInfo, isRef)); } return(GenerateTypeName(baseClass.PythonType)); }
internal ConstantInfo(BuiltinClassInfo klass, object value, PythonMemberType memberType) : base(klass) { _value = value; _memberType = memberType; _builtinInfo = klass.Instance; }
public ConstantInfo(IPythonConstant value, PythonAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)) { _value = value; _memberType = value.MemberType; _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)).Instance; }
public ConstantInfo(object value, PythonAnalyzer projectState) : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjectsThrowOnNull(projectState.GetTypeFromObject(value))) { _value = value; _memberType = PythonMemberType.Constant; _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(_type)).Instance; }