bool HandleDecl(TemplateTypeParameter p, MemberFunctionAttributeDecl m, AbstractType r) { if (r == null || r.Modifier == 0) { return(false); } // Modifiers must be equal on both sides if (m.Modifier != r.Modifier) { return(false); } // Strip modifier, but: immutable(int[]) becomes immutable(int)[] ?! AbstractType newR; if (r is AssocArrayType) { var aa = r as AssocArrayType; var clonedValueType = aa.Modifier != r.Modifier ? aa.ValueType.Clone(false) : aa.ValueType; clonedValueType.Modifier = r.Modifier; var at = aa as ArrayType; if (at != null) { newR = at.IsStaticArray ? new ArrayType(clonedValueType, at.FixedLength, r.DeclarationOrExpressionBase) : new ArrayType(clonedValueType, r.DeclarationOrExpressionBase); } else { newR = new AssocArrayType(clonedValueType, aa.KeyType, r.DeclarationOrExpressionBase); } } else { newR = r.Clone(false); newR.Modifier = 0; } // Now compare the type inside the parentheses with the given type 'r' return(m.InnerType != null && HandleDecl(p, m.InnerType, newR)); }
bool HandleDecl(TemplateTypeParameter p, MemberFunctionAttributeDecl m, AbstractType r) { if (r == null || r.Modifier == 0) return false; // Modifiers must be equal on both sides if (m.Modifier != r.Modifier) return false; // Strip modifier, but: immutable(int[]) becomes immutable(int)[] ?! AbstractType newR; if (r is AssocArrayType) { var aa = r as AssocArrayType; var clonedValueType = aa.Modifier != r.Modifier ? aa.ValueType.Clone(false) : aa.ValueType; clonedValueType.Modifier = r.Modifier; var at = aa as ArrayType; if (at != null) newR = at.IsStaticArray ? new ArrayType(clonedValueType, at.FixedLength, r.DeclarationOrExpressionBase) : new ArrayType(clonedValueType, r.DeclarationOrExpressionBase); else newR = new AssocArrayType(clonedValueType, aa.KeyType, r.DeclarationOrExpressionBase); } else { newR = r.Clone(false); newR.Modifier = 0; } // Now compare the type inside the parentheses with the given type 'r' return m.InnerType != null && HandleDecl(p, m.InnerType, newR); }
bool HandleDecl(TemplateTypeParameter parameterRef,ArrayDecl arrayDeclToCheckAgainst, AssocArrayType argumentArrayType) { if (argumentArrayType == null) return false; // Handle key type if((arrayDeclToCheckAgainst.KeyType != null || arrayDeclToCheckAgainst.KeyExpression!=null) && argumentArrayType.KeyType == null) return false; bool result = false; if (arrayDeclToCheckAgainst.KeyExpression != null) { // Remove all surrounding parentheses from the expression var x_param = arrayDeclToCheckAgainst.KeyExpression; while(x_param is SurroundingParenthesesExpression) x_param = ((SurroundingParenthesesExpression)x_param).Expression; var ad_Argument = argumentArrayType.DeclarationOrExpressionBase as ArrayDecl; /* * This might be critical: * the [n] part in class myClass(T:char[n], int n) {} * will be seen as an identifier expression, not as an identifier declaration. * So in the case the parameter expression is an identifier, * test if it's part of the parameter list */ var id = x_param as IdentifierExpression; if(id!=null && id.IsIdentifier && Contains(id.ValueStringHash)) { // If an expression (the usual case) has been passed as argument, evaluate its value, otherwise is its type already resolved. ISemantic finalArg = null; if (ad_Argument != null && ad_Argument.KeyExpression != null) { ISymbolValue val = null; int len = -1; finalArg = TypeDeclarationResolver.ResolveKey(ad_Argument, out len, out val, ctxt); if (val != null) finalArg = val; } else finalArg = argumentArrayType.KeyType; //TODO: Do a type convertability check between the param type and the given argument's type. // The affected parameter must also be a value parameter then, if an expression was given. // and handle it as if it was an identifier declaration.. result = Set(parameterRef, finalArg, id.ValueStringHash); } else if (ad_Argument != null && ad_Argument.KeyExpression != null) { // Just test for equality of the argument and parameter expression, e.g. if both param and arg are 123, the result will be true. result = SymbolValueComparer.IsEqual(arrayDeclToCheckAgainst.KeyExpression, ad_Argument.KeyExpression, new StandardValueProvider(ctxt)); } } else if (arrayDeclToCheckAgainst.KeyType != null) { // If the array we're passing to the decl check that is static (i.e. has a constant number as key 'type'), // pass that number instead of type 'int' to the check. var at = argumentArrayType as ArrayType; if (argumentArrayType != null && at != null && at.IsStaticArray) result = HandleDecl(parameterRef, arrayDeclToCheckAgainst.KeyType, new PrimitiveValue(D_Parser.Parser.DTokens.Int, (decimal)at.FixedLength, null)); else result = HandleDecl(parameterRef, arrayDeclToCheckAgainst.KeyType, argumentArrayType.KeyType); } // Handle inner type return result && HandleDecl(parameterRef,arrayDeclToCheckAgainst.InnerDeclaration, argumentArrayType.Base); }
public AssociativeArrayValue(AssocArrayType baseType, IList <KeyValuePair <ISymbolValue, ISymbolValue> > Elements) : base(baseType) { this.Elements = new ReadOnlyCollection <KeyValuePair <ISymbolValue, ISymbolValue> >(Elements); }
public AssocArrayPointer(DVariable accessedArray, AssocArrayType arrayType, ISymbolValue accessedItemKey) : base(new MemberSymbol(accessedArray, arrayType, null)) { Key = accessedItemKey; }
public AssocArrayPointer(DVariable accessedArray, AssocArrayType arrayType, ISymbolValue accessedItemKey) : base(new MemberSymbol(accessedArray, arrayType,null)) { Key = accessedItemKey; }
bool HandleDecl(TemplateTypeParameter parameterRef, ArrayDecl arrayDeclToCheckAgainst, AssocArrayType argumentArrayType) { if (argumentArrayType == null) { return(false); } // Handle key type var at = argumentArrayType as ArrayType; if ((arrayDeclToCheckAgainst.ClampsEmpty == (at == null)) && (at == null || !at.IsStaticArray || arrayDeclToCheckAgainst.KeyExpression == null)) { return(false); } bool result; if (arrayDeclToCheckAgainst.KeyExpression != null) { // Remove all surrounding parentheses from the expression var x_param = arrayDeclToCheckAgainst.KeyExpression; while (x_param is SurroundingParenthesesExpression) { x_param = ((SurroundingParenthesesExpression)x_param).Expression; } var ad_Argument = argumentArrayType.DeclarationOrExpressionBase as ArrayDecl; /* * This might be critical: * the [n] part in class myClass(T:char[n], int n) {} * will be seen as an identifier expression, not as an identifier declaration. * So in the case the parameter expression is an identifier, * test if it's part of the parameter list */ var id = x_param as IdentifierExpression; if (id != null && id.IsIdentifier && Contains(id.ValueStringHash)) { // If an expression (the usual case) has been passed as argument, evaluate its value, otherwise is its type already resolved. ISemantic finalArg = null; if (ad_Argument != null && ad_Argument.KeyExpression != null) { ISymbolValue val = null; int len = -1; finalArg = TypeDeclarationResolver.ResolveKey(ad_Argument, out len, out val, ctxt); if (val != null) { finalArg = val; } } else { finalArg = argumentArrayType.KeyType; } //TODO: Do a type convertability check between the param type and the given argument's type. // The affected parameter must also be a value parameter then, if an expression was given. // and handle it as if it was an identifier declaration.. result = Set(parameterRef, finalArg, id.ValueStringHash); } else if (ad_Argument != null && ad_Argument.KeyExpression != null) { // Just test for equality of the argument and parameter expression, e.g. if both param and arg are 123, the result will be true. result = SymbolValueComparer.IsEqual(arrayDeclToCheckAgainst.KeyExpression, ad_Argument.KeyExpression, new StandardValueProvider(ctxt)); } else { result = false; } if (!result) { return(false); } } else if (arrayDeclToCheckAgainst.KeyType != null) { // If the array we're passing to the decl check that is static (i.e. has a constant number as key 'type'), // pass that number instead of type 'int' to the check. if (argumentArrayType != null && at != null && at.IsStaticArray) { result = HandleDecl(parameterRef, arrayDeclToCheckAgainst.KeyType, new PrimitiveValue(D_Parser.Parser.DTokens.Int, (decimal)at.FixedLength, null)); } else { result = HandleDecl(parameterRef, arrayDeclToCheckAgainst.KeyType, argumentArrayType.KeyType); } if (!result) { return(false); } } // Handle inner type return(HandleDecl(parameterRef, arrayDeclToCheckAgainst.InnerDeclaration, argumentArrayType.Base)); }
bool HandleDecl(TemplateTypeParameter parameterRef,ArrayDecl arrayDeclToCheckAgainst, AssocArrayType argumentArrayType) { if (argumentArrayType == null) return false; // Handle key type var at = argumentArrayType as ArrayType; if((arrayDeclToCheckAgainst.ClampsEmpty == (at == null)) && (at == null || !at.IsStaticArray || arrayDeclToCheckAgainst.KeyExpression == null)) return false; bool result = true; if (arrayDeclToCheckAgainst.KeyExpression != null) { var x_param = arrayDeclToCheckAgainst.KeyExpression; while(x_param is SurroundingParenthesesExpression) x_param = ((SurroundingParenthesesExpression)x_param).Expression; /* * This might be critical: * the [n] part in class myClass(T:char[n], int n) {} * will be seen as an identifier expression, not as an identifier declaration. * So in the case the parameter expression is an identifier, * test if it's part of the parameter list */ var id = x_param as IdentifierExpression; if (id != null && id.IsIdentifier && Contains (id.ValueStringHash)) { // Match int[5] into T[n],n - after deduction, n will be 5 // If an expression (the usual case) has been passed as argument, evaluate its value, otherwise is its type already resolved. var finalArg = argumentArrayType is ArrayType ? (ISemantic)new PrimitiveValue ((argumentArrayType as ArrayType).FixedLength) : argumentArrayType.KeyType; //TODO: Do a type convertability check between the param type and the given argument's type. // The affected parameter must also be a value parameter then, if an expression was given. // and handle it as if it was an identifier declaration.. result = Set (parameterRef, finalArg, id.ValueStringHash); } else if (argumentArrayType is ArrayType) { // Match int[5] into T[5] // Just test for equality of the argument and parameter expression, e.g. if both param and arg are 123, the result will be true. result = SymbolValueComparer.IsEqual (Evaluation.EvaluateValue (arrayDeclToCheckAgainst.KeyExpression, ctxt), new PrimitiveValue ((argumentArrayType as ArrayType).FixedLength)); } else result = false; } else if (arrayDeclToCheckAgainst.KeyType != null) { // If the array we're passing to the decl check that is static (i.e. has a constant number as key 'type'), // pass that number instead of type 'int' to the check. if (argumentArrayType != null && at != null && at.IsStaticArray) result = HandleDecl(parameterRef, arrayDeclToCheckAgainst.KeyType, new PrimitiveValue(at.FixedLength)); else result = HandleDecl(parameterRef, arrayDeclToCheckAgainst.KeyType, argumentArrayType.KeyType); } // Handle inner type return result && HandleDecl(parameterRef,arrayDeclToCheckAgainst.InnerDeclaration, argumentArrayType.Base); }
public AssocArrayPointer(DVariable accessedArray, AssocArrayType arrayType, ISymbolValue accessedItemKey, IExpression baseExpression) : base(accessedArray, arrayType, baseExpression) { Key = accessedItemKey; }
public AssociativeArrayValue(AssocArrayType baseType, IExpression baseExpression, IList <KeyValuePair <ISymbolValue, ISymbolValue> > Elements) : base(ExpressionValueType.AssocArray, baseType, baseExpression) { this.Elements = new ReadOnlyCollection <KeyValuePair <ISymbolValue, ISymbolValue> >(Elements); }
public void VisitAssocArrayType(AssocArrayType aa) { isVariableInstance = true; GenUfcsAndStaticProperties(aa); }
public ulong VisitAssocArrayType(AssocArrayType t) { return(1001687); }
public void VisitAssocArrayType(AssocArrayType aa) { GenUfcsAndStaticProperties(aa); }
public ISymbolValue VisitAssocArrayType(AssocArrayType t) { throw new NotImplementedException(); }
public AssocArrayPointer(DVariable accessedArray, AssocArrayType arrayType, ISymbolValue accessedItemKey, IExpression baseExpression) : base(accessedArray, arrayType, baseExpression) { Key = accessedItemKey; }
public ISymbolValue VisitAssocArrayType(AssocArrayType aa) { return(new TypeValue(aa)); }