public bool Match(UnionType ut) { foreach (UnionAlternative a in ut.Alternatives.Values) { Pointer p = a.DataType as Pointer; if (p == null) return false; if (pointerSize == 0) pointerSize = p.Size; else if (pointerSize != p.Size) return false; EquivalenceClass eq = p.Pointee as EquivalenceClass; if (eq == null) return false; StructureType s = eq.DataType as StructureType; if (s == null) return false; eqClasses.Add(eq); strs.Add(s); } return true; }
public void CmpUnionToUnion() { //Warning : inner types were selected in such a way as to force UnionAlternativeCollection // to place them in provided order. DataType inner1 = PrimitiveType.UInt32; DataType inner2 = PrimitiveType.UInt16; DataType inner3 = PrimitiveType.UInt8; UnionType u1 = new UnionType("Union1",inner1,inner3,inner1); UnionType u2 = new UnionType("Union1",inner1,inner3,inner2); DataTypeComparer c = new DataTypeComparer(); Assert.AreNotEqual(0, c.Compare(u1, u2)); }
public void StrFldMerger_FindOverLappingClusterWithEqv() { StructureType str = new StructureType("foo", 0); UnionType u = new UnionType(null, null, PrimitiveType.Pointer32, PrimitiveType.Word16); EquivalenceClass eq = Eqv(u); str.Fields.Add(2, eq); str.Fields.Add(4, PrimitiveType.SegmentSelector); IEnumerable<List<StructureField>> eb = sfm.GetOverlappingClusters(str.Fields); IEnumerator<List<StructureField>> e = eb.GetEnumerator(); Assert.IsTrue(e.MoveNext()); Assert.AreEqual(3, e.Current.Count); List<StructureField> cluster = e.Current; }
public void NotMatch() { TypeVariable t1 = new TypeVariable(1); TypeVariable t2 = new TypeVariable(2); EquivalenceClass c1 = new EquivalenceClass(t1); EquivalenceClass c2 = new EquivalenceClass(t2); c1.DataType = new StructureType{ Fields = { { 4, PrimitiveType.Word16 } } }; c2.DataType = new StructureType { Fields = { { 20, PrimitiveType.Word32 } } }; t1.Class = c1; t2.Class = c2; UnionType u = new UnionType(null, null); u.Alternatives.Add(new Pointer(c1, 4)); u.Alternatives.Add(new Pointer(PrimitiveType.Word16, 4)); UnionPointersStructuresMatcher upsm = new UnionPointersStructuresMatcher(); Assert.IsFalse(upsm.Match(u)); }
public void Setup() { store = new TypeStore(); factory = new TypeFactory(); globals = new Identifier("globals", PrimitiveType.Word32, null); StructureType point = new StructureType("Point", 0) { Fields = { { 0, PrimitiveType.Word32, null }, { 4, PrimitiveType.Word32, null } } }; TypeVariable tvPoint = store.CreateTypeVariable(factory); EquivalenceClass eq = new EquivalenceClass(tvPoint) { DataType = point }; tvPoint.DataType = eq; ptrPoint = new Pointer(eq, 4); UnionType u = new UnionType("RealInt", null) { Alternatives = { new UnionAlternative("w", PrimitiveType.Word32, 0), new UnionAlternative("r", PrimitiveType.Real32, 1), } }; TypeVariable tvUnion = store.CreateTypeVariable(factory); eq = new EquivalenceClass(tvUnion) { DataType = u }; tvUnion.DataType = eq; ptrUnion = new Pointer(eq, 4); ptrInt = new Pointer(PrimitiveType.Int32, 4); ptrWord = new Pointer(PrimitiveType.Word32, 4); m = new ExpressionEmitter(); }
static AbstractType HandleClassLikeMatch (DClassLike dc, ResolutionContext ctxt, object typeBase, bool canResolveBase) { AbstractType ret; UserDefinedType udt = null; var invisibleTypeParams = GetInvisibleTypeParameters (dc, ctxt); switch (dc.ClassType) { case DTokens.Struct: ret = new StructType (dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; case DTokens.Union: ret = new UnionType (dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; case DTokens.Class: udt = new ClassType (dc, typeBase as ISyntaxRegion, null, null, invisibleTypeParams); ret = null; break; case DTokens.Interface: udt = new InterfaceType (dc, typeBase as ISyntaxRegion, null, invisibleTypeParams); ret = null; break; case DTokens.Template: if (dc.ContainsAttribute (DTokens.Mixin)) ret = new MixinTemplateType (dc, typeBase as ISyntaxRegion, invisibleTypeParams); else ret = new TemplateType (dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; default: ret = null; ctxt.LogError (new ResolutionError (dc, "Unknown type (" + DTokens.GetTokenString (dc.ClassType) + ")")); break; } if (dc.ClassType == DTokens.Class || dc.ClassType == DTokens.Interface) ret = canResolveBase ? DResolver.ResolveBaseClasses (udt, ctxt) : udt; return ret; }
private BooleanVal2(UnionType <True, False> input) : base(input) { }
/// <summary> /// The variable's or method's base type will be resolved (if auto type, the intializer's type will be taken). /// A class' base class will be searched. /// etc.. /// </summary> public static AbstractType HandleNodeMatch( INode m, ResolverContextStack ctxt, AbstractType resultBase = null, object typeBase = null) { stackNum_HandleNodeMatch++; bool popAfterwards = m.Parent != ctxt.ScopedBlock && m.Parent is IBlockNode; if (popAfterwards) ctxt.PushNewScope((IBlockNode)m.Parent); //HACK: Really dirty stack overflow prevention via manually counting call depth var canResolveBaseGenerally = stackNum_HandleNodeMatch < 6; var DoResolveBaseType = canResolveBaseGenerally && !ctxt.Options.HasFlag(ResolutionOptions.DontResolveBaseClasses) && (m.Type == null || m.Type.ToString(false) != m.Name); AbstractType ret = null; // To support resolving type parameters to concrete types if the context allows this, introduce all deduced parameters to the current context if (canResolveBaseGenerally && resultBase is DSymbol) ctxt.CurrentContext.IntroduceTemplateParameterTypes((DSymbol)resultBase); // Only import symbol aliases are allowed to search in the parse cache if (m is ImportSymbolAlias) { var isa = (ImportSymbolAlias)m; if (isa.IsModuleAlias ? isa.Type != null : isa.Type.InnerDeclaration != null) { var mods = new List<DModule>(); var td=isa.IsModuleAlias ? isa.Type : isa.Type.InnerDeclaration; foreach (var mod in ctxt.ParseCache.LookupModuleName(td.ToString())) mods.Add(mod as DModule); if(mods.Count == 0) ctxt.LogError(new NothingFoundError(isa.Type)); else if(mods.Count > 1) { var m__=new List<ISemantic>(); foreach(var mod in mods) m__.Add(new ModuleSymbol(mod, isa.Type)); ctxt.LogError(new AmbiguityError(isa.Type,m__)); } var bt=mods.Count != 0 ? (AbstractType)new ModuleSymbol(mods[0], td) : null; //TODO: Is this correct behaviour? if (!isa.IsModuleAlias){ var furtherId = ResolveFurtherTypeIdentifier(isa.Type.ToString(false), new[]{ bt }, ctxt, isa.Type); ctxt.CheckForSingleResult(furtherId, isa.Type); if (furtherId != null && furtherId.Length != 0) bt = furtherId[0]; else bt = null; } ret = new AliasedType(isa, bt, isa.Type); } } else if (m is DVariable) { var v = (DVariable)m; AbstractType bt = null; if (DoResolveBaseType) { var bts = TypeDeclarationResolver.Resolve(v.Type, ctxt); if (bts != null && bts.Length != 0 && ctxt.CheckForSingleResult(bts, v.Type)) bt = bts[0]; // For auto variables, use the initializer to get its type else if (v.Initializer != null) bt = ExpressionSemantics.Evaluation.EvaluateType(v.Initializer, ctxt); // Check if inside an foreach statement header if (bt == null && ctxt.ScopedStatement != null) bt = GetForeachIteratorType(v, ctxt); } // Note: Also works for aliases! In this case, we simply try to resolve the aliased type, otherwise the variable's base type ret=v.IsAlias ? (DSymbol)new AliasedType(v, bt, typeBase as ISyntaxRegion) : new MemberSymbol(v, bt, typeBase as ISyntaxRegion); } else if (m is DMethod) { ret = new MemberSymbol((DNode)m, DoResolveBaseType ? GetMethodReturnType((DMethod)m, ctxt) : null , typeBase as ISyntaxRegion); } else if (m is DClassLike) { UserDefinedType udt = null; var dc=(DClassLike)m; switch (dc.ClassType) { case DTokens.Struct: udt = new StructType(dc, typeBase as ISyntaxRegion); break; case DTokens.Union: udt = new UnionType(dc, typeBase as ISyntaxRegion); break; case DTokens.Class: udt = new ClassType(dc, typeBase as ISyntaxRegion, null); break; case DTokens.Template: udt = new TemplateType(dc, typeBase as ISyntaxRegion); break; case DTokens.Interface: udt = new InterfaceType(dc, typeBase as ISyntaxRegion); break; default: ctxt.LogError(new ResolutionError(m, "Unknown type ("+DTokens.GetTokenString(dc.ClassType)+")")); break; } if (canResolveBaseGenerally && !ctxt.Options.HasFlag(ResolutionOptions.DontResolveBaseClasses)) ret = DResolver.ResolveBaseClasses(udt, ctxt); else ret = udt; } else if (m is IAbstractSyntaxTree) { var mod = (IAbstractSyntaxTree)m; if (typeBase != null && typeBase.ToString() != mod.ModuleName) { var pack = ctxt.ParseCache.LookupPackage(typeBase.ToString()).First(); if (pack != null) ret = new PackageSymbol(pack, typeBase as ISyntaxRegion); } else ret = new ModuleSymbol(m as DModule, typeBase as ISyntaxRegion); } else if (m is DEnum) ret = new EnumType((DEnum)m, typeBase as ISyntaxRegion); else if (m is TemplateParameterNode) { var tmp = ((TemplateParameterNode)m).TemplateParameter; //ResolveResult[] templateParameterType = null; //TODO: Resolve the specialization type //var templateParameterType = TemplateInstanceHandler.ResolveTypeSpecialization(tmp, ctxt); ret = new MemberSymbol((DNode)m, null, typeBase as ISyntaxRegion); } if (canResolveBaseGenerally && resultBase is DSymbol) ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals((DSymbol)resultBase); if (popAfterwards) ctxt.Pop(); stackNum_HandleNodeMatch--; return ret; }
public override object Exec(UnionType t, object arg) { this.codeGenerator.ldelemRef(this.indent); return(null); }
public void Visit(UnionType type) { throw new NotImplementedException(); }
public void StrFldMerger_Merge() { StructureType str = new StructureType("foo", 0); UnionType u = new UnionType(null, null, PrimitiveType.Pointer32, PrimitiveType.Word16); EquivalenceClass eq = Eqv(u); str.Fields.Add(2, eq); str.Fields.Add(4, PrimitiveType.SegmentSelector); StructureType strNew = sfm.Merge(str); Assert.AreEqual("(struct \"foo\" (2 (union (ptr32 u0) ((struct (0 word16 w0000) (2 selector pseg0002)) u1)) u0002))", strNew.ToString()); }
public override object Exec(UnionType from, object arg) { return(from.AcceptOperation(PromotionOperation.Create(this.to, AssignmentOperator.Assign, this.methodAnalyzed, this.location, this.NotifyError), arg)); }
/// <summary> /// 执行表连接查询,该方法可连接两个不同的表 /// </summary> /// <typeparam name="TModel1">要连接的数据库实体对象</typeparam> /// <typeparam name="TModel2">要连接的数据库实体对象</typeparam> /// <param name="alisName">主表的别名</param> /// <param name="unionAlisName">连接表的别名</param> /// <param name="unionType">连接类型</param> /// <param name="predicate">On 的查询表达式</param> /// <returns></returns> public QueryContext <T> Union <TModel1, TModel2>(string alisName, string unionAlisName, UnionType unionType, Expression <Func <TModel1, TModel2, bool> > predicate) { Type type = typeof(TModel1); var last = UnionList.Where(f => f.Model.Equals(type) && f.UnionAlisName == alisName).FirstOrDefault(); if (alisName != masterAlisName && last == null) { ExpressionUnionModel u2 = new ExpressionUnionModel { Model = typeof(TModel1), MasterType = typeof(T), Body = predicate.Body, UnionType = unionType, AlisName = alisName, UnionAlisName = alisName }; UnionList.Add(u2); } ExpressionUnionModel us = new ExpressionUnionModel { Model = typeof(TModel2), MasterType = typeof(TModel1), Body = predicate.Body, UnionType = unionType, AlisName = alisName, UnionAlisName = unionAlisName }; UnionList.Add(us); return(this); }
public void Add(DataType key, DataType val) { KeyType = UnionType.Union(KeyType, key); ValueType = UnionType.Union(ValueType, val); }
public UnionTypeControllerGenerator(UnionType unionType, SchemaBuilder schema) { _unionType = unionType; _schema = schema; }
/// <summary> /// 执行表连接查询 /// </summary> /// <typeparam name="TModel">要连接的数据库实体对象</typeparam> /// <param name="alisName">连接的别名</param> /// <param name="unionType">连接类型</param> /// <param name="predicate">On 的查询表达式</param> /// <returns></returns> public QueryContext <T> Union <TModel>(string alisName, UnionType unionType, Expression <Func <T, TModel, bool> > predicate) => Union <T, TModel>("a", alisName, unionType, predicate);
public void Type_validation_narrowing_on_union_types(TypeSymbolValidationFlags validationFlags, DiagnosticLevel expectedDiagnosticLevel) { var customTypes = new [] { TestTypeHelper.CreateCustomResourceType("My.Rp/myType", "2020-01-01", validationFlags, new TypeProperty("stringOrInt", UnionType.Create(LanguageConstants.String, LanguageConstants.Int)), new TypeProperty("unspecifiedStringOrInt", UnionType.Create(LanguageConstants.String, LanguageConstants.Int)), new TypeProperty("abcOrDef", UnionType.Create(new StringLiteralType("abc"), new StringLiteralType("def"))), new TypeProperty("unspecifiedAbcOrDef", UnionType.Create(new StringLiteralType("abc"), new StringLiteralType("def")))), TestTypeHelper.CreateCustomResourceType("My.Rp/myDependentType", "2020-01-01", validationFlags, new TypeProperty("stringOnly", LanguageConstants.String), new TypeProperty("abcOnly", new StringLiteralType("abc")), new TypeProperty("abcOnlyUnNarrowed", new StringLiteralType("abc")), new TypeProperty("stringOrIntUnNarrowed", UnionType.Create(LanguageConstants.String, LanguageConstants.Int)), new TypeProperty("abcOrDefUnNarrowed", UnionType.Create(new StringLiteralType("abc"), new StringLiteralType("def"), new StringLiteralType("ghi")))), }; var program = @" resource myRes 'My.Rp/myType@2020-01-01' = { name: 'steve' properties: { stringOrInt: 'abc' abcOrDef: 'abc' } } resource myDependentRes 'My.Rp/myDependentType@2020-01-01' = { name: 'steve' properties: { stringOnly: myRes.properties.stringOrInt // should be allowed abcOnly: myRes.properties.abcOrDef abcOnlyUnNarrowed: myRes.properties.unspecifiedAbcOrDef stringOrIntUnNarrowed: myRes.properties.unspecifiedStringOrInt abcOrDefUnNarrowed: myRes.properties.abcOrDef } } "; var model = GetSemanticModelForTest(program, customTypes); model.GetAllDiagnostics().Should().SatisfyRespectively( x => x.Should().HaveCodeAndSeverity("BCP036", expectedDiagnosticLevel).And.HaveMessage("The property \"abcOnlyUnNarrowed\" expected a value of type \"'abc'\" but the provided value is of type \"'abc' | 'def'\".") ); }
/// <summary> /// 联合查询 /// 会清除父查询的排序 /// </summary> /// <typeparam name="TResult2"></typeparam> /// <param name="resultSelect"></param> /// <param name="unionType"></param> /// <returns></returns> public LambdaQueryResultSelect <TResult> Union <TResult2>(LambdaQueryResultSelect <TResult2> resultSelect, UnionType unionType = UnionType.UnionAll) { BaseQuery.__QueryOrderBy = "";//清除OrderBy BaseQuery.AddUnion(resultSelect.BaseQuery, unionType); return(this); }
private BooleanVal3(UnionType <True, False, Null> input) : base(input) { }
public void UnifyIntoUnion(UnionType u, DataType dt) { foreach (UnionAlternative alt in u.Alternatives.Values) { if (AreCompatible(alt.DataType, dt)) { alt.DataType = Unify(alt.DataType, dt); return; } } u.Alternatives.Add(new UnionAlternative(dt, u.Alternatives.Count)); }
public virtual object Exec(UnionType u, object arg) { return(Exec((TypeExpression)u, arg)); }
public void ArrayOfUnions() { var ut = new UnionType(null, null, false); ut.AddAlternative(PrimitiveType.Word32); ut.AddAlternative(PrimitiveType.Real64); ArrayType a = new ArrayType(ut, 0); TypeVariable tv = store.CreateTypeVariable(factory); tv.Class.DataType = a; Assert.AreEqual(1, store.UsedEquivalenceClasses.Count); tv.Class.DataType.Accept(nct); Assert.AreEqual(2, store.UsedEquivalenceClasses.Count); Assert.AreEqual( "(arr Eq_2)", store.UsedEquivalenceClasses[0].DataType.ToString()); Assert.AreEqual( "(union (real64 u1) (word32 u0))", store.UsedEquivalenceClasses[1].DataType.ToString()); }
// merge one more type into the type // used by stateful assignments which we can't track down the control flow public void addType(DataType t) { type = UnionType.Union(type, t); }
public CGRuntimeUnionTypePromotionOperation(int indent, T ilCodeGenerator, UnionType union) { this.indent = indent; this.codeGenerator = ilCodeGenerator; this.union = union; }
/// <summary> /// Called when an application of a function is encountered. /// </summary> //$TODO: move to Analyzer. public static DataType Apply( Analyzer analyzer, FunType func, List <DataType> pos, IDictionary <string, DataType> hash, DataType kw, DataType star, Exp call) { analyzer.RemoveUncalled(func); if (func.Definition != null && !func.Definition.called) { analyzer.CalledFunctions++; func.Definition.called = true; } if (func.Definition == null) { // func without definition (possibly builtins) return(func.GetReturnType()); } else if (call != null && analyzer.inStack(call)) { // Recursive call, ignore. func.SelfType = null; return(DataType.Unknown); } if (call != null) { analyzer.pushStack(call); } var pTypes = new List <DataType>(); // Python: bind first parameter to self type if (func.SelfType != null) { pTypes.Add(func.SelfType); } else if (func.Class != null) { pTypes.Add(func.Class.getCanon()); } if (pos != null) { pTypes.AddRange(pos); } BindMethodAttrs(analyzer, func); State funcTable = new State(func.env, State.StateType.FUNCTION); if (func.Table.Parent != null) { funcTable.Path = func.Table.Parent.extendPath(analyzer, func.Definition.name.Name); } else { funcTable.Path = func.Definition.name.Name; } DataType fromType = BindParameters(analyzer, call, func.Definition, funcTable, func.Definition.parameters, func.Definition.vararg, func.Definition.kwarg, pTypes, func.defaultTypes, hash, kw, star); DataType cachedTo = func.getMapping(fromType); if (cachedTo != null) { func.SelfType = null; return(cachedTo); } else { DataType toType = func.Definition.body.Accept(new TypeTransformer(funcTable, analyzer)); if (missingReturn(toType)) { analyzer.putProblem(func.Definition.name, "Function doesn't always return a value"); if (call != null) { analyzer.putProblem(call, "Call doesn't always return a value"); } } toType = UnionType.remove(toType, DataType.Cont); func.addMapping(fromType, toType); func.SelfType = null; return(toType); } }
protected override DslKeywordSchema VisitUnion(UnionType armUnion) { return(new OpenKeywordSchema(s_parameterBuilder.Visit(armUnion), useParametersForCompletions: true)); }
/// <summary> /// Binds the parameters of a call to the called function. /// </summary> /// <param name="analyzer"></param> /// <param name="call"></param> /// <param name="func"></param> /// <param name="funcTable"></param> /// <param name="parameters"></param> /// <param name="rest"></param> /// <param name="restKw"></param> /// <param name="pTypes"></param> /// <param name="dTypes"></param> /// <param name="hash"></param> /// <param name="kw"></param> /// <param name="star"></param> /// <returns></returns> private static DataType BindParameters( Analyzer analyzer, Node call, FunctionDef func, State funcTable, List <Parameter> parameters, Identifier rest, Identifier restKw, List <DataType> pTypes, List <DataType> dTypes, IDictionary <string, DataType> hash, DataType kw, DataType star) { TupleType fromType = analyzer.TypeFactory.CreateTuple(); int pSize = parameters == null ? 0 : parameters.Count; int aSize = pTypes == null ? 0 : pTypes.Count; int dSize = dTypes == null ? 0 : dTypes.Count; int nPos = pSize - dSize; if (star != null && star is ListType list) { star = list.toTupleType(); } for (int i = 0, j = 0; i < pSize; i++) { Parameter param = parameters[i]; DataType aType; if (i < aSize) { aType = pTypes[i]; } else if (i - nPos >= 0 && i - nPos < dSize) { aType = dTypes[i - nPos]; } else { if (hash != null && hash.ContainsKey(parameters[i].Id.Name)) { aType = hash[parameters[i].Id.Name]; hash.Remove(parameters[i].Id.Name); } else { if (star != null && star is TupleType && j < ((TupleType)star).eltTypes.Count) { aType = ((TupleType)star).get(j++); } else { aType = DataType.Unknown; if (call != null) { analyzer.putProblem(parameters[i].Id, //$REVIEW: should be using identifiers "unable to bind argument:" + parameters[i]); } } } } funcTable.Bind(analyzer, param.Id, aType, BindingKind.PARAMETER); fromType.add(aType); } if (restKw != null) { DataType dt; if (hash != null && hash.Count > 0) { DataType hashType = UnionType.newUnion(hash.Values); dt = analyzer.TypeFactory.CreateDict(DataType.Str, hashType); } else { dt = DataType.Unknown; } funcTable.Bind( analyzer, restKw, dt, BindingKind.PARAMETER); } if (rest != null) { if (pTypes.Count > pSize) { DataType restType = analyzer.TypeFactory.CreateTuple(pTypes.subList(pSize, pTypes.Count).ToArray()); funcTable.Bind(analyzer, rest, restType, BindingKind.PARAMETER); } else { funcTable.Bind( analyzer, rest, DataType.Unknown, BindingKind.PARAMETER); } } return(fromType); }
public void Casing_issues_are_corrected() { var bicepFile = @" resource resA 'My.Rp/resA@2020-01-01' = { name: 'resA' properties: { lowerCaseProp: 'abc' camelcaseprop: 'def' 'lowerCaseQuoted=+.Prop': 'ghi' 'camelcasequoted=+.prop': 'jkl' lowerCaseEnumProp: 'MyEnum' pascalCaseEnumProp: 'myenum' lowerCaseEnumUnionProp: 'MyEnum' pascalCaseEnumUnionProp: 'myenum' } } output myObj object = { lowerCaseProp: resA.properties.lowerCaseProp camelcaseprop: resA.properties.camelcaseprop } "; var typeDefinition = ResourceTypeProviderHelper.CreateCustomResourceType("My.Rp/resA", "2020-01-01", TypeSymbolValidationFlags.WarnOnTypeMismatch, new TypeProperty("lowercaseprop", LanguageConstants.String), new TypeProperty("camelCaseProp", LanguageConstants.String), new TypeProperty("lowercasequoted=+.prop", LanguageConstants.String), new TypeProperty("camelCaseQuoted=+.Prop", LanguageConstants.String), new TypeProperty("lowerCaseEnumProp", new StringLiteralType("myenum")), new TypeProperty("pascalCaseEnumProp", new StringLiteralType("MyEnum")), new TypeProperty("lowerCaseEnumUnionProp", UnionType.Create(new StringLiteralType("myenum"), new StringLiteralType("blahblah"))), new TypeProperty("pascalCaseEnumUnionProp", UnionType.Create(new StringLiteralType("MyEnum"), new StringLiteralType("BlahBlah")))); var typeProvider = ResourceTypeProviderHelper.CreateMockTypeProvider(typeDefinition.AsEnumerable()); var compilation = CompilationHelper.CreateCompilation(typeProvider, ("main.bicep", bicepFile)); var rewriter = new TypeCasingFixerRewriter(compilation.GetEntrypointSemanticModel()); var newProgramSyntax = rewriter.Rewrite(compilation.SyntaxTreeGrouping.EntryPoint.ProgramSyntax); PrintHelper.PrettyPrint(newProgramSyntax).Should().Be( @"resource resA 'My.Rp/resA@2020-01-01' = { name: 'resA' properties: { lowercaseprop: 'abc' camelCaseProp: 'def' 'lowercasequoted=+.prop': 'ghi' 'camelCaseQuoted=+.Prop': 'jkl' lowerCaseEnumProp: 'myenum' pascalCaseEnumProp: 'MyEnum' lowerCaseEnumUnionProp: 'myenum' pascalCaseEnumUnionProp: 'MyEnum' } } output myObj object = { lowerCaseProp: resA.properties.lowercaseprop camelcaseprop: resA.properties.camelCaseProp }"); }
public override object Exec(UnionType from, object arg) { return(this.InternalPromotion(from, arg)); }
public void VisitUnion(UnionType ut) { throw new NotImplementedException(); }
public string VisitUnion(UnionType ut) { return("u"); }
public override DataType VisitUnion(UnionType ut) { if (insideComplexType) { changed = true; NestedComplexTypeExtractor nctr = new NestedComplexTypeExtractor(factory, store); ut.Accept(nctr); return CreateEquivalenceClass(ut); } else { insideComplexType = true; return base.VisitUnion(ut); } }
public void TestNotNullDecide() { UnionType <int, string> _testInstance = 1; Assert.IsTrue(_testInstance != null); }
protected virtual void GenerateRightOperand(TypeExpression teLeft, UnionType teRight) { List <TypeExpression> typeSet = new List <TypeExpression>(); for (int i = 0; i < teRight.TypeSet.Count; i++) { typeSet.AddRange(GetTypes(teRight.TypeSet[i])); } typeSet = new List <TypeExpression>(new HashSet <TypeExpression>(typeSet)); String finalLabel = this.codeGenerator.NewLabel; String nextLabel = ""; if (typeSet.Count == 0) { typeSet.AddRange(GenerateAllUnionTypes().TypeSet); } for (int i = 0; i < typeSet.Count; i++) { if (!String.IsNullOrEmpty(nextLabel)) { this.codeGenerator.WriteLabel(indent, nextLabel); } if (i != typeSet.Count - 1) { LoadSecondOperand(); nextLabel = this.codeGenerator.NewLabel; this.codeGenerator.isinst(indent, typeSet[i]); this.codeGenerator.brfalse(indent, nextLabel); } if ((node.FirstOperand.ExpressionType is UnionType || node.FirstOperand.ExpressionType is TypeVariable) && IsValueType(typeSet[i]) && IsInternallyAnObject(node.FirstOperand)) { this.codeGenerator.UnboxAny(indent, teLeft); } else if (this.node.FirstOperand.ExpressionType is FieldType && ((FieldType)this.node.FirstOperand.ExpressionType).MemberInfo.Modifiers.Contains(Modifier.Static) && ((FieldType)this.node.FirstOperand.ExpressionType).FieldTypeExpression is TypeVariable) { this.codeGenerator.UnboxAny(indent, teLeft); } else if (this.node.FirstOperand.ExpressionType is FieldType && ((FieldType)this.node.FirstOperand.ExpressionType).FieldTypeExpression is TypeVariable && node.SecondOperand.ExpressionType.IsValueType()) { this.codeGenerator.UnboxAny(indent, teLeft); } else if (this.node.FirstOperand.ExpressionType is FieldType && ((FieldType)this.node.FirstOperand.ExpressionType).FieldTypeExpression is TypeVariable && ((TypeVariable)((FieldType)this.node.FirstOperand.ExpressionType).FieldTypeExpression).Substitution == null) { this.codeGenerator.UnboxAny(indent, teLeft); } else if (IsValueType(node.FirstOperand.ExpressionType) && typeSet[i] is StringType) { this.codeGenerator.Box(indent, teLeft); } LoadSecondOperand(); if (!(typeSet[i] is StringType) && !(teLeft is StringType)) { this.codeGenerator.UnboxAny(this.indent, typeSet[i]); } GenerateOperator(node, MajorType(teLeft, typeSet[i])); if (i != typeSet.Count - 1) { this.codeGenerator.br(indent, finalLabel); } } this.codeGenerator.WriteLabel(indent, finalLabel); if (!String.IsNullOrEmpty(label_result)) { this.codeGenerator.ldloc(this.indent, label_result); } }
public void TyfoUnion() { UnionType u = new UnionType( "foo", null); u.Alternatives.Add(PrimitiveType.Real32); u.Alternatives.Add(PrimitiveType.Int32); tyfo.Write(u, "bar"); Assert.AreEqual( @"union foo { int32 u0; real32 u1; } bar", sw.ToString()); }
public Atom(bool value) { _type = UnionType.Bool; _boolValue = value; }
public UnionType UnifyUnions(UnionType u1, UnionType u2) { UnionType u = new UnionType(null, null); foreach (UnionAlternative a in u1.Alternatives.Values) { UnifyIntoUnion(u, a.DataType); } foreach (UnionAlternative a in u2.Alternatives.Values) { UnifyIntoUnion(u, a.DataType); } return u; }
public void TtranSimplify2() { UnionType u = new UnionType(null, null); u.Alternatives.Add(PrimitiveType.Word32); u.Alternatives.Add(new Pointer(PrimitiveType.Real32, 4)); TypeTransformer trans = new TypeTransformer(factory, store, null); DataType dt = u.Accept(trans); Assert.AreEqual("(ptr real32)", dt.ToString()); }
public void UnifyWordMemptr() { TypeVariable tv = new TypeVariable(1); TypeVariable tv2 = new TypeVariable(2); TypeVariable tv3 = new TypeVariable(3); MemberPointer mp2 = new MemberPointer(tv, tv2, 0); MemberPointer mp3 = new MemberPointer(tv, tv3, 0); UnionType ut = new UnionType(null, null); un.UnifyIntoUnion(ut, mp2); un.UnifyIntoUnion(ut, mp3); un.UnifyIntoUnion(ut, PrimitiveType.Word16); Assert.AreEqual("(union ((memptr T_1 T_2) u0) ((memptr T_1 T_3) u1))", ut.ToString()); }
private void GenerateRightOperand(TypeExpression teLeft, TypeExpression teRight) { if (teRight is UnionType) { this.GenerateRightOperand(teLeft, teRight as UnionType); } else if (teRight is TypeVariable) { this.GenerateRightOperand(teLeft, teRight as TypeVariable); } else if (teRight is PropertyType) { GenerateRightOperand(teLeft, ((PropertyType)teRight).PropertyTypeExpression); } else if (teRight is FieldType) { FieldType fieldType = ((FieldType)teRight); if (fieldType.FieldTypeExpression is TypeVariable && ((TypeVariable)fieldType.FieldTypeExpression).Substitution != null && ((TypeVariable)fieldType.FieldTypeExpression).Substitution.IsValueType()) { UnionType union = new UnionType(); union.AddType(((TypeVariable)((FieldType)teRight).FieldTypeExpression).Substitution); GenerateRightOperand(teLeft, union); } else { GenerateRightOperand(teLeft, ((FieldType)teRight).FieldTypeExpression); } } else if (IsValueType(teRight) || TypeExpression.Is <StringType>(teRight)) { if (IsInternallyAnObject(node.FirstOperand)) { if (!(teLeft is StringType) && IsValueType(teRight)) { this.codeGenerator.UnboxAny(indent, teLeft); } } else { if (!CheckUnBox(teLeft, teRight)) { CheckBox(teLeft, teRight); } } LoadSecondOperand(); if (IsInternallyAnObject(node.SecondOperand)) { if (!(teRight is StringType) && IsValueType(teLeft)) { this.codeGenerator.UnboxAny(indent, teRight); } } else { if (!CheckUnBox(teRight, teLeft)) { CheckBox(teRight, teLeft); } } GenerateOperator(node, MajorType(teLeft, teRight)); } else if (teRight is NullType) { this.codeGenerator.ldnull(this.indent); GenerateOperator(node, MajorType(teLeft, teRight)); } }
public void TestSetDiffTypeValue() { UnionType <int, string> _testInstance = "s"; Assert.AreNotEqual(_testInstance.Value, 2); }
/// <summary> /// /// </summary> /// <param name="ut"></param> /// <returns>true or false depending whether the typeset of the UnionType returns void</returns> public override object Exec(UnionType ut, object arg) { return(!(ut.TypeSet[0] is VoidType)); }
public Atom(double value) { _type = UnionType.Double; _doubleValue = value; }
public IEnumerable <WorkItem> VisitUnion(UnionType ut) { throw new NotImplementedException(); }
public CodeFormatter VisitUnion(UnionType ut) { throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="statement"></param> /// <param name="customization"></param> /// <param name="type"></param> /// <returns></returns> public static SelectStatement Union <T>(SelectStatement statement, Action <Target, Context> customization, UnionType type = UnionType.Union) where T : class, new() { if (statement == null) { throw new ArgumentNullException(nameof(statement)); } var table = new Table <T>(); var unionStatement = new SelectStatement(table); foreach (var tbl in statement.Context) { if (tbl.Name != table.Name) { unionStatement.Context.Add(tbl); } } statement.Clauses.Add(unionStatement); unionStatement.HasUnion = type; unionStatement.Target.Customize(customization); return(unionStatement); }
public override DataType VisitUnion(UnionType ut) { // Do not transform user-defined types if (ut.UserDefined) return ut; if (insideComplexType) { changed = true; NestedComplexTypeExtractor nctr = new NestedComplexTypeExtractor(factory, store); ut.Accept(nctr); return CreateEquivalenceClass(ut); } else { insideComplexType = true; return base.VisitUnion(ut); } }
public bool VisitUnion(UnionType ut) { return(ut.Alternatives.Values.Any(a => Find(a.DataType))); }