public static Expression CreateDefaultValueForType(TypeReference type)
 {
     if (type != null && !type.IsArrayType) {
         switch (type.Type) {
             case "System.SByte":
             case "System.Byte":
             case "System.Int16":
             case "System.UInt16":
             case "System.Int32":
             case "System.UInt32":
             case "System.Int64":
             case "System.UInt64":
             case "System.Single":
             case "System.Double":
                 return new PrimitiveExpression(0, "0");
             case "System.Char":
                 return new PrimitiveExpression('\0', "'\\0'");
             case "System.Object":
             case "System.String":
                 return new PrimitiveExpression(null, "null");
             case "System.Boolean":
                 return new PrimitiveExpression(false, "false");
             default:
                 return new DefaultValueExpression(type);
         }
     } else {
         return new PrimitiveExpression(null, "null");
     }
 }
 public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation)
 {
     this.Name = name;
     this.TypeRef = typeRef;
     this.StartPos = startPos;
     this.EndPos = endPos;
     this.IsConst = isConst;
     this.IsLoopVariable = isLoopVariable;
     this.Initializer = initializer;
     this.ParentLambdaExpression = parentLambdaExpression;
     this.IsQueryContinuation = isQueryContinuation;
 }
Example #3
0
 public InnerClassTypeReference(TypeReference outerClass, string innerType, List<TypeReference> innerGenericTypes)
     : base(innerType, innerGenericTypes)
 {
     this.baseType = outerClass;
 }
Example #4
0
 public Using(string name, string xmlPrefix)
 {
     Name = name;
     XmlPrefix = xmlPrefix;
     alias = TypeReference.Null;
 }
 public virtual object VisitTypeReference(TypeReference typeReference, object data)
 {
     Debug.Assert((typeReference != null));
     Debug.Assert((typeReference.GenericTypes != null));
     foreach (TypeReference o in typeReference.GenericTypes) {
         Debug.Assert(o != null);
         o.AcceptVisitor(this, data);
     }
     return null;
 }
 public virtual object TrackedVisitTypeReference(TypeReference typeReference, object data)
 {
     return base.VisitTypeReference(typeReference, data);
 }
 string GetDotNetNameFromTypeReference(TypeReference type)
 {
     string name;
     InnerClassTypeReference ictr = type as InnerClassTypeReference;
     if (ictr != null) {
         name = GetDotNetNameFromTypeReference(ictr.BaseType) + "+" + ictr.Type;
     } else {
         name = type.Type;
     }
     if (type.GenericTypes.Count != 0)
         name = name + "`" + type.GenericTypes.Count.ToString();
     return name;
 }
Example #8
0
 /// <summary>
 /// Removes the last identifier from the type.
 /// e.g. "System.String.Length" becomes "System.String" or
 /// "System.Collections.IEnumerable(of string).Current" becomes "System.Collections.IEnumerable(of string)"
 /// This is used for explicit interface implementation in VB.
 /// </summary>
 public static string StripLastIdentifierFromType(ref TypeReference tr)
 {
     if (tr is InnerClassTypeReference && ((InnerClassTypeReference)tr).Type.IndexOf('.') < 0) {
         string ident = ((InnerClassTypeReference)tr).Type;
         tr = ((InnerClassTypeReference)tr).BaseType;
         return ident;
     } else {
         int pos = tr.Type.LastIndexOf('.');
         if (pos < 0)
             return tr.Type;
         string ident = tr.Type.Substring(pos + 1);
         tr.Type = tr.Type.Substring(0, pos);
         return ident;
     }
 }
Example #9
0
 public VariableDeclaration(string name)
 {
     Name = name;
     initializer = Expression.Null;
     typeReference = TypeReference.Null;
     fixedArrayInitialization = Expression.Null;
 }
Example #10
0
 public CatchClause(Statement statementBlock)
 {
     StatementBlock = statementBlock;
     typeReference = TypeReference.Null;
     variableName = "";
     condition = Expression.Null;
 }
Example #11
0
 public CollectionRangeVariable()
 {
     identifier = "";
     expression = Expression.Null;
     type = TypeReference.Null;
 }
Example #12
0
 public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock)
 {
     TypeReference = typeReference;
     VariableName = variableName;
     StatementBlock = statementBlock;
     condition = Expression.Null;
 }
Example #13
0
 public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition)
 {
     TypeReference = typeReference;
     VariableName = variableName;
     StatementBlock = statementBlock;
     Condition = condition;
 }
Example #14
0
 public CastExpression(TypeReference castTo, Expression expression, CastType castType)
 {
     CastTo = castTo;
     Expression = expression;
     CastType = castType;
 }
Example #15
0
 public CastExpression(TypeReference castTo)
 {
     CastTo = castTo;
     expression = Expression.Null;
 }
Example #16
0
 public VariableDeclaration(string name, Expression initializer, TypeReference typeReference)
 {
     Name = name;
     Initializer = initializer;
     TypeReference = typeReference;
     fixedArrayInitialization = Expression.Null;
 }
