Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d1ffaf
commit 139606a
Showing
9 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.lock-wscript | ||
build/ | ||
libclang.node | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "type.h" | ||
#include "nstring.h" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
using namespace nclang; | ||
|
||
#define KIND String::NewSymbol("kind") | ||
#define SPELL String::NewSymbol("spelling") | ||
#define RESULT String::NewSymbol("result") | ||
|
||
Type* | ||
Type::New(CXType ct) | ||
{ | ||
Local<Object> self = Klass->GetFunction()->NewInstance(); | ||
Type *t = ObjectWrap::Unwrap<Type>(self); | ||
t->opaque_ = ct; | ||
return t; | ||
} | ||
|
||
Handle<Value> | ||
Type::New(const Arguments &args) | ||
{ | ||
HandleScope scope; | ||
Type *t = new Type(); | ||
t->Wrap(args.This()); | ||
return args.This(); | ||
} | ||
|
||
static Handle<Value> | ||
Getter(Local<String> property, const AccessorInfo& info) | ||
{ | ||
HandleScope scope; | ||
Type *t = ObjectWrap::Unwrap<Type>(info.This()); | ||
|
||
if (KIND == property) | ||
return scope.Close(Integer::New(t->opaque_.kind)); | ||
else if (SPELL == property) | ||
return scope.Close(from_string(clang_getTypeKindSpelling(t->opaque_.kind))); | ||
else if (RESULT == property) | ||
{ | ||
Type *nt = Type::New(clang_getResultType(t->opaque_)); | ||
return scope.Close(nt->handle_); | ||
} | ||
|
||
return Undefined(); | ||
} | ||
Persistent<FunctionTemplate> Type::Klass; | ||
|
||
void | ||
Type::Initialize(Handle<Object> target) | ||
{ | ||
HandleScope scope; | ||
Local<FunctionTemplate> t = FunctionTemplate::New(New); | ||
Klass = Persistent<FunctionTemplate>::New(t); | ||
|
||
Klass->InstanceTemplate()->SetInternalFieldCount(1); | ||
|
||
Klass->PrototypeTemplate()->SetAccessor(KIND, Getter); | ||
Klass->PrototypeTemplate()->SetAccessor(SPELL, Getter); | ||
Klass->PrototypeTemplate()->SetAccessor(RESULT, Getter); | ||
|
||
target->Set(String::NewSymbol("type"), Klass->GetFunction()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef NCLANG_TYPE_H | ||
#define NCLANG_TYPE_H | ||
|
||
#include <node.h> | ||
#include <clang-c/Index.h> | ||
|
||
namespace nclang | ||
{ | ||
class Type : public node::ObjectWrap | ||
{ | ||
public: | ||
CXType opaque_; | ||
static void Initialize(v8::Handle<v8::Object> target); | ||
static v8::Handle<v8::Value> New(const v8::Arguments &args); | ||
static Type* New(CXType ct); | ||
static v8::Persistent<v8::FunctionTemplate> Klass; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters