protected XCodeTypeReference buildSimpleName(XSharpParser.SimpleNameContext simpleName) { XCodeTypeReference expr = null; // string name = simpleName.Id.GetText(); string gen = ""; if (simpleName.GenericArgList != null) { string argList = ""; int i = 0; foreach (var generic in simpleName.GenericArgList._GenericArgs) { if (i > 0) { argList += ","; } var tmp = buildDataType(generic); argList += tmp.TypeName; i++; } // //gen = "`" + i.ToString() + "[" + argList + "]"; gen = "<" + argList + ">"; } expr = buildTypeReference(name + gen); // return(expr); }
protected XCodeTypeReference buildDataType(XSharpParser.DatatypeContext context) { // // Datatype is ptrDatatype // or arrayDatatype // or simpleDatatype // or nullableDatatype // they all have a TypeName XSharpParser.TypeNameContext tn = null; if (context is XSharpParser.PtrDatatypeContext) { XSharpParser.PtrDatatypeContext ptrData = (XSharpParser.PtrDatatypeContext)context; tn = ptrData.TypeName; } else if (context is XSharpParser.ArrayDatatypeContext) { XSharpParser.ArrayDatatypeContext aData = (XSharpParser.ArrayDatatypeContext)context; tn = aData.TypeName; } else if (context is XSharpParser.SimpleDatatypeContext) { XSharpParser.SimpleDatatypeContext sdt = (XSharpParser.SimpleDatatypeContext)context; tn = sdt.TypeName; } else if (context is XSharpParser.NullableDatatypeContext) { XSharpParser.NullableDatatypeContext ndc = context as XSharpParser.NullableDatatypeContext; tn = ndc.TypeName; } // XCodeTypeReference expr = null; if (tn.NativeType != null) { expr = buildNativeType(tn.NativeType); } else if (tn.XType != null) { expr = buildXBaseType(tn.XType); } else if (tn.Name != null) { expr = buildName(tn.Name); } // return(expr); }
protected XCodeTypeReference buildName(XSharpParser.NameContext context) { XCodeTypeReference expr = null; // var sName = context.GetText(); if (context is XSharpParser.QualifiedNameContext) { XSharpParser.QualifiedNameContext qual = (XSharpParser.QualifiedNameContext)context; expr = buildName(qual.Left); expr = buildTypeReference(expr.TypeName + "." + buildSimpleName(qual.Right).TypeName); } else if (context is XSharpParser.SimpleOrAliasedNameContext) { var alias = context as XSharpParser.SimpleOrAliasedNameContext; var name = alias.Name as XSharpParser.AliasedNameContext; // if (name is XSharpParser.AliasQualifiedNameContext) { XSharpParser.AliasQualifiedNameContext al = (XSharpParser.AliasQualifiedNameContext)name; expr = buildSimpleName(al.Right); expr = buildTypeReference(al.Alias.GetText() + "::" + expr.TypeName); } else if (name is XSharpParser.GlobalQualifiedNameContext) { var gqn = name as XSharpParser.GlobalQualifiedNameContext; expr = buildSimpleName(gqn.Right); expr = buildTypeReference("global::" + expr.TypeName); } else if (name is XSharpParser.IdentifierOrGenericNameContext) { var id = name as XSharpParser.IdentifierOrGenericNameContext; expr = buildSimpleName(id.Name); } } // return(expr); }
public override void EnterImpliedvar([NotNull] XSharpParser.ImpliedvarContext context) { try { if (context.Expression is XSharpParser.PrimaryExpressionContext) { XSharpParser.PrimaryExpressionContext primaryEx = (XSharpParser.PrimaryExpressionContext)context.Expression; XSharpParser.PrimaryContext primary = primaryEx.Expr; if (primary is XSharpParser.LiteralExpressionContext) { // LOCAL IMPLIED xxx:= "azertyuiop" XSharpParser.LiteralExpressionContext lit = (XSharpParser.LiteralExpressionContext)primary; XVariable local; String localType = buildLiteralValue(lit.Literal); String localName; localName = context.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(context), localType); local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } else if (primary is XSharpParser.NameExpressionContext) { // LOCAL IMPLIED xx:= otherLocalVar XVariable local; XSharpParser.NameExpressionContext expr = (XSharpParser.NameExpressionContext)primary; string name = expr.Name.Id.GetText(); // String localName; localName = context.Id.GetText(); String localType = buildValueName(name); if (localType == XVariable.VarType) { XVariable xVar = findLocal(name); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), xVar.Interval, XVariable.VarType); } else { // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(context), localType); } local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } else if (primary is XSharpParser.CtorCallContext) { // LOCAL IMPLIED xxxx:= List<STRING>{ } XVariable local; XSharpParser.CtorCallContext expr = (XSharpParser.CtorCallContext)primary; XCodeTypeReference typeRef = buildDataType(expr.Type); // String localType = typeRef.TypeName; String localName; localName = context.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(context), localType); local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } } else if (context.Expression is XSharpParser.MethodCallContext) { // LOCAL IMPLIED xxxxx:= Obj:MethodCall() XSharpParser.MethodCallContext callCtxEx = (XSharpParser.MethodCallContext)context.Expression; XSharpParser.ExpressionContext exprCtx = callCtxEx.Expr; String mtdCall = exprCtx.GetText(); XVariable local; String localName; localName = context.Id.GetText(); // local = new XVariable(this._currentMethod, localName, Kind.Local, Modifiers.Public, new TextRange(context), new TextInterval(exprCtx), XVariable.VarType); local.File = this._file; local.IsArray = false; // if (this._currentMethod != null) { this._currentMethod.Locals.Add(local); } } } catch (Exception ex) { Support.Debug("EnterImpliedvar : Error Walking {0}, at {1}/{2} : " + ex.Message, this.File.Name, context.Start.Line, context.Start.Column); } }