Example #17
0
 public static bool AreEqualReferences(TypeReference a, TypeReference b)
 {
     if (a == b) return true;
     if (a == null || b == null) return false;
     if (a is InnerClassTypeReference) a = ((InnerClassTypeReference)a).CombineToNormalTypeReference();
     if (b is InnerClassTypeReference) b = ((InnerClassTypeReference)b).CombineToNormalTypeReference();
     if (a.type != b.type) return false;
     if (a.IsKeyword != b.IsKeyword) return false;
     if (a.IsGlobal != b.IsGlobal) return false;
     if (a.pointerNestingLevel != b.pointerNestingLevel) return false;
     if (a.IsArrayType != b.IsArrayType) return false;
     if (a.IsArrayType) {
         if (a.rankSpecifier.Length != b.rankSpecifier.Length) return false;
         for (int i = 0; i < a.rankSpecifier.Length; i++) {
             if (a.rankSpecifier[i] != b.rankSpecifier[i]) return false;
         }
     }
     if (a.genericTypes.Count != b.genericTypes.Count) return false;
     for (int i = 0; i < a.genericTypes.Count; i++) {
         if (!AreEqualReferences(a.genericTypes[i], b.genericTypes[i]))
             return false;
     }
     return true;
 }
Example #18
0
 /// <summary>
 /// Copies the pointerNestingLevel, RankSpecifier, GenericTypes and IsGlobal flag
 /// from <paramref name="from"/> to <paramref name="to"/>.
 /// </summary>
 /// <remarks>
 /// If <paramref name="to"/> already contains generics, the new generics are appended to the list.
 /// </remarks>
 protected static void CopyFields(TypeReference from, TypeReference to)
 {
     to.pointerNestingLevel = from.pointerNestingLevel;
     if (from.rankSpecifier != null) {
         to.rankSpecifier = (int[])from.rankSpecifier.Clone();
     }
     foreach (TypeReference r in from.genericTypes) {
         to.genericTypes.Add(r.Clone());
     }
     to.IsGlobal = from.IsGlobal;
     to.IsKeyword = from.IsKeyword;
 }
Example #19
0
 public static TypeReference CheckNull(TypeReference typeReference)
 {
     return typeReference ?? NullTypeReference.Instance;
 }
        public void AddVariable(TypeReference typeRef, string name,
		                        Location startPos, Location endPos, bool isConst,
		                        bool isLoopVariable, Expression initializer,
		                        LambdaExpression parentLambdaExpression,
		                        bool isQueryContinuation)
        {
            if (name == null || name.Length == 0) {
                return;
            }
            List<LocalLookupVariable> list;
            if (!variables.ContainsKey(name)) {
                variables[name] = list = new List<LocalLookupVariable>();
            } else {
                list = (List<LocalLookupVariable>)variables[name];
            }
            list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation));
        }
Example #21
0
 public virtual TypeReference Clone()
 {
     TypeReference c = new TypeReference(type);
     CopyFields(this, c);
     return c;
 }
Example #22
0
 public UsingDeclaration(string @namespace, TypeReference alias)
 {
     usings = new List<Using>(1); usings.Add(new Using(@namespace, alias));
 }
 public LocalVariableDeclaration(TypeReference typeReference)
 {
     this.TypeReference = typeReference;
 }
 public LocalVariableDeclaration(TypeReference typeReference, Modifiers modifier)
 {
     this.TypeReference = typeReference;
     this.modifier      = modifier;
 }
 public override sealed object VisitTypeReference(TypeReference typeReference, object data)
 {
     this.BeginVisit(typeReference);
     object result = this.TrackedVisitTypeReference(typeReference, data);
     this.EndVisit(typeReference);
     return result;
 }
 public LocalVariableDeclaration(Modifiers modifier)
 {
     this.typeReference = TypeReference.Null;
     this.modifier      = modifier;
 }
        CodeTypeReference ConvType(TypeReference type)
        {
            if (type == null) {
                throw new ArgumentNullException("type");
            }

            CodeTypeReference t = new CodeTypeReference(GetDotNetNameFromTypeReference(type));
            InnerClassTypeReference ictr = type as InnerClassTypeReference;
            if (ictr != null) {
                type = ictr.CombineToNormalTypeReference();
            }
            foreach (TypeReference gt in type.GenericTypes) {
                t.TypeArguments.Add(ConvType(gt));
            }
            if (type.IsArrayType) {
                for (int i = type.RankSpecifier.Length - 1; i >= 0; --i)
                {
                    t = new CodeTypeReference(t, type.RankSpecifier[i] + 1);
                }
            }

            return t;
        }
 public virtual object VisitTypeReference(TypeReference typeReference, object data)
 {
     throw new global::System.NotImplementedException("TypeReference");
 }
        public override object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
        {
            for (int i = 0; i < fieldDeclaration.Fields.Count; ++i) {
                VariableDeclaration field = (VariableDeclaration)fieldDeclaration.Fields[i];

                if ((fieldDeclaration.Modifier & Modifiers.WithEvents) != 0) {
                    //this.withEventsFields.Add(field);
                }
                TypeReference fieldType = fieldDeclaration.GetTypeForField(i);

                if (fieldType.IsNull) {
                    fieldType = new TypeReference(typeDeclarations.Peek().Name);
                }

                CodeMemberField memberField = new CodeMemberField(ConvType(fieldType), field.Name);
                memberField.Attributes = ConvMemberAttributes(fieldDeclaration.Modifier);
                if (!field.Initializer.IsNull) {
                    memberField.InitExpression = (CodeExpression)field.Initializer.AcceptVisitor(this, data);
                }

                typeDeclarations.Peek().Members.Add(memberField);
            }

            return null;
        }
Example #30
0
 public Using(string name, TypeReference alias)
 {
     Name = name;
     Alias = alias;
     xmlPrefix = "";
 }