public static Field GenerateConstValueFromMacro(this ASTContext context, MacroDefinition macro) { PrimitiveTypeExpression builtinTypeExpression = PrimitiveTypeExpression.TryCreate(macro.Expression); if (builtinTypeExpression == null) { return(null); } var valueType = new QualifiedType(new BuiltinType(builtinTypeExpression.Type)) { Qualifiers = new TypeQualifiers { IsConst = true } }; var item = new Field { Name = macro.Name, DebugText = macro.DebugText, Access = AccessSpecifier.Public, Expression = builtinTypeExpression, QualifiedType = valueType }; return(item); }
public SaveMacroCommand(String name, CommandScope scope, bool active, MacroDefinition md) : base(name, scope, active) { this.md = md; this.next = null; }
internal MacroCall(MacroDefinition target, Variable resultVar, IEnumerable <Ast> parameters) { Target = target; ResultVar = resultVar; if (resultVar.Type != target.Result.Type) { throw new ArgumentException("Incompatible result variable type", nameof(resultVar)); } Parameters = parameters.ToArray(); if (Parameters.Length != Target.Parameters.Length) { throw new ArgumentException("Wrong number of parameters", nameof(parameters)); } for (int i = 0; i < Parameters.Length; i++) { var par = Target.Parameters[i]; if (par is MacroDefParam && !(Parameters[i] is MacroDefinition)) { throw new ArgumentException("Macro parameter expected in position " + i); } if (!(par is MacroDefParam) && !(Parameters[i] is Expression)) { throw new ArgumentException("Expression expected in position " + i); } } }
/// <summary> /// Gets the surface controller meta data and a reference to the MethodInfo object for the ChildAction to render based on the /// macro definition /// </summary> /// <param name="macro"></param> /// <param name="components"></param> /// <param name="action"></param> /// <returns></returns> public static Lazy <SurfaceController, SurfaceMetadata> GetSurfaceMacroChildAction( this MacroDefinition macro, ComponentRegistrations components, out MethodInfo action) { var parsedMacroName = MacroNameParser.ParseChildActionMacroName(macro.SelectedItem); //get the surface controller for the area/controller name var surfaceController = components.SurfaceControllers .Where(x => x.Metadata.ControllerName == parsedMacroName.ControllerName && (parsedMacroName.AreaName == "" || (x.Metadata.PluginDefinition != null && x.Metadata.PluginDefinition.PackageName == parsedMacroName.AreaName))) .SingleOrDefault(); if (surfaceController == null) { throw new ApplicationException("Could not find the Surface controller '" + parsedMacroName.ControllerName); } if (!surfaceController.Metadata.HasChildActionMacros) { throw new ApplicationException("The Surface controller '" + parsedMacroName.ControllerName + "' is not advertising that it HasChildActionMacros"); } //now we need to get the controller's referenced child action var childAction = surfaceController.Metadata.ComponentType.GetMethods() .Where(x => x.Name == parsedMacroName.ActionName && x.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any()) .SingleOrDefault(); if (childAction == null) { throw new ApplicationException("The Surface controller '" + parsedMacroName.ControllerName + "' with Action: '" + parsedMacroName.ActionName + "' could not be found or was not attributed with a ChildActionOnlyAttribute"); } action = childAction; return(surfaceController); }
private bool ParseMacroDefinition(ParseTreeNode node, Block block, out MacroDefinition res) { res = new Assemble.MacroDefinition(); res.AssemblePosition = new Assemble.AssemblePosition(this.ParsingFilePath, node); res.ParentBlock = block; res.DefinedBlock = block; res.RootCode = block.RootCode; { //macro + name + ( + args + ) + { + contents + } //Name res.Name = node.ChildNodes[1].Token.Text; //Arguments if (!ParseMacroDefinitionArguments(node.ChildNodes[3], block, out res.Arguments)) { return(false); } //Contents Block blkedRes = res; if (!ParseBlockContents(node.ChildNodes[6], ref blkedRes)) { return(false); } } return(true); }
static ulong ParseEnumItemMacroExpression(MacroDefinition macro, Enumeration @enum) { var expression = macro.Expression; // TODO: Handle string expressions if (expression.Length == 3 && expression[0] == '\'' && expression[2] == '\'') // '0' || 'A' { return(expression[1]); // return the ASCII code of this character } object eval; try { EvaluateEnumExpression(expression, @enum, out eval); } catch (Exception) { // TODO: This should just throw, but we have a pre-existing behavior that expects malformed // macro expressions to default to 0, see CSharp.h (MY_MACRO_TEST2_0), so do it for now. return(0); } if (eval is ulong number) { return(number); } unchecked { ulong val = ((ulong)(int)eval); return(val); } }
public static void Write(System.IO.Stream stream, MacroDefinition macro) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, VERSION); formatter.Serialize(stream, macro); }
public static MacroDefinition Read(System.IO.Stream stream) { IFormatter formatter = new BinaryFormatter(); int version = (Int32)formatter.Deserialize(stream); MacroDefinition macro = (MacroDefinition)formatter.Deserialize(stream); return(macro); }
public override AST.Declaration VisitMacroDefinition(MacroDefinition decl) { var _macro = new AST.MacroDefinition(); VisitPreprocessedEntity(decl, _macro); _macro.Expression = decl.Expression; return(_macro); }
public static Enumeration.Item GenerateEnumItemFromMacro(this Enumeration @enum, MacroDefinition macro) { return(new Enumeration.Item { Name = macro.Name, Expression = macro.Expression, Value = ParseMacroExpression(macro.Expression, @enum), Namespace = @enum }); }
public static Enumeration.Item GenerateEnumItemFromMacro(this ASTContext context, MacroDefinition macro) { var item = new Enumeration.Item { Name = macro.Name, Expression = macro.Expression, Value = ParseMacroExpression(macro.Expression) }; return(item); }
private void Evaluate(MacroDefinition macro) { Expression expression; if (!_parser.TryParse(macro.Expression, out expression)) { return; } macro.TypeName = expression.TypeName; macro.IsValid = true; macro.Expression = expression.Value.ToString(); }
private static Expression ParseMacroApplication(AstNode parent) { int startIdx = parent.Ast.Index; MacroDefinition matchedMacro = parent.Ast.Macros.FirstOrDefault(macro => macro.Syntax.Match(parent)); if (matchedMacro == null) { return(new UnknownExpression(parent, startIdx)); } return(new MacroApplicationExpression( parent, matchedMacro )); }
/// <summary> /// Gets the surface controller meta data and a reference to the MethodInfo object for the ChildAction to render based on the /// macro definition /// </summary> /// <param name="macro"></param> /// <param name="components"></param> /// <param name="action"></param> /// <returns></returns> public static Lazy <SurfaceController, SurfaceMetadata> GetSurfaceMacroChildAction( this MacroDefinition macro, ComponentRegistrations components, out MethodInfo action) { //need to see if the surface controller is part of an area var areaParts = macro.SelectedItem.Split('-'); var areaName = areaParts.Length > 1 ? areaParts[0] : ""; //we need to get the surface controller by name var controllerParts = macro.SelectedItem.Split('.'); if (controllerParts.Length != 2) { throw new FormatException("The string format for macro.SelectedItem for child actions must be: [AreaName-]ControllerName.ActionName"); } var controllerName = controllerParts[0].Replace(areaName + "-", ""); //strip off area name and hyphen if present (will be for plug-in based surface controllers, won't be for local ones) var controllerAction = controllerParts[1]; //get the surface controller for the area/controller name var surfaceController = components.SurfaceControllers .Where(x => x.Metadata.ControllerName == controllerName && (areaName == "" || x.Metadata.PluginDefinition.PackageName == areaName)) .SingleOrDefault(); if (surfaceController == null) { throw new ApplicationException("Could not find the Surface controller '" + controllerName); } if (!surfaceController.Metadata.HasChildActionMacros) { throw new ApplicationException("The Surface controller '" + controllerName + "' is not advertising that it HasChildActionMacros"); } //now we need to get the controller's referenced child action var childAction = surfaceController.Metadata.ComponentType.GetMethods() .Where(x => x.Name == controllerAction && x.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any()) .SingleOrDefault(); if (childAction == null) { throw new ApplicationException("The Surface controller '" + controllerName + "' with Action: '" + controllerAction + "' could not be found or was not attributed with a ChildActionOnlyAttribute"); } action = childAction; return(surfaceController); }
/// <summary> /// Creates a macro call token. /// </summary> /// <param name="scope">(required) Current scope</param> /// <param name="nameToken">(required) Function name</param> /// <param name="def">(required) Definition of this macro in file</param> public MacroCallToken(Scope scope, IdentifierToken nameToken, MacroDefinition def) : base(scope) { #if DEBUG if (nameToken == null) { throw new ArgumentNullException("nameToken"); } if (def == null) { throw new ArgumentNullException("def"); } #endif AddToken(_nameToken = nameToken); _nameToken.SourceDefinition = def; }
/// <summary> /// Constructs an <see cref="Enumeration.Item"/> by parsing the <see /// cref="MacroDefinition.Expression"/> in <paramref name="macro"/>. /// </summary> /// <remarks> /// As a side effect, updates <see cref="Enumeration.Type"/> and <see /// cref="Enumeration.BuiltinType"/> in <paramref name="@enum"/> to reflect an appropriate /// primitive type that can hold the newly-parsed <paramref name="macro"/> expression value /// as well as all previously discovered <see cref="Enumeration.Items"/>. The intent is to /// preserve sign information about the values held in <paramref name="enum"/>. /// </remarks> public static Enumeration.Item GenerateEnumItemFromMacro(this Enumeration @enum, MacroDefinition macro) { var(value, type) = ParseEnumItemMacroExpression(macro, @enum); if (type > @enum.BuiltinType.Type) { @enum.BuiltinType = new BuiltinType(type); @enum.Type = @enum.BuiltinType; } return(new Enumeration.Item { Name = macro.Name, Expression = macro.Expression, Value = value, Namespace = @enum }); }
public JsonResult PopulateMacroParameters(MacroDefinition macroDefinition) { var engine = this.BackOfficeRequestContext.RegisteredComponents.MacroEngines.SingleOrDefault(x => x.Metadata.EngineName.InvariantEquals(macroDefinition.MacroEngineName)); if (engine == null) { throw new InvalidOperationException("Could not find a MacroEngine registered with the name: " + macroDefinition.MacroEngineName); } try { //get the parameters from the engine's response var macroParams = engine.Value.GetMacroParameters(this.BackOfficeRequestContext, macroDefinition); return(JsonParametersSuccess(macroParams)); } catch (Exception ex) { return(JsonParametersException(ex)); } }
private static Expression ParseInfixMacroApplication( AstNode parent, MacroDefinition matchedInfixMacro, Expression infixLeft = null ) { int startIdx = parent.Ast.Index; parent.GetNext(); parent.Ast.MacroApplicationParts.Add(parent.Token); var restCascade = new CascadePattern(matchedInfixMacro.Syntax.Patterns.Skip(2).ToArray()); if (restCascade.Match(parent)) { return(new MacroApplicationExpression( parent, matchedInfixMacro, infixLeft )); } return(new UnknownExpression(parent, startIdx)); }
public virtual bool VisitMacroDefinition(MacroDefinition macro) { throw new NotImplementedException(); }
public override bool VisitMacroDefinition(MacroDefinition macro) { throw new NotImplementedException(); }
private MacroDefinition(MacroDefinition.Internal native, bool skipVTables = false) : this(__CopyValue(native), skipVTables) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
private static void* __CopyValue(MacroDefinition.__Internal native) { var ret = Marshal.AllocHGlobal(68); global::CppSharp.Parser.AST.MacroDefinition.__Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); }
public virtual TRet Visit(Parser.AST.Declaration decl) { switch (decl.Kind) { case DeclarationKind.TranslationUnit: { var _decl = new TranslationUnit(decl.__Instance); return(VisitTranslationUnit(_decl)); } case DeclarationKind.Namespace: { var _decl = new Namespace(decl.__Instance); return(VisitNamespace(_decl)); } case DeclarationKind.Typedef: { var _decl = new TypedefDecl(decl.__Instance); return(VisitTypedef(_decl)); } case DeclarationKind.Parameter: { var _decl = new Parameter(decl.__Instance); return(VisitParameter(_decl)); } case DeclarationKind.Function: { var _decl = new Function(decl.__Instance); return(VisitFunction(_decl)); } case DeclarationKind.Method: { var _decl = new Method(decl.__Instance); return(VisitMethod(_decl)); } case DeclarationKind.Enumeration: { var _decl = new Enumeration(decl.__Instance); return(VisitEnumeration(_decl)); } case DeclarationKind.EnumerationItem: { var _decl = new Enumeration.Item(decl.__Instance); return(VisitEnumerationItem(_decl)); } case DeclarationKind.Variable: { var _decl = new Variable(decl.__Instance); return(VisitVariable(_decl)); } case DeclarationKind.Field: { var _decl = new Field(decl.__Instance); return(VisitField(_decl)); } case DeclarationKind.AccessSpecifier: { var _decl = new AccessSpecifierDecl(decl.__Instance); return(VisitAccessSpecifier(_decl)); } case DeclarationKind.Class: { var _decl = new Class(decl.__Instance); return(VisitClass(_decl)); } case DeclarationKind.ClassTemplate: { var _decl = new ClassTemplate(decl.__Instance); return(VisitClassTemplate(_decl)); } case DeclarationKind.ClassTemplateSpecialization: { var _decl = new ClassTemplateSpecialization(decl.__Instance); return(VisitClassTemplateSpecialization(_decl)); } case DeclarationKind.ClassTemplatePartialSpecialization: { var _decl = new ClassTemplatePartialSpecialization(decl.__Instance); return(VisitClassTemplatePartialSpecialization(_decl)); } case DeclarationKind.FunctionTemplate: { var _decl = new FunctionTemplate(decl.__Instance); return(VisitFunctionTemplate(_decl)); } case DeclarationKind.MacroDefinition: { var _decl = new MacroDefinition(decl.__Instance); return(VisitMacroDefinition(_decl)); } case DeclarationKind.MacroExpansion: { var _decl = new MacroExpansion(decl.__Instance); return(VisitMacroExpansion(_decl)); } } throw new ArgumentOutOfRangeException(); }
public int GetMacroDefParamIndex(MacroDefinition def) { return(Parameters.FirstIndex(p => p.IsMacroDefinition && (p as Ast.MacroDefParam).Definition == def)); }
public Macro(MacroDefinition keys) { macroKeys = keys; }
/// <summary> /// <c> /// infix_expr: /// prefix_expr (ID | SYMBOL) infix_expr /// </c> /// </summary> internal static Expression ParseInfixExpr(AstNode parent) { Expression ParseInfix(int precedence) { Expression expr = ParsePrefixExpr(parent); if (parent.Token.Type == Newline) { return(expr); } MacroDefinition infixMacro = parent.Ast.Macros.FirstOrDefault( m => m.Syntax.Patterns.Length > 1 && m.Syntax.Patterns[1] is TokenPattern t && t.Value == parent.Peek.Value ); // infix macro check // expr (keyword | expr) expr? if (infixMacro != null) { return(ParseInfixMacroApplication(parent, infixMacro, expr)); } while (parent.Peek is OperatorToken || parent.Peek.Is(Identifier)) { parent.GetNext(); if (parent.Token.Is(Identifier)) { expr = new BinaryExpression( parent, expr, parent.Token, ParseInfix(4) ); continue; } var op = (OperatorToken)parent.Token; if (op.Properties.Precedence < precedence) { break; } expr = new BinaryExpression( parent, expr, op, ParseInfix(op.Properties.Precedence + 1) ); } if (parent.Peek.Is(KeywordIf, KeywordUnless) && !parent.Token.Is(Newline, Outdent)) { return(new ConditionalInfixExpression(parent, expr)); } return(expr); } return(ParseInfix(0)); }
internal MacroDefinition(MacroDefinition.Internal native) : this(&native) { }
public static bool AreCompatible(MacroDefinition def, MacroDefinition other) { return(def.ToString() == other.ToString()); }
public abstract TRet VisitMacroDefinition(MacroDefinition decl);
private static MacroDefinition.Internal* __CopyValue(MacroDefinition.Internal native) { var ret = Marshal.AllocHGlobal(200); CppSharp.Parser.AST.MacroDefinition.Internal.cctor_2(ret, new global::System.IntPtr(&native)); return (MacroDefinition.Internal*) ret; }
public virtual bool VisitMacroDefinition(MacroDefinition macro) { return(false); }
protected MacroDefinition(MacroDefinition.Internal* native, bool isInternalImpl = false) : base((CppSharp.Parser.AST.PreprocessedEntity.Internal*) native) { }
public static Enumeration.Item GenerateEnumItemFromMacro(this ASTContext context, MacroDefinition macro) { var item = new Enumeration.Item { Name = macro.Name, Expression = macro.Expression, Value = ParseMacroExpression(macro.Expression) }; return item; }
public static MacroDefinition __CreateInstance(MacroDefinition.Internal native, bool skipVTables = false) { return new MacroDefinition(native, skipVTables); }
public bool VisitMacroDefinition(MacroDefinition macro) { throw new System.NotImplementedException(); }
protected MacroDefinition(MacroDefinition.Internal* native, bool skipVTables = false) : base((CppSharp.Parser.AST.PreprocessedEntity.Internal*) null) { __PointerAdjustment = 0; if (native == null) return; __Instance = new global::System.IntPtr(native); }
internal MacroDefinition(MacroDefinition.Internal native) : this(__CopyValue(native)) { }
public CSharpTypePrinterResult VisitMacroDefinition(MacroDefinition macro) { throw new NotImplementedException(); }
private MacroDefinition(MacroDefinition.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; }
public static MacroDefinition __CreateInstance(MacroDefinition.Internal native) { return new MacroDefinition(native); }
internal MacroDefinition(MacroDefinition.Internal* native) : this(new global::System.IntPtr(native)) { }
private MacroDefinition(MacroDefinition.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
public void Write(MacroDefinition macro) { var valid = macro.IsValid ? string.Empty : "// "; WriteLine($"{valid}public static {macro.TypeName} {macro.Name} = {macro.Expression};"); }
public string VisitMacroDefinition(MacroDefinition macro) { throw new NotImplementedException(); }