Exemple #1
0
 public NodeJSSources(BindingContext context, IEnumerable <TranslationUnit> units)
     : base(context, units)
 {
     nodeJSTypePrinter = new NodeJSTypePrinter(context);
     nodeJSTypePrinter.PrintScopeKind = TypePrintScopeKind.Local;
     nodeJSTypeCheckPrinter           = new NodeJSTypeCheckPrinter(context);
 }
Exemple #2
0
        public string GenerateCheckStatement(IEnumerable <Parameter> parameters)
        {
            NodeJSTypePrinter nodeJSTypePrinter = new NodeJSTypePrinter(Context);

            nodeJSTypePrinter.PrintScopeKind = TypePrintScopeKind.Local;

            string generatedCheckStatement = (parameters.Count() >= 1 ? "(" : string.Empty);

            generatedCheckStatement += "(info.Length() == " + parameters.Count() + ")";
            generatedCheckStatement += parameters.Count() > 0 ? " && " : string.Empty;

            int methodArgumentIndex = 0;

            foreach (Parameter parameter in parameters)
            {
                string parameterTypeName = nodeJSTypePrinter.VisitParameter(parameter, false, false);
                generatedCheckStatement += methodArgumentIndex > 0 ? " && " : string.Empty;

                if (QualifiedTypeIsObject(parameter.QualifiedType))
                {
                    generatedCheckStatement += "(info[" + methodArgumentIndex + "]->IsObject() && ";
                    generatedCheckStatement += "(pylon_v8::ToGCString(info[" + methodArgumentIndex + "]->ToObject()->GetConstructorName()) == \"" + parameterTypeName + "\"))";
                }
                else if (QualifiedTypeIsNumber(parameter.QualifiedType))
                {
                    generatedCheckStatement += "info[" + methodArgumentIndex + "]->IsNumber()";
                }
                else if (QualifiedTypeIsBoolean(parameter.QualifiedType))
                {
                    generatedCheckStatement += "info[" + methodArgumentIndex + "]->IsBoolean()";
                }
                else if (QualifiedTypeIsString(parameter.QualifiedType))
                {
                    generatedCheckStatement += "info[" + methodArgumentIndex + "]->IsString()";
                }
                else if (QualifiedTypeIsArray(parameter.QualifiedType))
                {
                    generatedCheckStatement += "info[" + methodArgumentIndex + "]->IsArray()";
                }
                else if (QualifiedTypeIsTypedBuffer(parameter.QualifiedType))
                {
                    generatedCheckStatement += "info[" + methodArgumentIndex + "]->IsObject()";
                }

                methodArgumentIndex++;
            }

            generatedCheckStatement += parameters.Count() >= 1 ? ")" : string.Empty;
            return(generatedCheckStatement);
        }