2026-02-06 19:04:37 -07:00
|
|
|
#pragma once
|
|
|
|
|
#include "ASTNode.h"
|
|
|
|
|
|
|
|
|
|
class Annotation : public ASTNode {
|
|
|
|
|
public:
|
|
|
|
|
Annotation() { conceptType = "Annotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DerefStrategy : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy;
|
|
|
|
|
std::string derefLocation;
|
|
|
|
|
std::string owner;
|
|
|
|
|
DerefStrategy() { conceptType = "DerefStrategy"; }
|
|
|
|
|
DerefStrategy(const std::string& id, const std::string& strategy)
|
|
|
|
|
: strategy(strategy) {
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->conceptType = "DerefStrategy";
|
|
|
|
|
}
|
|
|
|
|
// children: derefTime (0..1) via setChild("derefTime", ...)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OptimizationLock : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string lockedBy;
|
|
|
|
|
std::string lockReason;
|
|
|
|
|
std::string lockLevel;
|
|
|
|
|
std::string affectedStrategies;
|
|
|
|
|
std::string timestamp;
|
|
|
|
|
OptimizationLock() { conceptType = "OptimizationLock"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LangSpecific : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string language;
|
|
|
|
|
std::string idiomType;
|
|
|
|
|
std::string rawSyntax;
|
|
|
|
|
std::string semanticHint;
|
|
|
|
|
std::string position;
|
|
|
|
|
LangSpecific() { conceptType = "LangSpecific"; }
|
|
|
|
|
};
|
2026-02-07 09:44:31 -07:00
|
|
|
|
|
|
|
|
// New canonical memory annotations replacing the old DerefStrategy
|
|
|
|
|
|
|
|
|
|
class DeallocateAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy; // "Explicit" for manual allocation/deallocation
|
|
|
|
|
std::string deallocateLocation;
|
|
|
|
|
std::string owner;
|
|
|
|
|
DeallocateAnnotation() {
|
|
|
|
|
conceptType = "DeallocateAnnotation";
|
|
|
|
|
strategy = "Explicit";
|
|
|
|
|
}
|
|
|
|
|
DeallocateAnnotation(const std::string& id, const std::string& strategy_val)
|
|
|
|
|
: strategy(strategy_val) {
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->conceptType = "DeallocateAnnotation";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LifetimeAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy; // "RAII" for destructor-based cleanup
|
|
|
|
|
std::string lifetimeScope;
|
|
|
|
|
LifetimeAnnotation() {
|
|
|
|
|
conceptType = "LifetimeAnnotation";
|
|
|
|
|
strategy = "RAII";
|
|
|
|
|
}
|
|
|
|
|
LifetimeAnnotation(const std::string& id, const std::string& strategy_val)
|
|
|
|
|
: strategy(strategy_val) {
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->conceptType = "LifetimeAnnotation";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReclaimAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy; // "Tracing", "Cycle", "Escape" for different GC strategies
|
|
|
|
|
std::string reclaimPattern;
|
|
|
|
|
ReclaimAnnotation() {
|
|
|
|
|
conceptType = "ReclaimAnnotation";
|
|
|
|
|
strategy = "Tracing";
|
|
|
|
|
}
|
|
|
|
|
ReclaimAnnotation(const std::string& id, const std::string& strategy_val)
|
|
|
|
|
: strategy(strategy_val) {
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->conceptType = "ReclaimAnnotation";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OwnerAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy; // "Single", "Shared_ARC" for ownership strategies
|
|
|
|
|
std::string ownerType;
|
|
|
|
|
OwnerAnnotation() {
|
|
|
|
|
conceptType = "OwnerAnnotation";
|
|
|
|
|
strategy = "Single";
|
|
|
|
|
}
|
|
|
|
|
OwnerAnnotation(const std::string& id, const std::string& strategy_val)
|
|
|
|
|
: strategy(strategy_val) {
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->conceptType = "OwnerAnnotation";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AllocateAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy; // "Static", "Register", "Allocator" for allocation strategies
|
|
|
|
|
std::string allocationPattern;
|
2026-02-08 20:57:58 -07:00
|
|
|
AllocateAnnotation() {
|
|
|
|
|
conceptType = "AllocateAnnotation";
|
2026-02-07 09:44:31 -07:00
|
|
|
strategy = "Static";
|
|
|
|
|
}
|
|
|
|
|
AllocateAnnotation(const std::string& id, const std::string& strategy_val)
|
|
|
|
|
: strategy(strategy_val) {
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->conceptType = "AllocateAnnotation";
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-02-08 20:57:58 -07:00
|
|
|
|
|
|
|
|
// Optimization annotations (Step 67)
|
|
|
|
|
|
|
|
|
|
class HotColdAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string hint; // "Hot" or "Cold"
|
|
|
|
|
HotColdAnnotation() { conceptType = "HotColdAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class InlineAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string mode; // "Always", "Never", "Hint"
|
|
|
|
|
InlineAnnotation() { conceptType = "InlineAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PureAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
PureAnnotation() { conceptType = "PureAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ConstExprAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
ConstExprAnnotation() { conceptType = "ConstExprAnnotation"; }
|
|
|
|
|
};
|
Steps 266-268: Phase 10a — semantic annotation core + sidecar persistence (32/32 tests)
Step 266: 5 semantic annotation AST types (Intent, Complexity, Risk,
Contract, SemanticTag) with JSON roundtrip and compact AST integration.
Step 267: Sidecar AST persistence (.whetstone/<file>.ast.json) with
save/load/list RPC methods, MCP tools, and permission enforcement.
Step 268: Phase 10a integration tests — multi-file sidecar workflow,
all 5 types in compact view, idempotent roundtrip, source isolation.
Also includes Sprint 10 plan, GUI/installer polish, and Emacs integration fixes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 16:01:56 +00:00
|
|
|
|
|
|
|
|
// Semantic annotations for AI guidance (Sprint 10, Step 266)
|
|
|
|
|
|
|
|
|
|
class IntentAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string summary; // 1-sentence description of what/why
|
|
|
|
|
std::string category; // "validation", "transformation", "io",
|
|
|
|
|
// "coordination", "computation", "initialization"
|
|
|
|
|
IntentAnnotation() { conceptType = "IntentAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ComplexityAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string timeComplexity; // "O(1)", "O(n)", "O(n^2)", etc.
|
|
|
|
|
int cognitiveComplexity = 0; // 1-10 scale
|
|
|
|
|
int linesOfLogic = 0;
|
|
|
|
|
ComplexityAnnotation() { conceptType = "ComplexityAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RiskAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string level; // "low", "medium", "high", "critical"
|
|
|
|
|
std::string reason;
|
|
|
|
|
int dependentCount = 0; // how many callers/consumers
|
|
|
|
|
RiskAnnotation() { conceptType = "RiskAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ContractAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string preconditions;
|
|
|
|
|
std::string postconditions;
|
|
|
|
|
std::string returnShape; // human-readable type/shape description
|
|
|
|
|
std::string sideEffects; // "none", "io", "mutation", "network"
|
|
|
|
|
ContractAnnotation() { conceptType = "ContractAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SemanticTagAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::vector<std::string> tags; // e.g. ["@serialize", "@validation"]
|
|
|
|
|
SemanticTagAnnotation() { conceptType = "SemanticTagAnnotation"; }
|
|
|
|
|
};
|
Steps 272-277: Phase 10c — type system, concurrency & scope annotations (68/68 tests)
- Step 272: Type layout/constraints — BitWidth, Endian, Layout, Nullability, Variance (37 tests)
- Step 273: Type identity/mutability — Identity, Mut, TypeState (25 tests)
- Step 274: Concurrency primitives — Atomic, Sync, ThreadModel, MemoryBarrier (25 tests)
- Step 275: Async/error handling — Exec, Blocking, Parallel, Trap, Exception, Panic (36 tests)
- Step 276: Scope/namespace — Binding, Lookup, Capture, Visibility, Namespace, Scope (32 tests)
- Step 277: Integration tests — cross-subject workflows, sidecar roundtrip, RPC (16 tests)
- 24 new annotation classes with JSON roundtrip, compact AST, sidecar persistence
- Generic fallback in getSemanticAnnotations RPC for extensible annotation queries
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 18:15:21 +00:00
|
|
|
|
|
|
|
|
// Type System Annotations — Layout & Constraints (Step 272, Subject 2)
|
|
|
|
|
|
|
|
|
|
class BitWidthAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
int width = 0; // e.g. 32 for Java int
|
|
|
|
|
BitWidthAnnotation() { conceptType = "BitWidthAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class EndianAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string order; // "big" | "little"
|
|
|
|
|
EndianAnnotation() { conceptType = "EndianAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LayoutAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string mode; // "packed" | "aligned"
|
|
|
|
|
int alignment = 0;
|
|
|
|
|
LayoutAnnotation() { conceptType = "LayoutAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NullabilityAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
bool nullable = false;
|
|
|
|
|
std::string strategy; // "strict" | "nullable"
|
|
|
|
|
NullabilityAnnotation() { conceptType = "NullabilityAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VarianceAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string variance; // "covariant" | "contravariant" | "invariant"
|
|
|
|
|
VarianceAnnotation() { conceptType = "VarianceAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Type System Annotations — Identity & Mutability (Step 273, Subject 2)
|
|
|
|
|
|
|
|
|
|
class IdentityAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string mode; // "nominal" | "structural"
|
|
|
|
|
IdentityAnnotation() { conceptType = "IdentityAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MutAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string depth; // "shallow" | "deep" | "interior"
|
|
|
|
|
MutAnnotation() { conceptType = "MutAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TypeStateAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string state; // "erased" | "reified"
|
|
|
|
|
TypeStateAnnotation() { conceptType = "TypeStateAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Concurrency Annotations — Primitives & Memory Model (Step 274, Subject 3)
|
|
|
|
|
|
|
|
|
|
class AtomicAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string consistency; // "seq_cst" | "relaxed" | "acquire" | "release"
|
|
|
|
|
AtomicAnnotation() { conceptType = "AtomicAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SyncAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string primitive; // "monitor" | "spin" | "semaphore"
|
|
|
|
|
SyncAnnotation() { conceptType = "SyncAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ThreadModelAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string model; // "green" | "os" | "fiber"
|
|
|
|
|
ThreadModelAnnotation() { conceptType = "ThreadModelAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MemoryBarrierAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
MemoryBarrierAnnotation() { conceptType = "MemoryBarrierAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Async, Parallelism & Error Handling Annotations (Step 275, Subject 3)
|
|
|
|
|
|
|
|
|
|
class ExecAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string mode; // "async" | "event"
|
|
|
|
|
std::string runtimeHint; // e.g. "tokio", "libuv"
|
|
|
|
|
ExecAnnotation() { conceptType = "ExecAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BlockingAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string kind; // "io" | "compute"
|
|
|
|
|
BlockingAnnotation() { conceptType = "BlockingAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ParallelAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string kind; // "data" | "task"
|
|
|
|
|
ParallelAnnotation() { conceptType = "ParallelAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TrapAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string signal; // e.g. "SIGSEGV", "SIGFPE"
|
|
|
|
|
TrapAnnotation() { conceptType = "TrapAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ExceptionAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string style; // "checked" | "unchecked"
|
|
|
|
|
ExceptionAnnotation() { conceptType = "ExceptionAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PanicAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string behavior; // "abort" | "unwind"
|
|
|
|
|
PanicAnnotation() { conceptType = "PanicAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Scope & Namespace Annotations (Step 276, Subject 4)
|
|
|
|
|
|
|
|
|
|
class BindingAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string time; // "static" | "dynamic"
|
|
|
|
|
BindingAnnotation() { conceptType = "BindingAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LookupAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string mode; // "lexical" | "hoisted"
|
|
|
|
|
LookupAnnotation() { conceptType = "LookupAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CaptureAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string strategy; // "value" | "ref" | "move"
|
|
|
|
|
CaptureAnnotation() { conceptType = "CaptureAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VisibilityAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string level; // "private" | "internal" | "friend" | "public"
|
|
|
|
|
VisibilityAnnotation() { conceptType = "VisibilityAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NamespaceAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string style; // "qualified" | "flat"
|
|
|
|
|
NamespaceAnnotation() { conceptType = "NamespaceAnnotation"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ScopeAnnotation : public Annotation {
|
|
|
|
|
public:
|
|
|
|
|
std::string kind; // "local" | "global_leaked" | "singleton"
|
|
|
|
|
ScopeAnnotation() { conceptType = "ScopeAnnotation"; }
|
|
|
|
|
};
|