public static ISubtypeIndication GetBaseType(ISubtypeIndication type) { var getter = new TypeHelper(); type.accept(getter); return(getter.baseType); }
/// <summary> /// Writes a subtype indication. /// </summary> /// <param name="indication">the subtype indication</param> public virtual void writeSubtypeIndication(ISubtypeIndication indication) { if (indication is IndexSubtypeIndication) { getMiscellaneousElementOutput().indexSubtypeIndication((IndexSubtypeIndication)indication); } else if (indication is ResolvedSubtypeIndication) { getMiscellaneousElementOutput().resolvedSubtypeIndication((ResolvedSubtypeIndication)indication); } else if (indication is RangeSubtypeIndication) { getMiscellaneousElementOutput().rangeSubtypeIndication((RangeSubtypeIndication)indication); } else if (indication is Type) { getMiscellaneousElementOutput().typeSubtypeIndication((Type)indication); } else if (indication is Subtype) { getMiscellaneousElementOutput().subtypeSubtypeIndication((Subtype)indication); } else if (indication is UnresolvedType) { getMiscellaneousElementOutput().unresolvedTypeSubtypeIndication((UnresolvedType)indication); } else if (indication == null) { //ignore } else { throw new ArgumentException("Unknown subtype indication."); } }
/// <summary> /// Creates a new element declaration and adds it to this record. /// </summary> /// <param name="type">the type</param> /// <param name="identifiers">list of identifiers</param> /// <returns>the created element</returns> public virtual ElementDeclaration createElement(ISubtypeIndication type, List <string> identifiers) { ElementDeclaration element = new ElementDeclaration(type, identifiers); elements.Add(element); return(element); }
public static bool AreTypesEqual(ISubtypeIndication left, ISubtypeIndication right) { string leftTypeName = TypeHelper.GetTypeName(TypeHelper.GetBaseType(left)); string rightTypeName = TypeHelper.GetTypeName(TypeHelper.GetBaseType(right)); return(leftTypeName != "" && leftTypeName.EqualsIgnoreCase(rightTypeName)); }
public override void Observe(VHDLCompilerInterface compiler) { compiler.TypeDictionary.AddItem(type, type.Identifier); if (BuiltInTypesDictionary.ContainsBuiltInSubType(type)) { return; } ISubtypeIndication si = type.SubtypeIndication; string typeName = type.Identifier; if (si is RangeSubtypeIndication) { RangeSubtypeIndication rangeSI = si as RangeSubtypeIndication; ISubtypeIndication baseSI = rangeSI.BaseType; if (baseSI is VHDL.type.IntegerType) { ObserveIntegerSubType(compiler, rangeSI, typeName); } if (baseSI is VHDL.type.RealType) { ObserveRealSubType(compiler, rangeSI, typeName); } } }
public static ModellingType CreateType(ISubtypeIndication si) { if (si is ResolvedSubtypeIndication) { ModellingType res = CreateType((si as ResolvedSubtypeIndication).BaseType); res.Constraints.Add(new ResolvedTypeConstraint(si as ResolvedSubtypeIndication)); return(res); } if (si is RangeSubtypeIndication) { ModellingType res = CreateType((si as RangeSubtypeIndication).BaseType); res.Constraints.Add(new RangeTypeConstraint(si as RangeSubtypeIndication)); return(res); } if (si is IndexSubtypeIndication) { ModellingType res = CreateType((si as IndexSubtypeIndication).BaseType); res.Constraints.Add(new IndexTypeConstraint(si as IndexSubtypeIndication)); return(res); } if (si is Subtype) { return(CreateType((si as Subtype).SubtypeIndication)); } if (si is IntegerType) { return(ModellingType.CreateModellingType(si as IntegerType)); } if (si is RealType) { return(ModellingType.CreateModellingType(si as RealType)); } if (si is PhysicalType) { return(ModellingType.CreateModellingType(si as PhysicalType)); } if (si is RecordType) { return(ModellingType.CreateModellingType(si as RecordType)); } if (si is EnumerationType) { return(ModellingType.CreateModellingType(si as EnumerationType)); } if (si is UnconstrainedArray) { return(ModellingType.CreateModellingType(si as UnconstrainedArray)); } if (si is ConstrainedArray) { return(ModellingType.CreateModellingType(si as ConstrainedArray)); } return(null); }
public void visit(RangeSubtypeIndication item) { if (item == null) { return; } baseType = item.BaseType; }
public void visit(ISubtypeIndication item) { if (item == null) { return; } visit(item.BaseType); }
public static ISubtypeIndication Infer(IDeclarativeRegion scope, Expression expr, ISubtypeIndication expectedType = null) { ISubtypeIndication baseType = TypeHelper.GetBaseType(expectedType); TypeInference baseInfer = new TypeInference(baseType); ExpressionInference infer = new ExpressionInference(scope, baseInfer); expr.accept(infer); return(baseInfer.ResultType); }
public bool AnalyzeType(ISubtypeIndication type, bool strict = true) { bool success = strict ? AreTypesEqual(type, ExpectedType) : AreTypesCompatible(type, ExpectedType); if (success) { ResultType = type; } return(success); }
public string this[ISubtypeIndication key] { get { if (intenalDictionary.Keys.Contains(key) == false) { return(null); } return(intenalDictionary[key]); } }
public static string GetTypeName(ISubtypeIndication indication) { var unresolved_type = indication as UnresolvedType; if (unresolved_type != null) { return(unresolved_type.Identifier); } var type = indication as Type; if (type != null) { return(type.Identifier); } ISubtypeIndication base_type = indication.BaseType; if (base_type != null) { return(GetTypeName(base_type)); } return(""); }
private static bool CheckCharacter(char ch, ISubtypeIndication type) { var enumType = type as EnumerationType; if (enumType != null) { // Special case: not all literals present in this type if (enumType.Identifier.EqualsIgnoreCase("character")) { return(true); } foreach (var enumLiteral in enumType.Literals) { string enumStr = enumLiteral.ToString(); if (enumStr.IndexOf(ch) == 1) // e.g. '1' { return(true); } } } return(false); }
public static bool AreTypesCompatible(ISubtypeIndication left, ISubtypeIndication right) { // TODO: some types can be converted to other return(AreTypesEqual(TypeHelper.GetBaseType(left), TypeHelper.GetBaseType(right))); }
/// <summary> /// Creates a file type. /// </summary> /// <param name="identifier">the identifier of this file type</param> /// <param name="valueType">the type of the values in this file type</param> public FileType(string identifier, ISubtypeIndication valueType) : base(identifier) { this.valueType = valueType; }
public ElementDeclaration(ISubtypeIndication type, List <string> identifiers) { this.type = type; this.identifiers = new List <string>(identifiers); }
/// <summary> /// Creates a new element declaration and adds it to this record. /// </summary> /// <param name="type">the type</param> /// <param name="identifiers">a variable number of identifiers</param> /// <returns>the created element</returns> public virtual ElementDeclaration createElement(ISubtypeIndication type, params string[] identifiers) { return(createElement(type, new List <string>(identifiers))); }
/// <summary> /// Создание контейнера по заданному типу /// </summary> /// <param name="si"></param> /// <returns></returns> public static AbstractValue CreateValue(ISubtypeIndication si) { if (si == VHDL.builtin.Standard.TIME) { return(new TIME_VALUE(0)); } if (si is ResolvedSubtypeIndication) { AbstractValue res = CreateValue((si as ResolvedSubtypeIndication).BaseType); res.Type.Constraints.Add(new ResolvedTypeConstraint(si as ResolvedSubtypeIndication)); return(res); } if (si is RangeSubtypeIndication) { AbstractValue res = CreateValue((si as RangeSubtypeIndication).BaseType); res.Type.Constraints.Add(new RangeTypeConstraint(si as RangeSubtypeIndication)); return(res); } if (si is IndexSubtypeIndication) { ArrayValue res = CreateValue((si as IndexSubtypeIndication).BaseType) as ArrayValue; res.Type.Constraints.Add(new IndexTypeConstraint(si as IndexSubtypeIndication)); return(res); } if (si is Subtype) { return(CreateValue((si as Subtype).SubtypeIndication)); } if (si is IntegerType) { return(new IntegerValue(si as IntegerType)); } if (si is RealType) { return(new RealValue(si as RealType)); } if (si is EnumerationType) { EnumerationType en = si as EnumerationType; switch (en.Identifier.ToLower()) { case "std_logic": return(new STD_LOGIC_VALUE()); case "std_ulogic": return(new STD_LOGIC_VALUE()); case "bit": return(new BIT_VALUE()); case "character": return(new CHARACTER_VALUE()); default: return(new EnumerationValue(si as EnumerationType)); } } if (si is PhysicalType) { return(new PhysicalValue(si as PhysicalType)); } if (si is UnconstrainedArray) { throw new Exception("Undefined bounds of array"); } if (si is ConstrainedArray) { //ArrayValue val = new ArrayValue(si as ConstrainedArray, ); //return val; } if (si is RecordType) { return(new RecordValue(si as RecordType)); } return(null); }
public static Signal CreateSignal(string name, ISubtypeIndication si) { if (si is ResolvedSubtypeIndication) { Signal res = CreateSignal(name, (si as ResolvedSubtypeIndication).BaseType); return(res); } if (si is RangeSubtypeIndication) { Signal res = CreateSignal(name, (si as RangeSubtypeIndication).BaseType); return(res); } if (si is IndexSubtypeIndication) { Signal res = CreateUnconstrainedArraySignal(name, si as IndexSubtypeIndication); return(res); } if (si is Subtype) { return(CreateSignal(name, (si as Subtype).SubtypeIndication)); } if (si is IntegerType) { ModellingType resType = ModellingType.CreateModellingType(si as IntegerType); IntegerAbstractValueConvertor conv = new IntegerAbstractValueConvertor(resType); AbstractSimpleSignalDump <int> resDump = new AbstractSimpleSignalDump <int>(name, resType, conv); Signal resSignal = new Signal(resDump); return(resSignal); } if (si is RealType) { ModellingType resType = ModellingType.CreateModellingType(si as RealType); RealAbstractValueConvertor conv = new RealAbstractValueConvertor(resType); AbstractSimpleSignalDump <double> resDump = new AbstractSimpleSignalDump <double>(name, resType, conv); Signal resSignal = new Signal(resDump); return(resSignal); } if (si is PhysicalType) { ModellingType resType = ModellingType.CreateModellingType(si as PhysicalType); PhysicalAbstractValueConvertor conv = new PhysicalAbstractValueConvertor(resType); AbstractSimpleSignalDump <PhysicalLiteral> resDump = new AbstractSimpleSignalDump <PhysicalLiteral>(name, resType, conv); Signal resSignal = new Signal(resDump); return(resSignal); } if (si is RecordType) { RecordType recType = si as RecordType; ModellingType resType = ModellingType.CreateModellingType(recType); List <AbstractSignalDump> dumps = new List <AbstractSignalDump>(); List <Signal> childrens = new List <Signal>(); foreach (var el in recType.Elements) { foreach (string s in el.Identifiers) { Signal newSignal = CreateSignal(s, el.Type); childrens.Add(newSignal); dumps.Add(newSignal.Dump); } } SignalScopeDump resDump = new SignalScopeDump(name, resType, dumps); Signal resSignal = new Signal(resDump); return(resSignal); } if (si is EnumerationType) { ModellingType resType = ModellingType.CreateModellingType(si as EnumerationType); EnumerationAbstractValueConvertor conv; if (si == StdLogic1164.STD_ULOGIC) { conv = new STD_ULOGIC_AbstractValueConvertor(resType); } else { if (si == StdLogic1164.STD_LOGIC) { conv = new STD_LOGIC_AbstractValueConvertor(resType); } else { conv = new EnumerationAbstractValueConvertor(resType); } } AbstractSimpleSignalDump <EnumerationLiteral> resDump = new AbstractSimpleSignalDump <EnumerationLiteral>(name, resType, conv); Signal resSignal = new Signal(resDump); return(resSignal); } if (si is ConstrainedArray) { ConstrainedArray arrayType = si as ConstrainedArray; ModellingType resType = ModellingType.CreateModellingType(arrayType); List <AbstractSignalDump> dumps = new List <AbstractSignalDump>(); List <Signal> childrens = new List <Signal>(); ResolvedDiscreteRange[] ranges = resType.Dimension; int[,] resIndexes = ResolvedDiscreteRange.CombineRanges(ranges); for (int i = 0; i < resIndexes.GetLength(0); i++) { for (int j = 0; j < resIndexes.GetLength(1); j++) { Signal newSignal = CreateSignal(ranges[j][resIndexes[i, j]].ToString(), arrayType.ElementType); childrens.Add(newSignal); dumps.Add(newSignal.Dump); } } SignalScopeDump resDump = new SignalScopeDump(name, resType, dumps); Signal resSignal = new Signal(resDump); return(resSignal); } return(null); }
/// <summary> /// Creates a constrained array. /// </summary> /// <param name="identifier">the identifier</param> /// <param name="elementType">the type of the array elements</param> /// <param name="indexRanges">the index ranges</param> public ConstrainedArray(string identifier, ISubtypeIndication elementType, params DiscreteRange[] indexRanges) : this(identifier, elementType, new List <DiscreteRange>(indexRanges)) { }
/// <summary> /// Creates a index subtype indication. /// </summary> /// <param name="baseType">the base type</param> /// <param name="ranges">the ranges</param> public IndexSubtypeIndication(ISubtypeIndication baseType, params DiscreteRange[] ranges) : this(baseType, new List <DiscreteRange>(ranges)) { }
private TypeInference(ISubtypeIndication type) { this.ExpectedType = type; }
/// <summary> /// Creates an unconstrained array. /// </summary> /// <param name="identifier">the identifier</param> /// <param name="elementType">the element type</param> /// <param name="indexSubtypes">the index subtypes</param> public UnconstrainedArray(string identifier, ISubtypeIndication elementType, List <ISubtypeIndication> indexSubtypes) : base(identifier, elementType) { this.indexSubtypes = new List <ISubtypeIndication>(indexSubtypes); }
/// <summary> /// Creates an unconstrained array. /// </summary> /// <param name="identifier">the identifier</param> /// <param name="elementType">the element type</param> /// <param name="indexSubtypes">the index subtypes</param> public UnconstrainedArray(string identifier, ISubtypeIndication elementType, params ISubtypeIndication[] indexSubtypes) : this(identifier, elementType, new List <ISubtypeIndication>(indexSubtypes)) { }
/// <summary> /// Creates a constrained array. /// </summary> /// <param name="identifier">the identifier</param> /// <param name="elementType">the type of the array elements</param> /// <param name="indexRanges">the index ranges</param> public ConstrainedArray(string identifier, ISubtypeIndication elementType, List <DiscreteRange> indexRanges) : base(identifier, elementType) { this.indexRanges = new List <DiscreteRange>(indexRanges); }
/// <summary> /// Creates a index subtype indication. /// </summary> /// <param name="baseType">the base type</param> /// <param name="ranges">the ranges</param> public IndexSubtypeIndication(ISubtypeIndication baseType, List <DiscreteRange> ranges) { this.baseType = baseType; this.ranges = new List <DiscreteRange>(ranges); }
/// <summary> /// Creates array type. /// </summary> /// <param name="identifier">identifier the identifier</param> /// <param name="elementType">the type of the array elements</param> public ArrayType(string identifier, ISubtypeIndication elementType) : base(identifier) { this.elementType = elementType; }
public virtual void visit(Type item) { baseType = item; }
public static IFunction ResolveOverloadFunction(IDeclarativeRegion scope, List <IFunction> overloads, List <AssociationElement> arguments, ISubtypeIndication returnType) { string id = ""; var candidates = new List <IFunction>(overloads); switch (candidates.Count) { case 0: throw new Exception("Object is not declared"); case 1: return(candidates[0]); default: id = candidates[0].Identifier; for (int i = 0; i < candidates.Count;) { var decl = candidates[i]; // check by arguments count if (decl.Parameters.Count != arguments.Count) { candidates.RemoveAt(i); continue; } // check return type if so if (returnType != null) { var funcDecl = decl as IFunction; if (funcDecl == null) { candidates.RemoveAt(i); continue; } else if (!AreTypesCompatible(funcDecl.ReturnType, returnType)) { candidates.RemoveAt(i); continue; } } if (!CheckAssociationList(scope, decl.Parameters, arguments)) { candidates.RemoveAt(i); continue; } ++i; } switch (candidates.Count) { case 0: throw new vhdlNoMatchSubprogramException(id, "function"); case 1: return(candidates[0]); case 2: { // TODO: link body with declaration bool firstIsBody = candidates[0] is SubprogramBody; bool secndIsBody = candidates[1] is SubprogramBody; if (firstIsBody ^ secndIsBody) { return(candidates[0]); } } throw new vhdlAmbiguousCallException(id, "function"); default: throw new vhdlAmbiguousCallException(id, "function"); // TODO: add location to exception } } }
/// <summary> /// Creates a resolved subtype indication. /// </summary> /// <param name="resolutionFunction">the resolution function</param> /// <param name="baseType">the base type</param> public ResolvedSubtypeIndication(string resolutionFunction, ISubtypeIndication baseType) { this.resolutionFunction = resolutionFunction; this.baseType = baseType; }