CodeTypeReferenceExpression ConvertToIdentifier(FieldReferenceExpression fieldReferenceExpression) { // CodeFieldReferenceExpression cpre = new CodeFieldReferenceExpression (); // CodeFieldReferenceExpression firstCpre = cpre,newCpre; string type = String.Empty; while (fieldReferenceExpression.TargetObject is FieldReferenceExpression) { // newCpre = new CodeFieldReferenceExpression(); // Console.WriteLine(fieldReferenceExpression.FieldName); // cpre.FieldName = fieldReferenceExpression.FieldName; // cpre.TargetObject = newCpre; // cpre = newCpre; type = "." + fieldReferenceExpression.FieldName + type; fieldReferenceExpression = (FieldReferenceExpression)fieldReferenceExpression.TargetObject; } type = "." + fieldReferenceExpression.FieldName + type; // newCpre = new CodeFieldReferenceExpression(); // Console.WriteLine(fieldReferenceExpression.FieldName); // cpre.FieldName = fieldReferenceExpression.FieldName; // cpre.TargetObject = newCpre; // cpre = newCpre; if (fieldReferenceExpression.TargetObject is IdentifierExpression) { return new CodeTypeReferenceExpression(((IdentifierExpression)fieldReferenceExpression.TargetObject).Identifier + type); // cpre.TargetObject = // return firstCpre; } else { throw new Exception(); } }
bool IsQualIdent(FieldReferenceExpression fieldReferenceExpression) { while (fieldReferenceExpression.TargetObject is FieldReferenceExpression) { fieldReferenceExpression = (FieldReferenceExpression)fieldReferenceExpression.TargetObject; } return fieldReferenceExpression.TargetObject is IdentifierExpression; }
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data) { if (methodReference) { return new CodeMethodReferenceExpression((CodeExpression)fieldReferenceExpression.TargetObject.AcceptVisitor(this, data), fieldReferenceExpression.FieldName); } if (IsFieldReferenceExpression(fieldReferenceExpression)) { return new CodeFieldReferenceExpression((CodeExpression)fieldReferenceExpression.TargetObject.AcceptVisitor(this, data), fieldReferenceExpression.FieldName); } else { if (fieldReferenceExpression.TargetObject is FieldReferenceExpression) { if (IsQualIdent((FieldReferenceExpression)fieldReferenceExpression.TargetObject)) { CodeTypeReferenceExpression typeRef = ConvertToIdentifier((FieldReferenceExpression)fieldReferenceExpression.TargetObject); if (IsField(typeRef.Type.BaseType, fieldReferenceExpression.FieldName)) { return new CodeFieldReferenceExpression(typeRef, fieldReferenceExpression.FieldName); } else { return new CodePropertyReferenceExpression(typeRef, fieldReferenceExpression.FieldName); } } } CodeExpression codeExpression = (CodeExpression)fieldReferenceExpression.TargetObject.AcceptVisitor(this, data); return new CodePropertyReferenceExpression(codeExpression, fieldReferenceExpression.FieldName); } }
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data) { DebugOutput(fieldReferenceExpression); if (fieldReferenceExpression.TargetObject is ObjectCreateExpression) { return String.Concat("(", fieldReferenceExpression.TargetObject.AcceptVisitor(this, data), ").", fieldReferenceExpression.FieldName); } return String.Concat(fieldReferenceExpression.TargetObject.AcceptVisitor(this, data), ".", fieldReferenceExpression.FieldName); }
bool IsFieldReferenceExpression(FieldReferenceExpression fieldReferenceExpression) { if (fieldReferenceExpression.TargetObject is ThisReferenceExpression) { foreach (object o in this.currentTypeDeclaration.Children) { if (o is FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration)o; foreach (VariableDeclaration field in fd.Fields) { if (fieldReferenceExpression.FieldName == field.Name) { return true; } } } } } return false; //Char.IsLower(fieldReferenceExpression.FieldName[0]); }
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data) { Console.WriteLine(fieldReferenceExpression.ToString()); return fieldReferenceExpression.AcceptChildren(this, data); }
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data) { if (fieldReferenceExpression == null) { return null; } // int. generates a FieldreferenceExpression with TargetObject TypeReferenceExpression and no FieldName if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName == "") { if (fieldReferenceExpression.TargetObject is TypeReferenceExpression) { resolver.ShowStatic = true; return new ReturnType(((TypeReferenceExpression)fieldReferenceExpression.TargetObject).TypeReference); } } IReturnType returnType = fieldReferenceExpression.TargetObject.AcceptVisitor(this, data) as IReturnType; if (returnType != null) { string name = resolver.SearchNamespace(returnType.FullyQualifiedName, resolver.CompilationUnit); if (name != null) { string n = resolver.SearchNamespace(string.Concat(name, ".", fieldReferenceExpression.FieldName), null); if (n != null) { return new ReturnType(n); } IClass c = resolver.SearchType(string.Concat(name, ".", fieldReferenceExpression.FieldName), resolver.CompilationUnit); if (c != null) { resolver.ShowStatic = true; return new ReturnType(c.FullyQualifiedName); } return null; } return resolver.SearchMember(returnType, fieldReferenceExpression.FieldName); } // Console.WriteLine("returnType of child is null!"); return null; }
public virtual object Visit(FieldReferenceExpression fieldReferenceExpression, object data) { if (fieldReferenceExpression.TargetObject != null) { return fieldReferenceExpression.TargetObject.AcceptVisitor(this, data); } return data; }
void PrimaryExpr( #line 1824 "cs.ATG" out Expression pexpr) { #line 1826 "cs.ATG" TypeReference type = null; bool isArrayCreation = false; Expression expr; pexpr = null; switch (la.kind) { case 112: { lexer.NextToken(); #line 1833 "cs.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 71: { lexer.NextToken(); #line 1834 "cs.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 89: { lexer.NextToken(); #line 1835 "cs.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 2: { lexer.NextToken(); #line 1836 "cs.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 1: { lexer.NextToken(); #line 1838 "cs.ATG" pexpr = new IdentifierExpression(t.val); break; } case 18: { lexer.NextToken(); Expr( #line 1840 "cs.ATG" out expr); Expect(19); #line 1840 "cs.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 51: case 53: case 56: case 61: case 65: case 74: case 81: case 86: case 90: case 101: case 103: case 107: case 115: case 116: case 119: { switch (la.kind) { case 51: { lexer.NextToken(); break; } case 53: { lexer.NextToken(); break; } case 56: { lexer.NextToken(); break; } case 61: { lexer.NextToken(); break; } case 65: { lexer.NextToken(); break; } case 74: { lexer.NextToken(); break; } case 81: { lexer.NextToken(); break; } case 86: { lexer.NextToken(); break; } case 90: { lexer.NextToken(); break; } case 101: { lexer.NextToken(); break; } case 103: { lexer.NextToken(); break; } case 107: { lexer.NextToken(); break; } case 115: { lexer.NextToken(); break; } case 116: { lexer.NextToken(); break; } case 119: { lexer.NextToken(); break; } } #line 1846 "cs.ATG" string val = t.val; t.val = ""; Expect(13); Expect(1); #line 1846 "cs.ATG" pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); break; } case 110: { lexer.NextToken(); #line 1848 "cs.ATG" pexpr = new ThisReferenceExpression(); break; } case 50: { lexer.NextToken(); #line 1850 "cs.ATG" Expression retExpr = new BaseReferenceExpression(); if (la.kind == 13) { lexer.NextToken(); Expect(1); #line 1852 "cs.ATG" retExpr = new FieldReferenceExpression(retExpr, t.val); } else if (la.kind == 16) { lexer.NextToken(); Expr( #line 1853 "cs.ATG" out expr); #line 1853 "cs.ATG" ArrayList indices = new ArrayList(); indices.Add(expr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 1854 "cs.ATG" out expr); #line 1854 "cs.ATG" indices.Add(expr); } Expect(17); #line 1855 "cs.ATG" retExpr = new IndexerExpression(retExpr, indices); } else SynErr(179); #line 1856 "cs.ATG" pexpr = retExpr; break; } case 88: { lexer.NextToken(); NonArrayType( #line 1857 "cs.ATG" out type); #line 1857 "cs.ATG" ArrayList parameters = new ArrayList(); if (la.kind == 18) { lexer.NextToken(); #line 1862 "cs.ATG" ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); if (StartOf(21)) { Argument( #line 1862 "cs.ATG" out expr); #line 1862 "cs.ATG" parameters.Add(expr); while (la.kind == 12) { lexer.NextToken(); Argument( #line 1863 "cs.ATG" out expr); #line 1863 "cs.ATG" parameters.Add(expr); } } Expect(19); #line 1863 "cs.ATG" pexpr = oce; } else if (la.kind == 16) { #line 1865 "cs.ATG" isArrayCreation = true; ArrayCreateExpression ace = new ArrayCreateExpression(type); pexpr = ace; lexer.NextToken(); #line 1866 "cs.ATG" int dims = 0; ArrayList rank = new ArrayList(); ArrayList parameterExpression = new ArrayList(); if (StartOf(4)) { Expr( #line 1868 "cs.ATG" out expr); #line 1868 "cs.ATG" parameterExpression.Add(expr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 1868 "cs.ATG" out expr); #line 1868 "cs.ATG" parameterExpression.Add(expr); } Expect(17); #line 1868 "cs.ATG" parameters.Add(new ArrayCreationParameter(parameterExpression)); ace.Parameters = parameters; while ( #line 1869 "cs.ATG" IsDims()) { Expect(16); #line 1869 "cs.ATG" dims =0; while (la.kind == 12) { lexer.NextToken(); #line 1869 "cs.ATG" dims++; } #line 1869 "cs.ATG" rank.Add(dims); parameters.Add(new ArrayCreationParameter(dims)); Expect(17); } #line 1870 "cs.ATG" if (rank.Count > 0) { ace.Rank = (int[])rank.ToArray(typeof (int)); } if (la.kind == 14) { ArrayInitializer( #line 1871 "cs.ATG" out expr); #line 1871 "cs.ATG" ace.ArrayInitializer = (ArrayInitializerExpression)expr; } } else if (la.kind == 12 || la.kind == 17) { while (la.kind == 12) { lexer.NextToken(); #line 1873 "cs.ATG" dims++; } #line 1873 "cs.ATG" parameters.Add(new ArrayCreationParameter(dims)); Expect(17); while ( #line 1873 "cs.ATG" IsDims()) { Expect(16); #line 1873 "cs.ATG" dims =0; while (la.kind == 12) { lexer.NextToken(); #line 1873 "cs.ATG" dims++; } #line 1873 "cs.ATG" parameters.Add(new ArrayCreationParameter(dims)); Expect(17); } ArrayInitializer( #line 1873 "cs.ATG" out expr); #line 1873 "cs.ATG" ace.ArrayInitializer = (ArrayInitializerExpression)expr; ace.Parameters = parameters; } else SynErr(180); } else SynErr(181); break; } case 114: { lexer.NextToken(); Expect(18); if ( #line 1879 "cs.ATG" NotVoidPointer()) { Expect(122); #line 1879 "cs.ATG" type = new TypeReference("void"); } else if (StartOf(8)) { Type( #line 1880 "cs.ATG" out type); } else SynErr(182); Expect(19); #line 1881 "cs.ATG" pexpr = new TypeOfExpression(type); break; } case 104: { lexer.NextToken(); Expect(18); Type( #line 1882 "cs.ATG" out type); Expect(19); #line 1882 "cs.ATG" pexpr = new SizeOfExpression(type); break; } case 57: { lexer.NextToken(); Expect(18); Expr( #line 1883 "cs.ATG" out expr); Expect(19); #line 1883 "cs.ATG" pexpr = new CheckedExpression(expr); break; } case 117: { lexer.NextToken(); Expect(18); Expr( #line 1884 "cs.ATG" out expr); Expect(19); #line 1884 "cs.ATG" pexpr = new CheckedExpression(expr); break; } default: SynErr(183); break; } while (StartOf(27)) { if (la.kind == 29 || la.kind == 30) { if (la.kind == 29) { lexer.NextToken(); #line 1888 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); } else if (la.kind == 30) { lexer.NextToken(); #line 1889 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); } else SynErr(184); } else if (la.kind == 47) { lexer.NextToken(); Expect(1); #line 1892 "cs.ATG" pexpr = new PointerReferenceExpression(pexpr, t.val); } else if (la.kind == 13) { lexer.NextToken(); Expect(1); #line 1893 "cs.ATG" pexpr = new FieldReferenceExpression(pexpr, t.val); } else if (la.kind == 18) { lexer.NextToken(); #line 1895 "cs.ATG" ArrayList parameters = new ArrayList(); if (StartOf(21)) { Argument( #line 1896 "cs.ATG" out expr); #line 1896 "cs.ATG" parameters.Add(expr); while (la.kind == 12) { lexer.NextToken(); Argument( #line 1897 "cs.ATG" out expr); #line 1897 "cs.ATG" parameters.Add(expr); } } Expect(19); #line 1898 "cs.ATG" pexpr = new InvocationExpression(pexpr, parameters); } else { #line 1900 "cs.ATG" if (isArrayCreation) Error("element access not allow on array creation"); ArrayList indices = new ArrayList(); lexer.NextToken(); Expr( #line 1903 "cs.ATG" out expr); #line 1903 "cs.ATG" indices.Add(expr); while (la.kind == 12) { lexer.NextToken(); Expr( #line 1904 "cs.ATG" out expr); #line 1904 "cs.ATG" indices.Add(expr); } Expect(17); #line 1905 "cs.ATG" pexpr = new IndexerExpression(pexpr, indices); } } }
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data) { fieldReferenceExpression.TargetObject.AcceptVisitor(this, data); outputFormatter.PrintToken(Tokens.Dot); outputFormatter.PrintIdentifier(fieldReferenceExpression.FieldName); return null; }